# Tag Info

15

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 ...

10

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 ...

9

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 ...

8

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 ...

7

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

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

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

Qiskit uses little-endian for both classical bit ordering and qubit ordering. For classical bits: A 3-bit classical register creg with value abc has creg[0]=c, creg[1]=b, creg[2]=a. For qubits: The ordering is with respect to the tensor-product structure of the state space. So a 3-qubit quantum register qreg with wave-function $|\psi\rangle = |A\otimes B\... 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 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 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 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 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 ... 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 ... 5 Prepare a qubit in state$|\psi\rangle=\mathrm{cos}\frac{\theta}{2}|0\rangle+\mathrm{e}^{i\phi}\mathrm{sin}\frac{\theta}{2}|1\rangle$, given the angles$\psi$and$\theta$. Let's start with a qubit in the$|0\rangle$state, as is customary for Q#. You can use one of the general library operations to prepare the state, such as PrepareArbitraryState. Or you ... 5 One possibility is to override a default implementation using an alternative one for a specific simulator. Here, init_and would be the default implementation as in the uncommented code and CCNOT would be the alternative. In the Q# libraries, we have the exact same case for Microsoft.Quantum.Canon.ApplyAnd and Microsoft.Quantum.Canon.ApplyLowDepthAnd. Here is ... 5 Thanks for your question! If you're interested in running multiple shots of a quantum operation, Q# allow for doing that with conventional programming techniques such as a for loop: open Microsoft.Quantum.Arrays; open Microsoft.Quantum.Measurement; operation SampleRandomBit() : Result { using (q = Qubit()) { return MResetX(q); } } operation ... 5 You can create an array with every second element starting from the second one using the expression array[1..2...]. 5 Just as with classical computing, we don't expect that in quantum computing the choice of a programming language will have a direct effect on the time and space complexity of most algorithms. That is, while C, Python, Rust, and Swift are all very different programming languages, quicksort is a$O(n \ln n)$algorithm in all of them. Rather, classical ... 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 -...

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