# Tag Info

12

Bristlecone's native operation is the CZ, not CNOTs. However, you can transform between the two with Hadamard gates so this is sort of a trivial difference. Bristlecone can perform a CZ between any adjacent pair of qubits on a grid. You can see the grid by installing cirq and printing out the Bristlecone device: $pip install cirq$ python >>> ...

9

From the original blog post presenting the Bristlecone quantum chip, here is the connectivity map of the chip: Each cross represent a qubit, with nearest-neighbour connectivity. If you number the qubits from left to right, top to bottom (just like how you read english), starting by $0$ then the connectivity map would be given by: connectivity_map = { i ...

7

GridQubit has comparison methods defined, so sorted will give you a list of the qubits in row-major order: >>> sorted(cirq.google.Foxtail.qubits) [GridQubit(0, 0), GridQubit(0, 1), [...] GridQubit(1, 9), GridQubit(1, 10)] Once you have that, you're one list comprehension away: >>> [(q.row, q.col) for q in sorted(cirq.google.Foxtail....

7

Take a look again at the Hamiltonian, which is $$H = \sum_{\langle i, j \rangle} J_{i j} Z_i Z_j + \sum_{i} h_i Z_i$$ Then notice that ZPowGate is generated by the the Pauli Z operator, and CZPowGate is equivalent to an operator generated by $Z \otimes Z$ up to single-qubit rotations. The idea is that Step 2 of the ansatz corresponds to applying a pulse ...

6

This is actually very easy in Cirq. The controlled_by method can be used to automatically make any given gate controlled by an arbitrary number of control qubits. Here is a simple example for creating an X gate with 5 controls: import cirq qb = [cirq.LineQubit(i) for i in range(6)] cnX = cirq.X.controlled_by(qb, qb, qb, qb, qb) circuit = ...

6

Yes, it is possible to create controlled gates with an exponent in Cirq. For the specific case of the Z gate, Cirq includes a dedicated CZ gate that can be raised to a power: cs = cirq.CZ**0.5 More generally, cirq.ControlledGate works on any gate. It's a bit clunkier than the dedicated gates, but it does support being raised to a power (as long as the ...

6

You can use the controlled_by method on any Operation: op = cirq.X(target_qubit).controlled_by(control_qubit) You can also use controlled before specifying the target qubits: op = cirq.X.controlled().on(control_qubit, target_qubit) There are also built-in controlled operations such as cirq.CNOT, cirq.CZ, and cirq.CSWAP. The built-in operations are ...

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

5

Cirq uses numpy's pseudo random number generator to pick measurement results, e.g. here is code from XmonStepper.simulate_measurement: def simulate_measurement(self, index: int) -> bool: [...] prob_one = np.sum(self._pool.map(_one_prob_per_shard, args)) result = bool(np.random.random() <= prob_one) [...] Cirq ...

5

Cirq distinguishes between "running" a circuit, which is generally supposed to act like hardware would (e.g. only getting samples), and "simulating" a circuit, which has more freedom. Most "simulate" methods, like cirq.Simulator().simulate(...) have a parameter initial_state which can either be a computational basis state (specified as an integer e.g. ...

5

When using a simulator, it doesn't really matter what kind of qubit you refer to. You can even mix-and-match the types. The type of qubit only becomes relevant when you intend to run on a device, because devices have qubits at specific locations. For example, if you wanted to run on Bristlecone, you would limit yourself to GridQubit instances that actually ...

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

If you are looking for a more complete implementation of a quantum variational algorithm in the context of Cirq, I would recommend looking at the second example in the OpenFermion-Cirq notebook found here. It uses a custom ansatz for hydrogen in a minimal basis, but makes a bit more explicit all the required pieces. Another good example, perhaps without ...

3

The Fourier transform part (everything from the swaps onward) looks correct. The initialization (column of Hadamards) looks correct. But the part where you do controlled modular multiplications doesn't, because there's no operations controlled on the 2nd through fifth qubits that you are QFT-ing. You also seem to expect the output to be the period, when ...

3

You can test stand alone the a modular multiplication circuit. In this case $\text{base} = 2$ and $N = 3$. However the smallest useful composite $N = 15 = 3 \times 5$. Let's take a well known Multiplication by 7 modulo 15 circuit We start with input $$\ |1\rangle \text{ gives } |7\rangle$$ $$\ |7\rangle \text{ gives } |4\rangle$$ $$\ |4\rangle \text{ gives ... 3 The current version of PyQuil provides an "ISA" object that houses the information that you want about Rigetti's quantun processors, but it isn't formatted as you request. I'm a poor Python programmer, so you'll have to excuse my non-Pythonic-ness—but here's a snippet that will take a device_name and reformat the pyQuil ISA into one of your dictionaries: ... 3 Looking at the documentation and the GitHub, there is a something called ControlledGate. This class is said to augment existing gates with a control qubit. You can look at the test file. I can see line 72 : cxa = cirq.ControlledGate(cirq.X**cirq.Symbol('a')) Could you try: gate = cirq.ControlledGate(cirq.X**0.5) ? 3 This is going to change somewhat radically in the next version of cirq, so I'll give an answer for both versions. In v0.3, in order for a simulator to understand a custom gate, the gate must implement either cirq.CompositeGate or cirq.KnownMatrix. For your case, the simplest is to implement the matrix: # assuming cirq v0.3 import cirq import numpy as np ... 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 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 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())) 2 I searched for doing a custom gate on the Cirq documentation and here are the results : Gate sets The xmon simulator is designed to work with operations that are either a GateOperation applying an XmonGate, a CompositeOperation that decomposes (recursively) to XmonGates, or a 1-qubit or 2-qubit operation with a KnownMatrix. By default the ... 2 The endian-ness of the qubits is the answer. Both QFT and phase estimation rely on certain endianness of the register, and the representations used in the controlled-unitary part has to match the endianness used in the QFT part (and in the answer). This circuit produces the expected outcome with the inverse QFT block: 2 In the current release of Cirq (0.4.0) there is a strong limitation on symbols: you can't scale them or add them (Why? We were worried about being pulled down the rabbit hole of implementing a whole symbolic algebra system.). Making matters worse, Cirq internally works in radians divided by pi to avoid some minor sources of floating point error. So when you ... 2 This is the matrix for Z^t:$$Z^t = \begin{bmatrix} 1&0\\0&(-1)^t \end{bmatrix} = \begin{bmatrix} 1&0\\0&e^{i \pi t} \end{bmatrix}$$This is the matrix for R_Z(\pi t):$$R_Z(\pi t) = e^{-iZt/2} = \begin{bmatrix} e^{-i \pi t / 2}&0\\0&e^{+i \pi t / 2} \end{bmatrix} = e^{-i \pi t/2} Z^t $$Which means that$$Z^t \equiv R_Z(\pi ...

2

Note that $$RX(\phi) = \begin{pmatrix} \cos(\phi/2) & -i\sin(\phi/2) \\-isin(\phi/2) & \cos(\phi/2)\end{pmatrix}$$ Then $$RX(\pi q) = \begin{pmatrix} \cos(\pi q/2) & -i\sin(\pi q/2) \\-isin(\pi q/2) & \cos(\pi q/2)\end{pmatrix}.$$ Now, using that $\cos(\pi k + \pi/2) = 0 = \sin(\pi k)$ and $\cos(\pi k) = 1 = \sin(\pi k + \pi/2)$ for \$k\in \...

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

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]) There is more detail about how to use it in this tutorial

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)

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