Hot answers tagged

6

You're right in the sense that the cost unitary, which is composed of all the $Z$ and $CZ$ gates does not affect the underlying probabilities of measuring a specific state by itself, however when we apply the mixer (the layer of $Rx$ gates), the probabilities are changed, due to these added phases. Let's look at a basic example, to convince you that ...


4

One simple way to do it is by defining a composite gate, like this: class MyGateThenDepolarize(cirq.SingleQubitGate): def _decompose_(self, qubits): q = qubits[0] return [MyGate.on(q), cirq.depolarize(p).on(q)] If you want a depolarizing gate on every qubit at the end of every moment, you can do a noisy simulation: cirq.sample(circuit, ...


3

From the spec, $U_2(\phi, \lambda) = U ( \frac{\pi}{2}, \phi, \lambda)$. We can use Cirq's QasmUGate. import cirq from cirq.circuits.qasm_output import QasmUGate q0 = cirq.NamedQubit('q[0]') u2_gate = QasmUGate(0.5, 0, 1) # The angles are normalized to the range [0, 2) half_turns circuit = cirq.Circuit(u2_gate(q0))


3

Your mental model of how cirq works is slightly off. You don't invoke operations on a qubit in one line and then check how that qubit changed in another line. You create a circuit in one line and then ask about its properties, such as its effect on a qubit, in another line. In this case, you want to ask what the final_wavefunction of your circuit is and ...


3

On hardware, the number of moments is the relevant metric. That is why cirq focuses on that. To compute circuit depth in cirq, create a new circuit using just the operations. It defaults to packing them as tightly as possible, so the number of moments will be the depth. depth = len(cirq.Circuit(my_circuit.all_operations()))


3

What is the design philosophy behind the moment-based quantum circuit? What are the advantages and disadvantages of it? The basic idea is that we wanted to give users more control over what will actually happen on hardware. Whether or not two gates are run in parallel is really important information when dealing with noise (e.g. it determines total runtime),...


3

If you call initialize in this case, you will be specifying a general state in $\mathbb{C}^8$. However what you have is more specialized. For example only having 4 nonzero amplitudes. So the call to initialize won't know this a priori. So it won't realize the initialization circuit can be decomposed easily. Or at least it will need to do some extra ...


3

You can initialize a quantum state by using the QuantumCircuit.initialize() function. For example, to initialize a circuit into the state |1>, we can perform the initialization as follows : vector = [0,1] qr = QuantumRegister(1) qc = QuantumCircuit(qr) qc.initialize(vector, [qr[0]]) There is more detail about how to use it in this tutorial


2

I am definitely biased (writing a book on quantum computing with Python and Q#), but I am a Pythonista and love using Q#. The design of the language is good for long term quantum computing development; it allows you to think more at the algorithmic level, not at the assembly level as many other quantum programming languages are targeting. It has a Jupyter ...


2

I would suggest to start with Quirk as it offers a drag-and-drop circuit model. Furthermore, Quirk offers some subroutines such as basic arithmetic operation (on integers) and allows to easily define new subroutines. (All drag an drop!) It can simulate up to 17 (?) qubits. Once you want to go beyond an "easy" circuit representation I suggest Microsofts Q#. ...


2

cirq.Ry is a method that, given an angle, returns a gate. You then apply the gate to a qubit: cirq.Ry(angle).on(qubit) or, equivalently but a bit more confusingly: cirq.Ry(angle)(qubit)


2

Generally, yes, it is expected that you would define your own device and perhaps your own qubits in order to make custom topologies. There is currently a graph device package in the "contrib" package, which allows you to specify the connectivity graph for a device. But as with anything in contrib it may be a bit clunky and could disappear/change from ...


2

am I sure that the compiler will always be able to decompose this big gate into a succession of smaller, allowed gates, without breaking the complexity No, you're not. This is the whole problem with algorithms, be they classical or quantum. However, in the specific case you're talking about, there is a nice implementation. Imagine that you want to apply ...


2

In the tutorial, the RY gate is used. What you are using is different. If you look at the corresponding documentation of that gate, you would see: Note in particular that this gate has a global phase factor of e^{i·π·t/2} vs the traditionally defined rotation matrices about the Pauli Y axis. This may explain the difference. You can use instead the ...


1

MyTwoQubitGate().on(q1, q2).controlled_by(c) or MyTwoQubitGate().controlled().on(c, q1, q2)


1

You specified a matrix whose size is consistent with a four qubit gate, not a three qubit gate. Also, the matrix isn't unitary (it has columns containing nothing but zeros). The matrix' size must be consistent with the number of qubits that the gate applies to. Do this: def _unitary_(self): st = np.sin(self.theta) ct = np.cos(self.theta) ...


1

You're looking for cirq.resolve_parameters(object, resolver), which returns the object after the parameters have been resolved. For example: import cirq import sympy q = cirq.LineQubit(0) s = sympy.Symbol('s') symbol_op = cirq.X(q)**s resolved_op = cirq.resolve_parameters(symbol_op, {s: 0.25}) print(resolved_op) # X**0.25(0) symbol_circuit = cirq.Circuit(...


1

Yes, pointing at the github repository is how to cite Cirq. You can also optionally set the author to "The Cirq Contributors".


1

There is currently no code in cirq that attempts to rewrite connectivity-violating operations into a series of connectivity-satisfying operations. The reasoning for not including this functionality is basically that it is expected that any such rewriting step will produce a circuit that is longer than any realistic noise budget. There are tools that work ...


1

tl;dr: You need to compute the average of the parity of the observed bitstrings, with an understanding that the circuit was executed with some appended measurement gates like $V_{measure} U(\theta)$. Check out footnote 3 for an example implementation in Cirq. The core idea of how to do this is fairly simple, but I'm going to provide a series of ...


1

You say "I believe any state is always normalized, so that $|\alpha|^2 + |\beta|^2 = 1$", but you don't apply this to your calculation. The summation of squares of the absolute values is what gets the appropriate answer. For a single qubit system, $|\psi\rangle = \alpha|0\rangle + \beta|1\rangle$ and $|\alpha|^2 + |\beta|^2 = 1$. For a multiqubit system (3 ...


1

In my opinion, at the moment, qiskit is the most suitable one for learning and teaching. For a basic introductory material (we have used it in 14 two-day or three-day workshops), I recommend the following repo: https://gitlab.com/qkitchen/basics-of-quantum-computing the link to workshops: https://qsoftware.lu.lv/index.php/workshops/


1

Cirq's simulator is a state vector simulator, which cannot be told to focus on the amplitude of a specific output state or combination of output states. Some tensor network based simulators can get benefit from focusing on a specific output state, but there isn't such a simulator in Cirq.


1

cirq.ZPowGate(exponent=t/pi).controlled_by(control_qubit).on(target_qubit) or equivalently cirq.CZ(control_qubit, target_qubit)**(t / pi)


1

The other answers seem outdated, so here is an answer written for Cirq v0.7.0. Applying a unitary matrix is basically constructing a custom gate, and a simple example for a qubit is shown below. The gate below simply converts 0 -> 1 and 1 -> 0, but more complex examples are possible. import cirq import numpy as np class QubitPlusGate(cirq....


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