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
9
votes
1answer
306 views

Ground state energy estimation - VQE vs. Ising vs. Trotter–Suzuki

Disclaimer: I am a software engineer who is curious about quantum computing. Although I understand some basic concepts, theory and math behind it, I am by no means experienced in this domain. I am ...
8
votes
2answers
165 views

Can we perform quantum mechanical simulations using a quantum computer?

I'm a computer science major who's really keen on physics and quantum mechanics. I have started learning about Q# and D-Wave, but I just wanted to know if it's possible to test quantum mechanical ...
7
votes
1answer
1k views

How many logical qubits are needed to run Shor's algorithm efficiently on large integers ($n > 2^{1024}$)?

First, I know there are differences in logical qubits and physical qubits. It takes more physical qubits for each logical qubit due to quantum error. Wikipedia states that it takes quantum gates of ...
7
votes
2answers
143 views

How does one obtain amplitude information in Q#?

Is it possible to obtain amplitude information (in lexicographic ordering) for a particular qubit register in Q#? For example, in the following code: ...
7
votes
2answers
419 views

How to construct the “Inversion About the Mean” operator?

It seems like it should be simple, based on how Nielsen and Chuang talk about it, but I cannot seem to correctly implement the Inversion About the Mean operator ($2|\psi\rangle \langle\psi| - \mathcal{...
7
votes
3answers
606 views

How do you send an array of qubits to an operation in Q#?

I have the following operation in my .qs files: operation myOp(qubits: Qubit[]) : () { // uses elements from the qubit array } How do I send an ...
7
votes
2answers
348 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 (...
6
votes
2answers
279 views

Quantum counting in Q#

I cannot seem to get an estimate for the number of solutions using the quantum counting algorithm described in Nielsen and Chuang, i.e. phase estimation with the Grover iteration acting as $U$. I try ...
5
votes
1answer
163 views

Q# factorization Method Program

Is there a method to calculate prime factorization in Q# of Visual Studio of Microsoft Quantum Development Kit? In the Python language, it is the sympy.factorint ...
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, ...
4
votes
2answers
110 views

How do I produce circuit diagrams from a Q# program?

If I implement an adder operation in Q#, I'd like to see a quantum circuit diagram of what that adder is doing in order to check that it looks right. Is there a built-in way to do this?
4
votes
2answers
147 views

Does Q# have a bigint type?

Shor's algorithm works with very large integers; larger than 64 bits. So the built-in 64-bit Int type is insufficient for doing the classical processing (e.g. ...
4
votes
1answer
103 views

What is the corresponding code for finding the state of a qubit on the Bloch sphere?

To find the state of a qubit on the Bloch sphere we use the following formula: \begin{equation} |\psi\rangle=\mathrm{cos}\frac{\theta}{2}|0\rangle+\mathrm{e}^{i\phi}\mathrm{sin}\frac{\theta}{2}|1\...
4
votes
1answer
191 views

How do I write functions that modify operations in Q#?

In Q#'s type documentation, it is mentioned that you can create signatures like this: ...
4
votes
1answer
108 views

How to see the QASM code corresponding to compiled Q# function?

I'm learning Q#. Is there any way to see the QASM code of a Q# function I write, the same way I can see the disassembly of a C# function?
4
votes
1answer
100 views

How do I name the adjoint of an operation in Q#?

For example, if I've defined the operation PlusEqual, I'd like to say operation MinusEqual = Adjoint PlusEqual; but this ...
4
votes
1answer
477 views

Creating controlled R1 gates in Q#?

I know how to create controlled versions of gates like X, Y, Z. For example, a controlled X gate would be implemented by writing (Controlled X)([control],target); ...
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 ...
4
votes
2answers
295 views

Finding the maximum number of Q# simulatable qubits

I'm new to Q# and I was curious on how one would find the number of Q# simulatable qubits for a specific machine. I know Microsoft has an approximation of 16GB ~ 30 qubits but I wanted a better ...
3
votes
2answers
523 views

How to compute the inverse of an operation in Q#?

I want to implement amplitude amplification using Q#. I have the operation $A$ that prepares my initial state and I need to compute $ A^{-1} $ to implement the algorithm. Is there an easy way to do ...
3
votes
1answer
95 views

How do I get a list of control qubits from Q# operations when tracing the simulation in C#?

I want to write code that prints out the controls of each operation executed during a simulation in Q#. For example this code prints the control counts: ...
3
votes
2answers
291 views

Big Endian vs. Little Endian in Qiskit

I've noticed that Q# favors Little Endian. Meaning that most operations are designed for this type of encoding. Is is it the same with Qiskit?
3
votes
1answer
832 views

Practical example of Grover's algorithm (in Q#)

Is there any real example for Grover's algorithm but with real database (generated from SQL or file)? I download the Q# development kit & its example, there was one call DatabaseSearchExample ...
3
votes
1answer
44 views

How can I transform a Result into a Bool in Q# + C# environment?

I'm writing a Q# program and I'm calling an operation defined in the program that outputs a Result (One or ...
3
votes
1answer
185 views

Counting in Q#: number of solutions

I have this program derived from Microsoft Quantum Katas for counting (see here): ...
3
votes
1answer
62 views

How do I do printf debugging in Q# in a convenient way?

When initially writing an operator in Q#, I often want to see intermediate values of registers during the computation. This allows me to check that I haven't made ...
3
votes
1answer
770 views

How to measure in an arbitrary basis in Q#?

Q# has a measurement operator defined as follows according to the docs: operation Measure (bases : Pauli[], qubits : Qubit[]) : Result Where you give a Pauli gate ...
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 ...
3
votes
1answer
59 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 ...
3
votes
1answer
65 views

Type error creating R gate in Q#?

The R operation in Q# is listed by Microsoft in the documentation as follows operation R (pauli : Pauli, theta : Double, qubit : Qubit) : Unit However, when I try ...
3
votes
1answer
123 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 ...
2
votes
2answers
118 views

Is programming in quantum computer same as programming in quantum simulator in classical computer?

I just started programming in Q# and I wonder if the coding for Q# in classical computer would be the same as coding in a quantum computer. Obviously, these 2 kinds of computers work differently, so I ...
2
votes
3answers
185 views

How do I start as a quantum computing programmer?

How do I learn Q#? What languages should I know prior to learning Q#? How do I get started with quantum computing?
2
votes
1answer
102 views

How do I multiply an integer and a double in Q#?

If I write this: function f(n: Int) : Double { return 1.5*n; } I get an error: ...
2
votes
1answer
168 views

How to add two integers in Q#?

I have programmed in C++, but I am interested in writing quantum programs. I have some experience with Microsoft's Q#, and I know about the canonical Shor's and Grover's algorithms. Can anyone tell ...
2
votes
1answer
37 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 ...
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: ...
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
44 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 ...
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 ...
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: ...
2
votes
1answer
52 views

Hamming with prefix oracle

I'm doing the Q# quantum katas and I'm stuck on an oracle in the Deutsch-Josza algorithm katas. Let $|x\rangle=|x_0x_1\dots x_{n-1}\rangle$ be a qubit array and $r$ be bit string of $k\leq n$. The $...
2
votes
1answer
120 views

An algorithm with the Hadamard operator

My goal in writing this algorithm in Q# was that func would either output (1,2) or (10,20), ...
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 ...
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?
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
1answer
61 views

How do these alternative Q# algorithms produce the same set of Bell states?

In the "Superposition" Microsoft quantum katas (https://github.com/microsoft/QuantumKatas/blob/master/Superposition/ReferenceImplementation.qs) the solution for Task 7 looks like this: ...
2
votes
1answer
68 views

Programmatic access to wavefunction in Q# for tests

I'm trying to write unit tests for some small Q# operations. It would be ideal if I could access the wavefunction. Is there a way to get it? I found ...
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 ...
2
votes
0answers
38 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 ...