Questions tagged [q#]

Q# is a domain-specific programming language used to express quantum algorithms. This tag should be used for questions related to creating/programming quantum algorithms using the 'Q#' language. If the question is not related to, or arising from some quantum aspect of Q#, it might be better to ask on StackOverflow. If appropriate, also use the [programming] tag.

Filter by
Sorted by
Tagged with
0
votes
1answer
2 views

how can i update microsoft Q# to include global phase

having challenges with Microsoft Q#. i wrote this short code and it says it can only occur on a global phase. how do i include the global phase in my Q# package. Any ideas thanks
2
votes
1answer
27 views

Finding phase angle in Q#

I've trying to measure the phase angle from X axis of a qubit, but unable to find any function in Q# documentation, can anyone help me with this?
1
vote
2answers
64 views

How can I code a Conditional phase shift transform?

I am interested in implementing a operation in Q#. The operation should follow the algorithm below: When $A=0$ it is quite easy to see that the algorithm states if the qubitt is in nullspace apply a ...
1
vote
1answer
23 views

What would be the difference between using qsharp library on python vs learning the Q# langauge?

One difference of course is the syntax. But I'm guessing the idea is eventually quantum computers will be able run Q#, whereas now it uses simulations. Will code written in Python with the qSharp ...
1
vote
2answers
246 views

How can I create an n-dimensional Hadamard transform in Q#?

I would like to create a n-dimensional Hadamard transform in Q# with n in set of even integers.
2
votes
1answer
27 views

What's the relationship between output of qubit measurements and classification of data in Quantum Machine Learning?

I'm training a model in Q# which has more than 2 features. I have trouble understanding the following things: How is the data classified based on the qubit states? For example: If I have only 2 ...
-1
votes
1answer
54 views

Difference between $Rz$ and $R1$ gate [closed]

You are given an operation that implements a single-qubit unitary transformation: either the Rz gate or the R1 gate. The operation will have Adjoint and Controlled variants defined. Your task is to ...
1
vote
2answers
58 views

How can I create a basis state of $n$ qubits in Q#?

I would like to create a set of basis qubits. For example if I have $n=2$ I should get 4 states being 01 10 11 00. Generalized for $2^n$. Is there a way to do this in Q#?
5
votes
2answers
332 views

Checking value of variable using quantum approach

A beginner question after watching few videos. Say, var=a; var can be either of two values, ...
2
votes
0answers
39 views

Is it possible to create a gate in Q# that is dictated by a matrix?

When observing the Hadamard gate it is simply a transformation matrix. I am wondering if there is functionality to hard code an arbitrary transformation matrix and its family members up till $m \times ...
0
votes
0answers
39 views

How do you decide which rotations to use in a Quantum Machine Learning model?

I am trying to design a model using Q#'s machine learning library that takes in two features (real numbers from 0 to 1) and classifies as 0 or 1. So how do I decide which Rotations and what seeds to ...
-2
votes
0answers
25 views

How to solve these questions? [duplicate]

Link: v.ht/qhash. Here are some of the best questions available on the net, if anyone could code them in Q#, then it would be great. By solving you will gain experience on qubits, quantum gates, ...
2
votes
2answers
86 views

Q# Error: No namespace with the name “Microsoft.Quantum.MachineLearning” exists

I'm having trouble getting the namespace Microsoft.Quantum.MachineLearning. Here is an example Q# code: ...
-4
votes
0answers
45 views

Qubit Operations [closed]

You are given an operation that implements a two-qubit unitary transformation: either the CNOT gate with the first qubit as control and the second qubit as target (CNOT12), or the CNOT gate with the ...
2
votes
1answer
38 views

Graph coloring - Q# -

I am checking Q# - Graph coloring for (C in 0 .. (1 <<< N) - 1) { InitializeColor(C, register); Can you help me explain ...
4
votes
1answer
154 views

qsharp.reload() throws error in python

I'm trying to add the Q# machine learning library to my program by ...
0
votes
1answer
33 views

Is there a way to grab probablities of my qubits in Q#?

https://qiskit.org/textbook/ch-algorithms/grover.html I am looking for a visual, or just probabilities like the ones given in the link.Is this possible on Q#?
0
votes
1answer
29 views

dotnet iqsharp install gives error “FileNotFoundError: The system cannot find the path specified”

installing Q# version g --version 0.1.2.3 in jupyter. but this command line dotnet iqsharp install responds system cannot find path specified . what should i do . i have also installed vscode ...
1
vote
0answers
32 views

Attempting to use the QuantumMachineLearning Repositry with vscode and now import qsharp is reporting 'Fail'

I have been trying to follow the Quantum machine learning kata by using vscode and jupyter notebook, I was using the wrong version of iqsharp so changed it in the code like so: As can be seen the ...
2
votes
1answer
109 views

Installing Q# in jupyter

I have followed all steps described in https://docs.microsoft.com/en-us/quantum/install-guide/qjupyter But I am unable to get through part 3. It is showing syntax error in Python terminal in Jupyter ...
0
votes
1answer
48 views

How do I encode integers into BigEndian in Q#?

https://export.arxiv.org/ftp/arxiv/papers/1908/1908.07943.pdf page 4 point 1 states that we use the bits of an integer as a basis in our space. I understand that BigEndian grabs our largest bit and ...
1
vote
0answers
122 views

Q# Quantum.MachineLearning namespace doesn't exist error

I am trying to use the HalfMoon Classifier in Quantum Machine Learning Sample Examples. I am trying to run it locally. However I keep getting this error. ...
2
votes
1answer
63 views

How to apply a gate to a LittleEndian in Q#

I have been given a LittleEndian register. I want to know the following things: How many bits there are in the LittleEndian? How to convert the LittleEndian into a Qubit[] Array. How to access ...
2
votes
1answer
45 views

Creating a W state for $2^k$ qubits

This question is available in Quantum Katas here In Task 2.6 of this notebook, we are required to create the W State for $2^k$ qubits. Input: $𝑁=2^𝑘$ qubits in ...
1
vote
0answers
84 views

How can I initialize a state with chosen amplitudes in Qiskit?

I was trying to initialize to an arbitrary state of n qubits with the initialize() from Qiskit but it doesn't generate a state with the same amplitudes passed as an ...
1
vote
2answers
179 views

Passing an array of qubits into Q# using Python

I am trying to learn Q# and have very limited knowledge in Q#. As the title suggests, I am trying to pass an array of qubits into an operation using a python script ...
1
vote
1answer
24 views

'Unable to import' error message in Q# using VS Code

I'm a complete beginner in Q#. Consider the code in the following image: For some reason, there always is an error message when I try to import anything. It also implies to keywords like ...
1
vote
1answer
25 views

Change single qubit state in Q#

I am starting with Q# and I would like to know how can I get the following qubit state: 0.8|0⟩ + 0.2|1⟩ from a qubit initialized as |0⟩. Thanks in advance!
3
votes
1answer
124 views

Creating Hamiltonian Simulation Operator in Q#

I am trying to create a unitary operator $U = \sum^{T - 1}_{k=0}$ $|k\rangle$ $\langle k |$ $ \otimes$ $e^{i A k}$ in Q#, where A is a Hermitian matrix. For the beginning, I just want A to be a ...
0
votes
1answer
61 views

Error running Q# notebooks: Syntax does not match any known patterns

C:/snippet_.qs(1,85): error QS3001: Syntax does not match any known patterns. C:/snippet_.qs(1,26): error QS6104: No namespace with the name "Microsoft.Quantum.Intrinsic" exists. C:/snippet_.qs(7,17): ...
1
vote
1answer
33 views

How can I run Q# program in Azure Quantum

I have already made a small Q# program and ran it using Python on VSCode, my question is how can I run it on Azure Quantum to make it run faster? Q# program : ...
2
votes
1answer
83 views

Are there patterns in the numbers created with qrng by entangled qubits?

I want to examine the graph of 2 sets consisting of 1000 numbers created with quantum random number generator which were created by entangled qubits and see if there is a pattern in the randomly ...
0
votes
1answer
54 views

Tensor Product in Q#

Does anyone know how you can obtain a new state |z> from two pre-existing states |x> and ...
3
votes
1answer
60 views

Inner product of states in Q#

I have a state $|x\rangle$ and I want to get the expected result when measuring observable $A$ (i.e. get the result of $\langle x| A | x \rangle$). In my case $A$ can be any of the Pauli gates. Does ...
2
votes
1answer
73 views

Generic matrix exponential in Q#

I am trying to find a way to implement a unitary transformation in Q# that implements e^(iA) where A is a square matrix. However, I only found ways to do this in Q# if A can be represented as a ...
1
vote
1answer
62 views

Why don't I get what I expect when measuring with respect to a different basis?

$\newcommand{\bra}[1]{\left<#1\right|}\newcommand{\ket}[1]{\left|#1\right>}\newcommand{\bk}[2]{\left<#1\middle|#2\right>}\newcommand{\bke}[3]{\left<#1\middle|#2\middle|#3\right>}$ If ...
7
votes
2answers
349 views

From Q# measurements to Bloch sphere

I would like to represent the state of a qubit on a Bloch sphere from the measurements made with Q#. According the documentation, it is possible to measure a qubit in the different Pauli bases (...
1
vote
1answer
23 views

How to use ApplyToEach when operation has parameters?

Problem Apply a global phase -1 to all qubits x : Qubit[]. My solution ApplyToEach(R, PauliI, 2.0 * PI(), x) However this ...
2
votes
1answer
88 views

Is it possible to write a Q# teleportation code which returns a qubit?

Is it possible to write a Q# teleportation code which returns a qubit? Thanks.
2
votes
2answers
118 views

Unit testing for quantum programs?

Does unit testing on real quantum computers make sense as any observation in the quantum system can cause the system to loose its superposition state?
0
votes
1answer
43 views

How to retrieve the parameters of a Q# operation?

How to retrieve the parameters of a Q# operation? Is it possible to do such a thing at all?
1
vote
2answers
69 views
0
votes
2answers
267 views

Problems with Q# installing

I don't know if this is the right place to ask this question. I just thought it would be a place where people knew what they are doing. If there is a better place to look for answers (stackoverflow ...
1
vote
1answer
81 views

Controlled NOT gate using multiple control qubits in Q#

I am trying to implement the Grover's search algorithm using Q# and I am not able to implement the oracle (black box) part for the search of state $|1010\rangle$. How to implement the controlled NOT ...
1
vote
0answers
173 views

IBM qiskit vs Microsoft QDK [closed]

I am new to both IBM Qiskit and Microsoft QDK. I wish to understand which framework would be best suited for someone new to this field. I am lookig for the pros and cons of both frameworks.
2
votes
2answers
93 views

Is it possible to create a Q# operation with optional parameters?

In C# it is possible to have: public void Fun (int n = 0){ // ... } then the following method call examples will be compiled: ...
0
votes
0answers
61 views

How to reduce the length of Q# programs execution time?

In the released Q# documentation by Microsoft available at: Quantum Development Kit Full State Simulator, it is written By default OpenMP uses all available hardware threads, which means that ...
3
votes
1answer
108 views

How to invoke a C# method inside a Q# operation?

Suppose there is a Q# operation as follows: operation Op () : Bool { let result = CSharpMethod (); return result } where ...