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

6

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

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

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

In Cirq v0.5.0 and later you can use the controlled_by method on any Operation: op = cirq.X(target_qubit).controlled_by(control_qubit) You can also use controlled_by on any Gate, i.e. before specifying the target qubits: op = cirq.X.controlled_by(control_qubit).on(target_qubit) And you can also make a controlled version of the gate with an initially ...

4

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[0], qb[1], qb[2], qb[3], qb[4]); circuit = ...

4

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

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

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

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

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

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

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 \... 1 If you want a random computational basis state, set the input state to the integer random.randint(0, 2**qubits-1). If you want a random superposition sampled from the Haar measure, there is a method cirq.testing.random_superposition(dim=2**qubits). Once you have created your initial state, you pass it into the simulator like cirq.Simulator().simulate(... 1 The following code snippet will do almost what you want: class MyLayerGate(cirq.Gate): def _decompose_(self, qubits): a, b, c = qubits return my_layer(a, b, c) # [will be unnecessary in v0.5.0] workaround for cirq.unitary ignoring _decompose_: def _unitary_(self): return cirq.unitary( cirq.Circuit.from_ops(... 1 You have to put an extra SWAP-gate after the QFT, see this circuit. Furthermore, the two controlled-Z gates on the same qubit are not necessary. This can reduce the circuit further to this. 1 This looks right, although I would emphasise that it is not really best practice to have to ask this question at this stage. The whole point of doing a particularly simple example is so that you can confirm that it's doing what you've already calculated analytically. It's quite important to do the analytic bit first to avoid confirmation bias. Anyway, let's ... 1 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 ...

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