Hot answers tagged

12

The question is about how many logical qubits it takes to implement Shor's algorithm for factoring an integer $N$ of bit-size $n$, i.e., a non-negative integer $N$ such that $1 \leq N \leq 2^n{-}1$. The question is a poignant one and not easy to answer as there are various tradeoffs possible (e.g., between number of qubits and circuit size). Executive ...


9

Yes, it is possible to obtain this information, but only for troubleshooting purposes, not for using it in the code. Dump functions dump the status of the target machine into a file or to the console output. If the program is executed on the full-state simulator, this status will include the wave function of the whole system (for DumpMachine) or of the ...


7

Unfortunately, there is indeed currently no way to generate circuit diagrams from a Q# program. Since this is a feature request, consider making it here: https://quantum.uservoice.com/forums/906940-debugging-and-simulation. To give a little bit of context, Q# makes a conscious effort to encourage reasoning about quantum algorithms in terms of control flow ...


6

arg.Value contains the actual tuple that the controlled operation receives at runtime. It's a two item tuple in which the first item is the control qubits, and the second another tuple with the arguments the operation normally expects, so in your case you are only interested in the first item of this tuple. Overall, arg.Value can be anything, thus it has ...


6

There is none at the moment (as of version 0.3). We're working on adding it as a primitive type, hopefully it will be included in the next release.


6

First, let's represent operation $2|\psi\rangle \langle\psi| - \mathcal{I}$ as $H^{\otimes n}(2|0\rangle \langle0| - \mathcal{I})H^{\otimes n}$, as Nielsen and Chuang do. Doing $H^{\otimes n}$ is easy - it's just ApplyToEach(H, register). $2|0\rangle \langle0| - \mathcal{I}$ flips the phase of all computational basis states except $|0...0\rangle$. Let's ...


6

A separate note on using simulators for this (as opposed to using an actual quantum computer). Simulators, like the one that ships with Q#, are built to simulate quantum mechanical theories as we understand them now. This means that any experiment you run on a simulator will behave exactly as the theory says (well, unless the simulator has a bug in the code)...


6

Running programs on a quantum computer will indeed require some routines which are not required for running them on a classical simulation. Two easiest examples are error correction (a classical simulation is perfect but a quantum device will be noisy and will require error correction to produce useful results) and translating logical qubits and gates to ...


6

In each of the examples you mentioned, the task breaks very roughly down into two steps: finding a Hamiltonian that describes the problem in terms of qubits, and finding the ground state energy of that Hamiltonian. From that perspective, the Jordan–Wigner transform is a way to find a qubit Hamiltonian corresponding to a given fermionic Hamiltonian. Once you ...


5

In general, there are exactly two ways to allocate qubits in Q#: the using statement, and the borrowing statement. Both can only be used from within Q#, and can't be directly used from within C#. Thus, you'd likely want to make a new Q# operation to serve as the "entry point" from C#; this new operation would then be responsible for allocating qubits and ...


5

The problem you are describing (i.e. finding an approximation of some state given some number of identical copies of it and some set of measurements) is known as quantum state tomography or state tomography for short. In practise, the most efficient schemes for state tomography will depend on a specific experiment's setup and limitations, for which ...


5

So far, it is better to say that the Grover Search algorithm, while presented as an algorithm searching through a database, would not be suited for such purpose. We prefer to say that we search through inputs of a function (the famous oracle). Loading the database/list in a quantum form would be costly in terms of qubits so for now it is not the best ...


5

Integer factorization sample in the official Quantum Development Kit samples repository implements Shor's algorithm in Q# and shows how to call it from C#.


5

For this example, one obtains a function with that signature by partial application of an operation that is defined outside the body, instead of as a lambda in the function. As a concrete example, consider this non-generic version of the WithA operation, modified from Q# canon. operation WithA( outer : (Qubit[] => Unit : Adjoint), inner : (Qubit[...


5

You want the Microsoft.Quantum.Extensions.Convert.ToDouble function (deprecated in favor of Microsoft.Quantum.Convert.IntAsDouble in 0.6 release). open Microsoft.Quantum.Extensions.Convert; function f(n: Int) : Double { return 1.5*ToDouble(n); } The reason it works this way is because in Q# (Num a) => a -> a -> a is not the same as (Num a,Num ...


5

As given in the documentation, if your operation is unitary, you can add the statement adjoint auto; within the operation after the body block. This will generate the adjoint (which is the inverse for unitary). Then, to use the inverse call Adjoint A(parameters)


5

In the case that your operation can be represented by a unitary operator $U$ (this is typically the case if your operation doesn't use any measurements), you can indicate that by adding is Adj to your operation's signature, letting the Q# compiler know that your operation is adjointable: open Microsoft.Quantum.Math as Math; /// # Summary /// Prepares a ...


4

You can define an immutable symbol for MinusEqual inside the body of an operation which will use it (you can't define it globally): operation UseMinusEqual () : Unit { ... let MinusEqual = Adjoint PlusEqual; MinusEqual(...); } If you need MinusEqual to be a globally visible operation, there is no shorthand syntax for this right now, so the only ...


4

You will need quantum circuits called adders. You have for example one from Cuccaro et al. and another from Himanshu et al.


4

Let's say you want to distinguish two states: $$|A\rangle = \cos \alpha |0\rangle + \sin \alpha |1\rangle \\ |B\rangle = -\sin \alpha |0\rangle + \cos \alpha |1\rangle$$ For your particular example $\cos \alpha = \frac {\sqrt{3}}{2}$ and $\sin \alpha = \frac{1}{2}$, so $\alpha = \frac{\pi}{6}$. These states are orthogonal and can be obtained from $|0\...


4

What do you mean by "Quantum Mechanical Simulations" ? One of the primary motivations in the early history of quantum computing was a statement from Richard Feynman that a quantum computer would be able to effectively simulate quantum systems. To that end, a lot of the nearest term quantum programs people are trying to run (and have run) are simulations of ...


4

For Toffoli simulator in particular, DumpRegister will provide this information. For example, the following code operation XorTest() : Bool { using ((a, b) = (Qubit[2], Qubit[2])) { // initialize: a = 1, b = 2 ApplyPauli([PauliI, PauliX], a); ApplyPauli([PauliX, PauliI], b); // check initialization Message("a = ");...


4

I have a theory as for where the issue comes from (huge thanks to Robin for helping me figure it out!) Grover iteration consists of four steps: Apply the oracle. Apply the Hadamard transform. Perform a conditional phase shift. Apply the Hadamard transform. ConditionalPhaseFlip operation in the Q# code implements the third step: it gives a phase shift of -...


4

Q# is not compiled into QASM, so that would be tricky. Q# compilation and execution process is approximately as follows: Q# code is parsed into an internal data structure representing an abstract syntax tree. This data structure undergoes some transformations (for example, to generate adjoint and controlled versions of operations used in the code). I don't ...


4

Probably the first big reference I would highlight is qsharp.community. Its a community org where we work on projects and collecting learning materials for Q#. Contributions are always welcome, so just make a PR on a repo or hop on the gitter and say hi! I'll also add that I am working on a textbook that is currently in Early Access called Learn Quantum ...


3

All qubits must be allocated by the Simulator, so you can't create an instance and pass it down to your Operation. Why do you want to create the Qubits on the driver? If anything, you should create an "entry" method on Q# that just allocates your qubits and then call your operation, and call that from the Driver.


3

Comparing your code to the reference implementation for the Grover search quantum kata, I think the problem might be in the way you're using your oracle in GroverPow. It's a little hard to tell, but if your Oracle is flipping the state of the ancilla based on whether or not the state is a "hit", you're then not including the ancilla in the rest of the ...


3

Thanks for posting the full Q# code! The problem is in testPr1: you're calling func() twice, and returning the first element of the tuple returned from the first call, and the second element of the tuple returned from the second call. Each call operates on a different qubit and performs a separate random measurement, so all 4 possible combinations should ...


3

Q#'s full state simulator has an OnOperationStart and OnOperationEnd events that, as the names imply, are triggered every time a quantum operation starts/ends. Thus the easiest way to get and print the sequence of gates would be to attach a handler to the OnOperationStart, for example: using (var qsim = new QuantumSimulator()) { ...


3

One problem is that you are resetting the $\left|z\right\rangle$ register after applying the Controlled X(z, y) operation. Right before you reset, your $\left|z\right\rangle$ register is entangled with the other two registers, such that resetting in that way collapses any superposition on the $\left|x\right\rangle \left|y\right\rangle$ registers. While that'...


Only top voted, non community-wiki answers of a minimum length are eligible