class FakeSycamoreGate(cirq.FSimGate): def __init__(self): super().__init__(theta=np.pi / 2, phi=np.pi / 6) @pytest.mark.parametrize( 'qubits, depth, two_qubit_op_factory, pattern, ' 'single_qubit_gates, add_final_single_qubit_layer, ' 'seed, expected_circuit_length, single_qubit_layers_slice, ' 'two_qubit_layers_slice', ( ( cirq.GridQubit.rect(4, 3), 20, lambda a, b, _: cirq.CZ(a, b), cirq.experiments.GRID_STAGGERED_PATTERN, (cirq.X ** 0.5, cirq.Y ** 0.5, cirq.Z ** 0.5), True, 1234, 41, slice(None, None, 2), slice(1, None, 2), ), ( cirq.GridQubit.rect(4, 3), 20, lambda a, b, _: FakeSycamoreGate()(a, b), cirq.experiments.HALF_GRID_STAGGERED_PATTERN, (cirq.X ** 0.5, cirq.Y ** 0.5, cirq.Z ** 0.5), True,
def test_without_operations_touching(): a = cirq.NamedQubit('a') b = cirq.NamedQubit('b') c = cirq.NamedQubit('c') # Empty case. assert Moment().without_operations_touching([]) == Moment() assert Moment().without_operations_touching([a]) == Moment() assert Moment().without_operations_touching([a, b]) == Moment() # One-qubit operation case. assert (Moment([cirq.X(a) ]).without_operations_touching([]) == Moment([cirq.X(a)])) assert (Moment([cirq.X(a)]).without_operations_touching([a]) == Moment()) assert (Moment([cirq.X(a) ]).without_operations_touching([b]) == Moment([cirq.X(a)])) # Two-qubit operation case. assert (Moment([cirq.CZ(a, b)]).without_operations_touching([]) == Moment( [cirq.CZ(a, b)])) assert (Moment([cirq.CZ(a, b)]).without_operations_touching([a]) == Moment()) assert (Moment([cirq.CZ(a, b)]).without_operations_touching([b]) == Moment()) assert (Moment([cirq.CZ(a, b)]).without_operations_touching([c]) == Moment( [cirq.CZ(a, b)])) # Multiple operation case. assert (Moment([cirq.CZ(a, b), cirq.X(c)]).without_operations_touching( []) == Moment([cirq.CZ(a, b), cirq.X(c)])) assert (Moment([cirq.CZ(a, b), cirq.X(c) ]).without_operations_touching([a]) == Moment([cirq.X(c)])) assert (Moment([cirq.CZ(a, b), cirq.X(c) ]).without_operations_touching([b]) == Moment([cirq.X(c)])) assert (Moment([cirq.CZ(a, b), cirq.X(c)]).without_operations_touching( [c]) == Moment([cirq.CZ(a, b)])) assert (Moment([cirq.CZ(a, b), cirq.X(c) ]).without_operations_touching([a, b]) == Moment([cirq.X(c)])) assert (Moment([cirq.CZ(a, b), cirq.X(c)]).without_operations_touching([a, c]) == Moment())
def generator(depth): if depth <= 0: yield cirq.CZ(q0, q1), cirq.Y(q0) else: yield cirq.X(q0), generator(depth - 1) yield cirq.Z(q0)
def test_merge_complex_circuit_preserving_moment_structure(): q = cirq.LineQubit.range(3) c_orig = cirq.Circuit( cirq.Moment(cirq.H.on_each(*q)), cirq.CNOT(q[0], q[2]), cirq.CNOT(*q[0:2]), cirq.H(q[0]), cirq.CZ(*q[:2]), cirq.X(q[0]), cirq.Y(q[1]), cirq.CNOT(*q[0:2]), cirq.CNOT(*q[1:3]).with_tags("ignore"), cirq.X(q[0]), cirq.Moment( cirq.X(q[0]).with_tags("ignore"), cirq.Y(q[1]), cirq.Z(q[2])), cirq.Moment(cirq.CNOT(*q[:2]), cirq.measure(q[2], key="a")), cirq.X(q[0]).with_classical_controls("a"), strategy=cirq.InsertStrategy.NEW, ) cirq.testing.assert_has_diagram( c_orig, ''' 0: ───H───@───@───H───@───X───────@─────────────────X───X['ignore']───@───X─── │ │ │ │ │ ║ 1: ───H───┼───X───────@───────Y───X───@['ignore']───────Y─────────────X───╫─── │ │ ║ 2: ───H───X───────────────────────────X─────────────────Z─────────────M───╫─── ║ ║ a: ═══════════════════════════════════════════════════════════════════@═══^═══ ''', ) component_id = 0 def rewriter_merge_to_circuit_op( op: 'cirq.CircuitOperation') -> 'cirq.OP_TREE': nonlocal component_id component_id = component_id + 1 return op.with_tags(f'{component_id}') c_new = cirq.merge_k_qubit_unitaries( c_orig, k=2, context=cirq.TransformerContext(tags_to_ignore=("ignore", )), rewriter=rewriter_merge_to_circuit_op, ) cirq.testing.assert_has_diagram( cirq.drop_empty_moments(c_new), ''' [ 0: ───H───@─── ] [ 0: ───────@───H───@───X───@───X─── ] [ 0: ───────@─── ] 0: ───[ │ ]────────[ │ │ │ ]──────────────────────X['ignore']───────────[ │ ]────────X─── [ 2: ───H───X─── ]['1'] [ 1: ───H───X───────@───Y───X─────── ]['2'] [ 1: ───Y───X─── ]['4'] ║ │ │ │ ║ 1: ───┼─────────────────────────#2────────────────────────────────────────────@['ignore']─────────────────────────#2────────────────────────╫─── │ │ ║ 2: ───#2──────────────────────────────────────────────────────────────────────X─────────────[ 2: ───Z─── ]['3']───M─────────────────────────╫─── ║ ║ a: ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════@═════════════════════════^═══''', ) component_id = 0 def rewriter_replace_with_decomp( op: 'cirq.CircuitOperation') -> 'cirq.OP_TREE': nonlocal component_id component_id = component_id + 1 tag = f'{component_id}' if len(op.qubits) == 1: return [cirq.T(op.qubits[0]).with_tags(tag)] one_layer = [op.with_tags(tag) for op in cirq.T.on_each(*op.qubits)] two_layer = [cirq.SQRT_ISWAP(*op.qubits).with_tags(tag)] return [one_layer, two_layer, one_layer] c_new = cirq.merge_k_qubit_unitaries( c_orig, k=2, context=cirq.TransformerContext(tags_to_ignore=("ignore", )), rewriter=rewriter_replace_with_decomp, ) cirq.testing.assert_has_diagram( cirq.drop_empty_moments(c_new), ''' 0: ───T['1']───iSwap['1']───T['1']───T['2']───iSwap['2']───T['2']─────────────────X['ignore']───T['4']───iSwap['4']───T['4']───X─── │ │ │ ║ 1: ────────────┼─────────────────────T['2']───iSwap^0.5────T['2']───@['ignore']─────────────────T['4']───iSwap^0.5────T['4']───╫─── │ │ ║ 2: ───T['1']───iSwap^0.5────T['1']──────────────────────────────────X─────────────T['3']────────M──────────────────────────────╫─── ║ ║ a: ═════════════════════════════════════════════════════════════════════════════════════════════@══════════════════════════════^═══''', )
def test_ignores_2qubit_target(): c = cirq.Circuit(cirq.CZ(*cirq.LineQubit.range(2))) assert_optimizes(optimized=cirq.merge_k_qubit_unitaries(c, k=1), expected=c)
def _decompose_(self, qubits): yield cirq.CZ(qubits[0], qubits[1]) yield CompositeDummy()(qubits[1])
'phasedxzgate': { 'x_exponent': { 'float_value': 0.125 }, 'z_exponent': { 'float_value': 0.5 }, 'axis_phase_exponent': { 'float_value': 0.25 }, }, 'qubit_constant_index': [0], }), ), ( cirq.CZ(Q0, Q1), op_proto({ 'czpowgate': { 'exponent': { 'float_value': 1.0 } }, 'qubit_constant_index': [0, 1] }), ), ( cirq.CZPowGate(exponent=0.5)(Q0, Q1), op_proto({ 'czpowgate': { 'exponent': { 'float_value': 0.5
a += gate b -= gate prefix = gates[:i + 1] expected_a = cirq.LinearCombinationOfGates(collections.Counter(prefix)) expected_b = -expected_a assert_linear_combinations_are_equal(a, expected_a) assert_linear_combinations_are_equal(b, expected_b) @pytest.mark.parametrize('op', ( cirq.X(q0), cirq.Y(q1), cirq.XX(q0, q1), cirq.CZ(q0, q1), cirq.FREDKIN(q0, q1, q2), cirq.ControlledOperation((q0, q1), cirq.H(q2)), cirq.ParallelGateOperation(cirq.X, (q0, q1, q2)), cirq.PauliString({ q0: cirq.X, q1: cirq.Y, q2: cirq.Z }), )) def test_empty_linear_combination_of_operations_accepts_all_operations(op): combination = cirq.LinearCombinationOfOperations({}) combination[op] = -0.5j assert len(combination) == 1
def to_cirq(self, input_cirq_qubits=None): """Convert to a cirq gate. Args: input_cirq_qubits: list[cirq.LineQubit] (optional) a list of cirq Qubits that the gate can act on. If not provided the function will generate new cirq.LineQubit objects. Returns: A cirq Circuit object that corresponds to the specification of the quantum gate. In the special case the gate itself was natively generated from cirq, the function will faithfully reproduce the original GateOperation object, taking into account whether the gate acts on GridQubit objects or LineQubit objects. In the other cases the resulting cirq gate simply assumes that the qubits are LineQubit objects. """ if self.name not in ALL_GATES: sys.exit("Gate {} currently not supported.".format(self.name)) q_inds = [] q_inds.append(self.qubits[0].index) if len(self.qubits) >= 2: q_inds.append(self.qubits[1].index) if len(self.qubits) >= 3: q_inds.append(self.qubits[2].index) cirq_qubits = [] if input_cirq_qubits == None: for q in self.qubits: if q.info["label"] == "cirq": qkey = q.info["QubitKey"] if q.info["QubitType"] == "GridQubit": cirq_qubits.append(cirq.GridQubit(qkey[0], qkey[1])) if q.info["QubitType"] == "LineQubit": cirq_qubits.append(cirq.LineQubit(qkey)) else: cirq_qubits.append(cirq.LineQubit(q.index)) else: cirq_qubits = [ input_cirq_qubits[x] for x in [q.index for q in self.qubits] ] if len(self.params) > 0: params = self.params # single-qubit gates if self.name == "I": # Identity return cirq.I(cirq_qubits[0]) if self.name == "X": # Pauli X return cirq.X(cirq_qubits[0]) if self.name == "Y": # Pauli Y return cirq.Y(cirq_qubits[0]) if self.name == "Z": # Pauli Z return cirq.Z(cirq_qubits[0]) if self.name == "H": # Hadamard return cirq.H(cirq_qubits[0]) if self.name == "S": # S gate return cirq.S(cirq_qubits[0]) if self.name == "T": # T gate return cirq.T(cirq_qubits[0]) if self.name == "Rx": # Single-qubit X rotation return cirq.Rx(params[0])(cirq_qubits[0]) if self.name == "Ry": # Single-qubit Y rotation return cirq.Ry(params[0])(cirq_qubits[0]) if self.name == "Rz": # Single-qubit Z rotation return cirq.Rz(params[0])(cirq_qubits[0]) if self.name == "PHASE": # Phase gate return cirq.Z(cirq_qubits[0])**(params[0] / pi) if self.name == "ZXZ": # PhasedXPowGate gate g = cirq.PhasedXPowGate(phase_exponent=params[0] / pi, exponent=params[1] / pi) return g(cirq_qubits[0]) if self.name == "RH": # HPowGate g = cirq.H**(params[0] / pi) return g(cirq_qubits[0]) if self.name == "Da": # Damping alpha gate g = DampingAlpha(params[0]) return g(cirq_qubits[0]) if self.name == "Db": # Damping beta gate g = DampingBeta(params[0]) return g(cirq_qubits[0]) # two-qubit gates if self.name == "CNOT": return cirq.CNOT(cirq_qubits[0], cirq_qubits[1]) if self.name == "CZ": return cirq.CZ(cirq_qubits[0], cirq_qubits[1]) if self.name == "CPHASE": return cirq.CZPowGate(exponent=params[0] / pi)(cirq_qubits[0], cirq_qubits[1]) if self.name == "SWAP": return cirq.SWAP(cirq_qubits[0], cirq_qubits[1]) if self.name == "XX": return cirq.XX(cirq_qubits[0], cirq_qubits[1])**(params[0] * 2 / pi) if self.name == "YY": return cirq.YY(cirq_qubits[0], cirq_qubits[1])**(params[0] * 2 / pi) if self.name == "ZZ": return cirq.ZZ(cirq_qubits[0], cirq_qubits[1])**(params[0] * 2 / pi)
def test_merge_operations_raises(): q = cirq.LineQubit.range(3) c = cirq.Circuit(cirq.CZ(*q[:2]), cirq.X(q[0])) with pytest.raises(ValueError, match='must act on a subset of qubits'): cirq.merge_operations(c, lambda *_: cirq.X(q[2]))
def test_repr(): a = cirq.NamedQubit('a') b = cirq.NamedQubit('b') original = Moment([cirq.CZ(a, b)]) cirq.testing.assert_equivalent_repr(original)
# create an empty circuit circuit = cq.Circuit() # construct a simulator to run the circuit sim = cq.google.XmonSimulator() #%% ## The indexing of lineQubits is such that the high-order bit (top wire) is ## index 0. ## initialize starting state to |11> circuit.append(cq.X(qubits[1])) circuit.append([cq.H(qubits[0]), cq.H(qubits[1])]) circuit.append(cq.CZ(qubits[0], qubits[1])) # solution to puzzle 4-7 circuit.append(cq.CZ(qubits[0], qubits[1])) circuit.append([cq.H(qubits[0]), cq.H(qubits[1])]) # finish with standard measurement on both bits circuit.append( [cq.MeasurementGate(key="q" + str(1 - i))(qubits[i]) for i in range(2)]) print(circuit) #%% # "Run" the computation 20 times. result = sim.run(circuit, repetitions=20)
def test_ignore_non_composite(): q0, q1 = cirq.LineQubit.range(2) circuit = cirq.Circuit() circuit.append([cirq.X(q0), cirq.Y(q1), cirq.CZ(q0, q1), cirq.Z(q0)]) assert_optimizes(None, circuit.copy(), circuit)
from cirq import Circuit from cirq.devices import GridQubit from cirq.google import XmonSimulator # creating circuit with 4 qubits #define length of qubits l = 4 #setting up qubits on grid qubits = [cirq.GridQubit(x, y) for x in range(l) for y in range(l)] #defining the cirquit circuit = cirq.Circuit() #all the gates r applied to the circuit man its like deep learninig neural model h1 = cirq.H(qubits[2]) toffoli = cirq.TOFFOLI(qubits[2], qubits[3], qubits[4]) h2 = cirq.H(qubits[1]) h3 = cirq.H(qubits[2]) h4 = cirq.H(qubits[3]) cz1 = cirq.CZ(qubits[2], qubits[1]) cz2 = cirq.CZ(qubits[2], qubits[3]) #constructing moments of gates to apply on circuit moment1 = cirq.Moment([h1]) moment2 = cirq.Moment([toffoli]) moment3 = cirq.Moment([h1]) moment4 = cirq.Moment([h2, h3, h4]) moment5 = cirq.Moment([cz1]) moment6 = cirq.Moment([cz2]) moment7 = cirq.Moment([h2, h3, h4]) circuit = cirq.Circuit( (moment1, moment2, moment3, moment4, moment5, moment6, moment7)) simulator = cirq.google.XmonSimulator() result = simulator.simulate(circuit) #print(result) print(circuit)
def test_pass_operations_over_cz(): q0, q1 = _make_qubits(2) op0 = cirq.CZ(q0, q1) ps_before = cirq.PauliString({q0: cirq.Z, q1: cirq.Y}) ps_after = cirq.PauliString({q1: cirq.Y}) _assert_pass_over([op0], ps_before, ps_after)
def test_sensitive_to_measurement_but_not_measured_phase(): q = cirq.NamedQubit('q') with pytest.raises(AssertionError): cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent( cirq.Circuit([ cirq.Moment([cirq.measure(q)]) ]), cirq.Circuit(), atol=1e-8) cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent( cirq.Circuit([ cirq.Moment([cirq.measure(q)]) ]), cirq.Circuit([ cirq.Moment([cirq.Z(q)]), cirq.Moment([cirq.measure(q)]), ]), atol=1e-8) a, b = cirq.LineQubit.range(2) cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent( cirq.Circuit([ cirq.Moment([cirq.measure(a, b)]) ]), cirq.Circuit([ cirq.Moment([cirq.Z(a)]), cirq.Moment([cirq.measure(a, b)]), ]), atol=1e-8) cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent( cirq.Circuit([ cirq.Moment([cirq.measure(a)]) ]), cirq.Circuit([ cirq.Moment([cirq.Z(a)]), cirq.Moment([cirq.measure(a)]), ]), atol=1e-8) cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent( cirq.Circuit([ cirq.Moment([cirq.measure(a, b)]) ]), cirq.Circuit([ cirq.Moment([cirq.T(a), cirq.S(b)]), cirq.Moment([cirq.measure(a, b)]), ]), atol=1e-8) with pytest.raises(AssertionError): cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent( cirq.Circuit([ cirq.Moment([cirq.measure(a)]) ]), cirq.Circuit([ cirq.Moment([cirq.T(a), cirq.S(b)]), cirq.Moment([cirq.measure(a)]), ]), atol=1e-8) cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent( cirq.Circuit([ cirq.Moment([cirq.measure(a, b)]) ]), cirq.Circuit([ cirq.Moment([cirq.CZ(a, b)]), cirq.Moment([cirq.measure(a, b)]), ]), atol=1e-8)
def test_circuit_to_compute_and_feed_dict_small(n: int): qs = cirq.LineQubit.range(n) c = cirq.Circuit([cirq.X(q)**(0.13 * i + 0.1) for i, q in enumerate(qs)], [[cirq.CZ(a, b), cirq.X(a)**0.5, cirq.H(b)] for a in qs for b in qs if a < b]) _assert_evaluates_correctly(c)
def test_json_dict(): a = cirq.NamedQubit('a') b = cirq.NamedQubit('b') mom = cirq.Moment([cirq.CZ(a, b)]) assert mom._json_dict_() == {'operations': (cirq.CZ(a, b), )}
assert np.allclose( thermal_choi, [ [1, 0, 0, 9.99750031e-01], [0, 2.49968753e-04, 0, 0], [0, 0, 0, 0], [9.99750031e-01, 0, 0, 9.99750031e-01], ], ) @pytest.mark.parametrize( 'op', [ cirq.ISWAP(*cirq.LineQubit.range(2))**0.6, cirq.CZ(*cirq.LineQubit.range(2))**0.3, ], ) def test_two_qubit_gates(op): q0, q1 = cirq.LineQubit.range(2) props = TestNoiseProperties( **default_props([q0, q1], [(q0, q1), (q1, q0)])) model = NoiseModelFromNoiseProperties(props) circuit = cirq.Circuit(op) noisy_circuit = circuit.with_noise(model) assert len(noisy_circuit.moments) == 3 assert len(noisy_circuit.moments[0].operations) == 1 assert noisy_circuit.moments[0].operations[0] == op.with_tags( PHYSICAL_GATE_TAG) # Depolarizing noise
import cirq import numpy as numpy from cirq.devices import GridQubit from cirq.google import XmonSimulator length = 4 qubits = [cirq.GridQubit(x, y) for x in range(length) for y in range(length)] print("qubits") circuit = cirq.Circuit() H1 = cirq.H(qubits[2]) TOFFOLI = cirq.TOFFOLI(qubits[2], qubits[3], qubits[4]) H2 = cirq.H(qubits[1]) H3 = cirq.H(qubits[2]) H4 = cirq.H(qubits[3]) CZ1 = cirq.CZ(qubits[2], qubits[1]) CZ2 = cirq.CZ(qubits[2], qubits[3]) moment1 = cirq.moment([H1]) moment2 = cirq.moment([TOFFOLI]) moment3 = cirq.moment([H1]) moment4 = cirq.moment([H2, H3, H4]) moment5 = cirq.moment([CZ1]) moment6 = cirq.moment([CZ2]) moment7 = cirq.moment([H2, H3, H4]) circuit = cirq.Circuit( (moment1, moment2, moment3, moment4, moment5, moment6, moment7)) print(circuit) simulator = Xmonsimulator() result = simulator.simulate(circuit) print(result)
def test_crosses_czs(): a = cirq.NamedQubit('a') b = cirq.NamedQubit('b') x = sympy.Symbol('x') y = sympy.Symbol('y') z = sympy.Symbol('z') # Full CZ. assert_optimizes( before=quick_circuit( [cirq.PhasedXPowGate(phase_exponent=0.25).on(a)], [cirq.CZ(a, b)], ), expected=quick_circuit( [cirq.Z(b)], [cirq.CZ(a, b)], [cirq.PhasedXPowGate(phase_exponent=0.25).on(a)], ), ) assert_optimizes( before=quick_circuit( [cirq.PhasedXPowGate(phase_exponent=0.125).on(a)], [cirq.CZ(b, a)], ), expected=quick_circuit( [cirq.Z(b)], [cirq.CZ(a, b)], [cirq.PhasedXPowGate(phase_exponent=0.125).on(a)], ), ) assert_optimizes( before=quick_circuit( [cirq.PhasedXPowGate(phase_exponent=x).on(a)], [cirq.CZ(b, a)], ), expected=quick_circuit( [cirq.Z(b)], [cirq.CZ(a, b)], [cirq.PhasedXPowGate(phase_exponent=x).on(a)], ), eject_parameterized=True, ) # Partial CZ. assert_optimizes( before=quick_circuit( [cirq.X(a)], [cirq.CZ(a, b) ** 0.25], ), expected=quick_circuit( [cirq.Z(b) ** 0.25], [cirq.CZ(a, b) ** -0.25], [cirq.X(a)], ), ) assert_optimizes( before=quick_circuit( [cirq.X(a)], [cirq.CZ(a, b) ** x], ), expected=quick_circuit( [cirq.Z(b) ** x], [cirq.CZ(a, b) ** -x], [cirq.X(a)], ), eject_parameterized=True, ) # Double cross. assert_optimizes( before=quick_circuit( [cirq.PhasedXPowGate(phase_exponent=0.125).on(a)], [cirq.PhasedXPowGate(phase_exponent=0.375).on(b)], [cirq.CZ(a, b) ** 0.25], ), expected=quick_circuit( [cirq.CZ(a, b) ** 0.25], [ cirq.PhasedXPowGate(phase_exponent=0.5).on(b), cirq.PhasedXPowGate(phase_exponent=0.25).on(a), ], ), ) assert_optimizes( before=quick_circuit( [cirq.PhasedXPowGate(phase_exponent=x).on(a)], [cirq.PhasedXPowGate(phase_exponent=y).on(b)], [cirq.CZ(a, b) ** z], ), expected=quick_circuit( [cirq.CZ(a, b) ** z], [ cirq.PhasedXPowGate(phase_exponent=y + z / 2).on(b), cirq.PhasedXPowGate(phase_exponent=x + z / 2).on(a), ], ), eject_parameterized=True, )
def test_moment_text_diagram(): a, b, c, d = cirq.GridQubit.rect(2, 2) m = cirq.Moment(cirq.CZ(a, b), cirq.CNOT(c, d)) assert (str(m).strip() == """ ╷ 0 1 ╶─┼───── 0 │ @─@ │ 1 │ @─X │ """.strip()) m = cirq.Moment(cirq.CZ(a, b), cirq.CNOT(c, d)) cirq.testing.assert_has_diagram( m, """ ╷ None 0 1 ╶──┼────────── aa │ │ 0 │ @─@ │ 1 │ @─X │ """, extra_qubits=[cirq.NamedQubit("aa")], ) m = cirq.Moment(cirq.S(c), cirq.ISWAP(a, d)) cirq.testing.assert_has_diagram( m, """ ╷ 0 1 ╶─┼───────────── 0 │ iSwap─┐ │ │ 1 │ S iSwap │ """, ) m = cirq.Moment(cirq.S(c)**0.1, cirq.ISWAP(a, d)**0.5) cirq.testing.assert_has_diagram( m, """ ╷ 0 1 ╶─┼───────────────── 0 │ iSwap^0.5─┐ │ │ 1 │ Z^0.05 iSwap │ """, ) a, b, c = cirq.LineQubit.range(3) m = cirq.Moment(cirq.X(a), cirq.SWAP(b, c)) cirq.testing.assert_has_diagram( m, """ ╷ a b c ╶─┼─────── 0 │ X │ 1 │ ×─┐ │ │ 2 │ × │ """, xy_breakdown_func=lambda q: ('abc'[q.x], q.x), ) class EmptyGate(cirq.Gate): def _num_qubits_(self) -> int: return 1 def __str__(self): return 'Empty' m = cirq.Moment(EmptyGate().on(a)) cirq.testing.assert_has_diagram( m, """ ╷ 0 ╶─┼─────── 0 │ Empty │ """, )
def test_merge_k_qubit_unitaries_deep(): q = cirq.LineQubit.range(2) h_cz_y = [cirq.H(q[0]), cirq.CZ(*q), cirq.Y(q[1])] c_orig = cirq.Circuit( h_cz_y, cirq.Moment(cirq.X(q[0]).with_tags("ignore"), cirq.Y(q[1])), cirq.CircuitOperation( cirq.FrozenCircuit(h_cz_y)).repeat(6).with_tags("ignore"), [cirq.CNOT(*q), cirq.CNOT(*q)], cirq.CircuitOperation(cirq.FrozenCircuit(h_cz_y)).repeat(4), [cirq.CNOT(*q), cirq.CZ(*q), cirq.CNOT(*q)], cirq.CircuitOperation( cirq.FrozenCircuit(h_cz_y)).repeat(5).with_tags("preserve_tag"), ) def _wrap_in_cop(ops: cirq.OP_TREE, tag: str): return cirq.CircuitOperation(cirq.FrozenCircuit(ops)).with_tags(tag) c_expected = cirq.Circuit( _wrap_in_cop([h_cz_y, cirq.Y(q[1])], '1'), cirq.Moment(cirq.X(q[0]).with_tags("ignore")), cirq.CircuitOperation( cirq.FrozenCircuit(h_cz_y)).repeat(6).with_tags("ignore"), _wrap_in_cop([cirq.CNOT(*q), cirq.CNOT(*q)], '2'), cirq.CircuitOperation(cirq.FrozenCircuit(_wrap_in_cop(h_cz_y, '3'))).repeat(4), _wrap_in_cop([cirq.CNOT(*q), cirq.CZ(*q), cirq.CNOT(*q)], '4'), cirq.CircuitOperation(cirq.FrozenCircuit(_wrap_in_cop( h_cz_y, '5'))).repeat(5).with_tags("preserve_tag"), strategy=cirq.InsertStrategy.NEW, ) component_id = 0 def rewriter_merge_to_circuit_op( op: 'cirq.CircuitOperation') -> 'cirq.OP_TREE': nonlocal component_id component_id = component_id + 1 return op.with_tags(f'{component_id}') context = cirq.TransformerContext(tags_to_ignore=("ignore", ), deep=True) c_new = cirq.merge_k_qubit_unitaries(c_orig, k=2, context=context, rewriter=rewriter_merge_to_circuit_op) cirq.testing.assert_same_circuits(c_new, c_expected) def _wrap_in_matrix_gate(ops: cirq.OP_TREE): op = _wrap_in_cop(ops, 'temp') return cirq.MatrixGate(cirq.unitary(op)).on(*op.qubits) c_expected_matrix = cirq.Circuit( _wrap_in_matrix_gate([h_cz_y, cirq.Y(q[1])]), cirq.Moment(cirq.X(q[0]).with_tags("ignore")), cirq.CircuitOperation( cirq.FrozenCircuit(h_cz_y)).repeat(6).with_tags("ignore"), _wrap_in_matrix_gate([cirq.CNOT(*q), cirq.CNOT(*q)]), cirq.CircuitOperation(cirq.FrozenCircuit( _wrap_in_matrix_gate(h_cz_y))).repeat(4), _wrap_in_matrix_gate([cirq.CNOT(*q), cirq.CZ(*q), cirq.CNOT(*q)]), cirq.CircuitOperation(cirq.FrozenCircuit( _wrap_in_matrix_gate(h_cz_y))).repeat(5).with_tags("preserve_tag"), strategy=cirq.InsertStrategy.NEW, ) c_new_matrix = cirq.merge_k_qubit_unitaries(c_orig, k=2, context=context) cirq.testing.assert_same_circuits(c_new_matrix, c_expected_matrix)
def test_unconstrained_undirected_graph_device_edge(): edge = ccgd.UnconstrainedUndirectedGraphDeviceEdge qubits = cirq.LineQubit.range(2) assert edge.duration_of(cirq.X(qubits[0])) == cirq.Duration(picos=0) assert edge.duration_of(cirq.CZ(*qubits[:2])) == cirq.Duration(picos=0)
def _cz_and_swap(q0, q1, rot): yield cirq.CZ(q0, q1)**rot yield cirq.SWAP(q0, q1)
def test_graph_device(): one_qubit_duration = cirq.Duration(picos=10) two_qubit_duration = cirq.Duration(picos=1) one_qubit_edge = ccgd.FixedDurationUndirectedGraphDeviceEdge( one_qubit_duration) two_qubit_edge = ccgd.FixedDurationUndirectedGraphDeviceEdge( two_qubit_duration) empty_device = ccgd.UndirectedGraphDevice() assert not empty_device.qubits assert not empty_device.edges n_qubits = 4 qubits = cirq.LineQubit.range(n_qubits) edges = {(cirq.LineQubit(i), cirq.LineQubit((i + 1) % n_qubits)): two_qubit_edge for i in range(n_qubits)} edges.update({(cirq.LineQubit(i), ): one_qubit_edge for i in range(n_qubits)}) device_graph = ccgd.UndirectedHypergraph(labelled_edges=edges) def not_cnots(first_op, second_op): if all( isinstance(op, cirq.GateOperation) and op.gate == cirq.CNOT for op in (first_op, second_op)): raise ValueError('Simultaneous CNOTs') assert ccgd.is_undirected_device_graph(device_graph) with pytest.raises(TypeError): ccgd.UndirectedGraphDevice('abc') constraint_edges = { (frozenset(cirq.LineQubit.range(2)), frozenset(cirq.LineQubit.range(2, 4))): None, (frozenset(cirq.LineQubit.range(1, 3)), frozenset((cirq.LineQubit(0), cirq.LineQubit(3)))): not_cnots } crosstalk_graph = ccgd.UndirectedHypergraph( labelled_edges=constraint_edges) assert ccgd.is_crosstalk_graph(crosstalk_graph) with pytest.raises(TypeError): ccgd.UndirectedGraphDevice(device_graph, crosstalk_graph='abc') graph_device = ccgd.UndirectedGraphDevice(device_graph) assert graph_device.crosstalk_graph == ccgd.UndirectedHypergraph() graph_device = ccgd.UndirectedGraphDevice(device_graph, crosstalk_graph=crosstalk_graph) assert sorted(graph_device.edges) == sorted(device_graph.edges) assert graph_device.qubits == tuple(qubits) assert graph_device.device_graph == device_graph assert graph_device.labelled_edges == device_graph.labelled_edges assert graph_device.duration_of(cirq.X(qubits[2])) == one_qubit_duration assert (graph_device.duration_of( cirq.CNOT(*qubits[:2])) == two_qubit_duration) with pytest.raises(KeyError): graph_device.duration_of(cirq.CNOT(qubits[0], qubits[2])) with pytest.raises(ValueError): graph_device.validate_operation(cirq.CNOT(qubits[0], qubits[2])) with pytest.raises(AttributeError): graph_device.validate_operation(list((2, 3))) moment = cirq.Moment([cirq.CNOT(*qubits[:2]), cirq.CNOT(*qubits[2:])]) with pytest.raises(ValueError): graph_device.validate_moment(moment) with pytest.raises(ValueError): scheduled_operations = (cirq.ScheduledOperation.op_at_on( op, cirq.Timestamp(), graph_device) for op in moment.operations) schedule = cirq.Schedule(graph_device, scheduled_operations) graph_device.validate_schedule(schedule) moment = cirq.Moment( [cirq.CNOT(qubits[0], qubits[3]), cirq.CZ(qubits[1], qubits[2])]) graph_device.validate_moment(moment) circuit = cirq.Circuit(moment, device=graph_device) schedule = cirq.moment_by_moment_schedule(graph_device, circuit) assert graph_device.validate_schedule(schedule) is None moment = cirq.Moment( [cirq.CNOT(qubits[0], qubits[3]), cirq.CNOT(qubits[1], qubits[2])]) with pytest.raises(ValueError): graph_device.validate_moment(moment) with pytest.raises(ValueError): scheduled_operations = (cirq.ScheduledOperation.op_at_on( op, cirq.Timestamp(), graph_device) for op in moment.operations) schedule = cirq.Schedule(graph_device, scheduled_operations) graph_device.validate_schedule(schedule)
def three_qubit_matrix_to_operations(q0: ops.Qid, q1: ops.Qid, q2: ops.Qid, u: np.ndarray, atol: float = 1e-8 ) -> Sequence[ops.Operation]: """Returns operations for a 3 qubit unitary. The algorithm is described in Shende et al.: Synthesis of Quantum Logic Circuits. Tech. rep. 2006, https://arxiv.org/abs/quant-ph/0406176 Args: q0: first qubit q1: second qubit q2: third qubit u: unitary matrix atol: A limit on the amount of absolute error introduced by the construction. Returns: The resulting operations will have only known two-qubit and one-qubit gates based operations, namely CZ, CNOT and rx, ry, PhasedXPow gates. Raises: ValueError: If the u matrix is non-unitary or not of shape (8,8). ImportError: If the decomposition cannot be done because the SciPy version is less than 1.5.0 and so does not contain the required `cossin` method. """ if np.shape(u) != (8, 8): raise ValueError( f"Expected unitary matrix with shape (8,8) got {np.shape(u)}") if not cirq.is_unitary(u, atol=atol): raise ValueError(f"Matrix is not unitary: {u}") try: from scipy.linalg import cossin except ImportError: # coverage: ignore # coverage: ignore raise ImportError( "cirq.three_qubit_unitary_to_operations requires " "SciPy 1.5.0+, as it uses the cossin function. Please" " upgrade scipy in your environment to use this " "function!") (u1, u2), theta, (v1h, v2h) = cossin(u, 4, 4, separate=True) cs_ops = _cs_to_ops(q0, q1, q2, theta) if len(cs_ops) > 0 and cs_ops[-1] == cirq.CZ(q2, q0): # optimization A.1 - merging the last CZ from the end of CS into UD # cz = cirq.Circuit([cs_ops[-1]]).unitary() # CZ(c,a) = CZ(a,c) as CZ is symmetric # for the u1⊕u2 multiplexor operator: # as u1(b,c) is the operator in case a = \0>, # and u2(b,c) is the operator for (b,c) in case a = |1> # we can represent the merge by phasing u2 with I ⊗ Z u2 = u2 @ np.diag([1, -1, 1, -1]) cs_ops = cs_ops[:-1] d_ud, ud_ops = _two_qubit_multiplexor_to_ops(q0, q1, q2, u1, u2, shift_left=True, atol=atol) _, vdh_ops = _two_qubit_multiplexor_to_ops(q0, q1, q2, v1h, v2h, shift_left=False, diagonal=d_ud, atol=atol) return list(cirq.Circuit(vdh_ops + cs_ops + ud_ops).all_operations())
def _get_valid_circuit_proto_pairs(): q0 = cirq.GridQubit(0, 0) q1 = cirq.GridQubit(0, 1) pairs = [ # HPOW and aliases. (cirq.Circuit(cirq.HPowGate(exponent=0.3)(q0)), _build_gate_proto("HP", ['exponent', 'exponent_scalar', 'global_shift'], [0.3, 1.0, 0.0], ['0_0'])), (cirq.Circuit(cirq.HPowGate(exponent=sympy.Symbol('alpha'))(q0)), _build_gate_proto("HP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 1.0, 0.0], ['0_0'])), (cirq.Circuit(cirq.HPowGate(exponent=3.0 * sympy.Symbol('alpha'))(q0)), _build_gate_proto("HP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 3.0, 0.0], ['0_0'])), (cirq.Circuit(cirq.H(q0)), _build_gate_proto("HP", ['exponent', 'exponent_scalar', 'global_shift'], [1.0, 1.0, 0.0], ['0_0'])), # XPOW and aliases. (cirq.Circuit(cirq.XPowGate(exponent=0.3)(q0)), _build_gate_proto("XP", ['exponent', 'exponent_scalar', 'global_shift'], [0.3, 1.0, 0.0], ['0_0'])), (cirq.Circuit(cirq.XPowGate(exponent=sympy.Symbol('alpha'))(q0)), _build_gate_proto("XP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 1.0, 0.0], ['0_0'])), (cirq.Circuit(cirq.XPowGate(exponent=3.0 * sympy.Symbol('alpha'))(q0)), _build_gate_proto("XP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 3.0, 0.0], ['0_0'])), (cirq.Circuit(cirq.X(q0)), _build_gate_proto("XP", ['exponent', 'exponent_scalar', 'global_shift'], [1.0, 1.0, 0.0], ['0_0'])), # YPOW and aliases (cirq.Circuit(cirq.YPowGate(exponent=0.3)(q0)), _build_gate_proto("YP", ['exponent', 'exponent_scalar', 'global_shift'], [0.3, 1.0, 0.0], ['0_0'])), (cirq.Circuit(cirq.YPowGate(exponent=sympy.Symbol('alpha'))(q0)), _build_gate_proto("YP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 1.0, 0.0], ['0_0'])), (cirq.Circuit(cirq.YPowGate(exponent=3.0 * sympy.Symbol('alpha'))(q0)), _build_gate_proto("YP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 3.0, 0.0], ['0_0'])), (cirq.Circuit(cirq.Y(q0)), _build_gate_proto("YP", ['exponent', 'exponent_scalar', 'global_shift'], [1.0, 1.0, 0.0], ['0_0'])), # ZPOW and aliases. (cirq.Circuit(cirq.ZPowGate(exponent=0.3)(q0)), _build_gate_proto("ZP", ['exponent', 'exponent_scalar', 'global_shift'], [0.3, 1.0, 0.0], ['0_0'])), (cirq.Circuit(cirq.ZPowGate(exponent=sympy.Symbol('alpha'))(q0)), _build_gate_proto("ZP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 1.0, 0.0], ['0_0'])), (cirq.Circuit(cirq.ZPowGate(exponent=3.0 * sympy.Symbol('alpha'))(q0)), _build_gate_proto("ZP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 3.0, 0.0], ['0_0'])), (cirq.Circuit(cirq.Z(q0)), _build_gate_proto("ZP", ['exponent', 'exponent_scalar', 'global_shift'], [1.0, 1.0, 0.0], ['0_0'])), # XXPow and aliases (cirq.Circuit(cirq.XXPowGate(exponent=0.3)(q0, q1)), _build_gate_proto("XXP", ['exponent', 'exponent_scalar', 'global_shift'], [0.3, 1.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit(cirq.XXPowGate(exponent=sympy.Symbol('alpha'))(q0, q1)), _build_gate_proto("XXP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 1.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit( cirq.XXPowGate(exponent=3.0 * sympy.Symbol('alpha'))(q0, q1)), _build_gate_proto("XXP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 3.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit(cirq.XX(q0, q1)), _build_gate_proto("XXP", ['exponent', 'exponent_scalar', 'global_shift'], [1.0, 1.0, 0.0], ['0_0', '0_1'])), # YYPow and aliases (cirq.Circuit(cirq.YYPowGate(exponent=0.3)(q0, q1)), _build_gate_proto("YYP", ['exponent', 'exponent_scalar', 'global_shift'], [0.3, 1.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit(cirq.YYPowGate(exponent=sympy.Symbol('alpha'))(q0, q1)), _build_gate_proto("YYP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 1.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit( cirq.YYPowGate(exponent=3.0 * sympy.Symbol('alpha'))(q0, q1)), _build_gate_proto("YYP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 3.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit(cirq.YY(q0, q1)), _build_gate_proto("YYP", ['exponent', 'exponent_scalar', 'global_shift'], [1.0, 1.0, 0.0], ['0_0', '0_1'])), # ZZPow and aliases (cirq.Circuit(cirq.ZZPowGate(exponent=0.3)(q0, q1)), _build_gate_proto("ZZP", ['exponent', 'exponent_scalar', 'global_shift'], [0.3, 1.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit(cirq.ZZPowGate(exponent=sympy.Symbol('alpha'))(q0, q1)), _build_gate_proto("ZZP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 1.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit( cirq.ZZPowGate(exponent=3.0 * sympy.Symbol('alpha'))(q0, q1)), _build_gate_proto("ZZP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 3.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit(cirq.ZZ(q0, q1)), _build_gate_proto("ZZP", ['exponent', 'exponent_scalar', 'global_shift'], [1.0, 1.0, 0.0], ['0_0', '0_1'])), # CZPow and aliases (cirq.Circuit(cirq.CZPowGate(exponent=0.3)(q0, q1)), _build_gate_proto("CZP", ['exponent', 'exponent_scalar', 'global_shift'], [0.3, 1.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit(cirq.CZPowGate(exponent=sympy.Symbol('alpha'))(q0, q1)), _build_gate_proto("CZP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 1.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit( cirq.CZPowGate(exponent=3.0 * sympy.Symbol('alpha'))(q0, q1)), _build_gate_proto("CZP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 3.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit(cirq.CZ(q0, q1)), _build_gate_proto("CZP", ['exponent', 'exponent_scalar', 'global_shift'], [1.0, 1.0, 0.0], ['0_0', '0_1'])), # CNOTPow and aliases (cirq.Circuit(cirq.CNotPowGate(exponent=0.3)(q0, q1)), _build_gate_proto("CNP", ['exponent', 'exponent_scalar', 'global_shift'], [0.3, 1.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit(cirq.CNotPowGate(exponent=sympy.Symbol('alpha'))(q0, q1)), _build_gate_proto("CNP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 1.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit( cirq.CNotPowGate(exponent=3.0 * sympy.Symbol('alpha'))(q0, q1)), _build_gate_proto("CNP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 3.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit(cirq.CNOT(q0, q1)), _build_gate_proto("CNP", ['exponent', 'exponent_scalar', 'global_shift'], [1.0, 1.0, 0.0], ['0_0', '0_1'])), # SWAPPow and aliases (cirq.Circuit(cirq.SwapPowGate(exponent=0.3)(q0, q1)), _build_gate_proto("SP", ['exponent', 'exponent_scalar', 'global_shift'], [0.3, 1.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit(cirq.SwapPowGate(exponent=sympy.Symbol('alpha'))(q0, q1)), _build_gate_proto("SP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 1.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit( cirq.SwapPowGate(exponent=3.0 * sympy.Symbol('alpha'))(q0, q1)), _build_gate_proto("SP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 3.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit(cirq.SWAP(q0, q1)), _build_gate_proto("SP", ['exponent', 'exponent_scalar', 'global_shift'], [1.0, 1.0, 0.0], ['0_0', '0_1'])), # ISWAPPow and aliases (cirq.Circuit(cirq.ISwapPowGate(exponent=0.3)(q0, q1)), _build_gate_proto("ISP", ['exponent', 'exponent_scalar', 'global_shift'], [0.3, 1.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit( cirq.ISwapPowGate(exponent=sympy.Symbol('alpha'))(q0, q1)), _build_gate_proto("ISP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 1.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit( cirq.ISwapPowGate(exponent=3.0 * sympy.Symbol('alpha'))(q0, q1)), _build_gate_proto("ISP", ['exponent', 'exponent_scalar', 'global_shift'], ['alpha', 3.0, 0.0], ['0_0', '0_1'])), (cirq.Circuit(cirq.ISWAP(q0, q1)), _build_gate_proto("ISP", ['exponent', 'exponent_scalar', 'global_shift'], [1.0, 1.0, 0.0], ['0_0', '0_1'])), # PhasedXPow and aliases (cirq.Circuit( cirq.PhasedXPowGate(phase_exponent=0.9, exponent=0.3, global_shift=0.2)(q0)), _build_gate_proto("PXP", [ 'phase_exponent', 'phase_exponent_scalar', 'exponent', 'exponent_scalar', 'global_shift' ], [0.9, 1.0, 0.3, 1.0, 0.2], ['0_0'])), (cirq.Circuit( cirq.PhasedXPowGate(phase_exponent=sympy.Symbol('alpha'), exponent=0.3)(q0)), _build_gate_proto("PXP", [ 'phase_exponent', 'phase_exponent_scalar', 'exponent', 'exponent_scalar', 'global_shift' ], ['alpha', 1.0, 0.3, 1.0, 0.0], ['0_0'])), (cirq.Circuit( cirq.PhasedXPowGate(phase_exponent=3.0 * sympy.Symbol('alpha'), exponent=0.3)(q0)), _build_gate_proto("PXP", [ 'phase_exponent', 'phase_exponent_scalar', 'exponent', 'exponent_scalar', 'global_shift' ], ['alpha', 3.0, 0.3, 1.0, 0.0], ['0_0'])), (cirq.Circuit( cirq.PhasedXPowGate(phase_exponent=0.9, exponent=sympy.Symbol('beta'))(q0)), _build_gate_proto("PXP", [ 'phase_exponent', 'phase_exponent_scalar', 'exponent', 'exponent_scalar', 'global_shift' ], [0.9, 1.0, 'beta', 1.0, 0.0], ['0_0'])), (cirq.Circuit( cirq.PhasedXPowGate(phase_exponent=0.9, exponent=5.0 * sympy.Symbol('beta'))(q0)), _build_gate_proto("PXP", [ 'phase_exponent', 'phase_exponent_scalar', 'exponent', 'exponent_scalar', 'global_shift' ], [0.9, 1.0, 'beta', 5.0, 0.0], ['0_0'])), (cirq.Circuit( cirq.PhasedXPowGate(phase_exponent=3.0 * sympy.Symbol('alpha'), exponent=5.0 * sympy.Symbol('beta'))(q0)), _build_gate_proto("PXP", [ 'phase_exponent', 'phase_exponent_scalar', 'exponent', 'exponent_scalar', 'global_shift' ], ['alpha', 3.0, 'beta', 5.0, 0.0], ['0_0'])), # RX, RY, RZ with symbolization is tested in special cases as the # string comparison of the float converted sympy.pi does not happen # smoothly. See: test_serialize_deserialize_special_case_one_qubit (cirq.Circuit(cirq.Rx(np.pi)(q0)), _build_gate_proto("XP", ['exponent', 'exponent_scalar', 'global_shift'], [1.0, 1.0, -0.5], ['0_0'])), (cirq.Circuit(cirq.Ry(np.pi)(q0)), _build_gate_proto("YP", ['exponent', 'exponent_scalar', 'global_shift'], [1.0, 1.0, -0.5], ['0_0'])), (cirq.Circuit(cirq.Rz(np.pi)(q0)), _build_gate_proto("ZP", ['exponent', 'exponent_scalar', 'global_shift'], [1.0, 1.0, -0.5], ['0_0'])), # Identity (cirq.Circuit(cirq.I(q0)), _build_gate_proto("I", ['unused'], [True], ['0_0'])), # FSimGate (cirq.Circuit(cirq.FSimGate(theta=0.1, phi=0.2)(q0, q1)), _build_gate_proto("FSIM", ['theta', 'theta_scalar', 'phi', 'phi_scalar'], [0.1, 1.0, 0.2, 1.0], ['0_0', '0_1'])), (cirq.Circuit( cirq.FSimGate(theta=2.0 * sympy.Symbol("alpha"), phi=1.3 * sympy.Symbol("beta"))(q0, q1)), _build_gate_proto("FSIM", ['theta', 'theta_scalar', 'phi', 'phi_scalar'], ['alpha', 2.0, 'beta', 1.3], ['0_0', '0_1'])), ] return pairs
(cirq.Y(q0), cirq.SingleQubitCliffordGate.Y(q0)), (cirq.Z(q0), cirq.SingleQubitCliffordGate.Z(q0)), (cirq.X(q0)**0.5, cirq.SingleQubitCliffordGate.X_sqrt(q0)), (cirq.Y(q0)**0.5, cirq.SingleQubitCliffordGate.Y_sqrt(q0)), (cirq.Z(q0)**0.5, cirq.SingleQubitCliffordGate.Z_sqrt(q0)), (cirq.X(q0)**-0.5, cirq.SingleQubitCliffordGate.X_nsqrt(q0)), (cirq.Y(q0)**-0.5, cirq.SingleQubitCliffordGate.Y_nsqrt(q0)), (cirq.Z(q0)**-0.5, cirq.SingleQubitCliffordGate.Z_nsqrt(q0)), (cirq.X(q0)**0.25, cirq.PauliStringPhasor(cirq.PauliString.from_single(q0, cirq.X))**0.25), (cirq.Y(q0)**0.25, cirq.PauliStringPhasor(cirq.PauliString.from_single(q0, cirq.Y))**0.25), (cirq.Z(q0)**0.25, cirq.PauliStringPhasor(cirq.PauliString.from_single(q0, cirq.Z))**0.25), (cirq.X(q0)**0, ()), (cirq.CZ(q0, q1), cirq.CZ(q0, q1)), (cirq.measure(q0, q1, key='key'), cirq.measure(q0, q1, key='key')), ))(cirq.LineQubit(0), cirq.LineQubit(1))) def test_converts_various_ops(op, expected_ops): before = cirq.Circuit(op) expected = cirq.Circuit(expected_ops, strategy=cirq.InsertStrategy.EARLIEST) after = converted_gate_set(before) assert after == expected cirq.testing.assert_allclose_up_to_global_phase( before.unitary(), after.unitary(qubits_that_should_be_present=op.qubits), atol=1e-7) cirq.testing.assert_allclose_up_to_global_phase( after.unitary(qubits_that_should_be_present=op.qubits),
def get_circuit(): """Gets circuit.""" q = cirq.LineQubit.range(12) circuit = cirq.Circuit.from_ops( *[ [cirq.X(q[0])**0.5, cirq.H(q[0])**0.5, cirq.X(q[0])**-0.5], [cirq.X(q[1])**0.5, cirq.H(q[1])**0.5, cirq.X(q[1])**-0.5], [cirq.X(q[2])**0.5, cirq.H(q[2])**0.5, cirq.X(q[2])**-0.5], cirq.Y(q[3])**0.5, [cirq.X(q[4])**0.5, cirq.H(q[4])**0.5, cirq.X(q[4])**-0.5], cirq.Y(q[5])**0.5, cirq.X(q[6])**0.5, cirq.X(q[7])**0.5, cirq.X(q[8])**0.5, cirq.X(q[9])**0.5, cirq.Y(q[10])**0.5, [cirq.X(q[11])**0.5, cirq.H(q[11])**0.5, cirq.X(q[11])**-0.5], cirq.Rz(rads=0.2767373377033284*np.pi).on(q[1]), cirq.Rz(rads=-0.18492941569567625*np.pi).on(q[2]), cirq.Rz(rads=-1.00125113388313*np.pi).on(q[5]), cirq.Rz(rads=1.1224546746752684*np.pi).on(q[6]), cirq.Rz(rads=-0.33113463396189063*np.pi).on(q[9]), cirq.Rz(rads=0.40440704518468423*np.pi).on(q[10]), [ cirq.ISWAP(q[1], q[2])**-1.009868884178167, cirq.CZ(q[1], q[2])**-0.16552586798219657, ], [ cirq.ISWAP(q[5], q[6])**-0.9733750299685556, cirq.CZ(q[5], q[6])**-0.16091330726740966, ], [ cirq.ISWAP(q[9], q[10])**-0.9769678680475263, cirq.CZ(q[9], q[10])**-0.16332605888196952, ], cirq.Rz(rads=-0.6722145774944012*np.pi).on(q[1]), cirq.Rz(rads=0.7640224995020534*np.pi).on(q[2]), cirq.Rz(rads=0.7990757781248072*np.pi).on(q[5]), cirq.Rz(rads=-0.6778722373326689*np.pi).on(q[6]), cirq.Rz(rads=0.049341949396894985*np.pi).on(q[9]), cirq.Rz(rads=0.02393046182589869*np.pi).on(q[10]), cirq.Y(q[0])**0.5, cirq.X(q[1])**0.5, cirq.Y(q[2])**0.5, [cirq.X(q[3])**0.5, cirq.H(q[3])**0.5, cirq.X(q[3])**-0.5], cirq.Y(q[4])**0.5, [cirq.X(q[5])**0.5, cirq.H(q[5])**0.5, cirq.X(q[5])**-0.5], cirq.Y(q[6])**0.5, cirq.Y(q[7])**0.5, cirq.Y(q[8])**0.5, [cirq.X(q[9])**0.5, cirq.H(q[9])**0.5, cirq.X(q[9])**-0.5], [cirq.X(q[10])**0.5, cirq.H(q[10])**0.5, cirq.X(q[10])**-0.5], cirq.Y(q[11])**0.5, cirq.Rz(rads=2.5333591271878086*np.pi).on(q[0]), cirq.Rz(rads=-2.4748096263683066*np.pi).on(q[1]), cirq.Rz(rads=-4.480708067260001*np.pi).on(q[2]), cirq.Rz(rads=4.525888267898699*np.pi).on(q[3]), cirq.Rz(rads=2.135954522972214*np.pi).on(q[4]), cirq.Rz(rads=-2.1822665205802965*np.pi).on(q[5]), cirq.Rz(rads=-3.7780476633662574*np.pi).on(q[6]), cirq.Rz(rads=3.817335880513747*np.pi).on(q[7]), cirq.Rz(rads=0.7811374803446167*np.pi).on(q[8]), cirq.Rz(rads=-0.6780279413275597*np.pi).on(q[9]), cirq.Rz(rads=1.863573798571082*np.pi).on(q[10]), cirq.Rz(rads=-2.150412392135508*np.pi).on(q[11]), [ cirq.ISWAP(q[0], q[1])**-0.8242343706275942, cirq.CZ(q[0], q[1])**-0.15468164635790926, ], [ cirq.ISWAP(q[2], q[3])**-0.981653050634976, cirq.CZ(q[2], q[3])**-0.1933349989832593, ], [ cirq.ISWAP(q[4], q[5])**-0.9637565510028211, cirq.CZ(q[4], q[5])**-0.15186761578643612, ], [ cirq.ISWAP(q[6], q[7])**-1.0089894642925605, cirq.CZ(q[6], q[7])**-0.17298943435986638, ], [ cirq.ISWAP(q[8], q[9])**-0.980271915828302, cirq.CZ(q[8], q[9])**-0.16470994863165317, ], [ cirq.ISWAP(q[10], q[11])**-0.9290392306402181, cirq.CZ(q[10], q[11])**-0.1664963204791881, ], cirq.Rz(rads=-2.346072351850546*np.pi).on(q[0]), cirq.Rz(rads=2.404621852670048*np.pi).on(q[1]), cirq.Rz(rads=5.048199817882042*np.pi).on(q[2]), cirq.Rz(rads=-5.0030196172433445*np.pi).on(q[3]), cirq.Rz(rads=-2.6543362735839113*np.pi).on(q[4]), cirq.Rz(rads=2.6080242759758283*np.pi).on(q[5]), cirq.Rz(rads=3.9045088495271663*np.pi).on(q[6]), cirq.Rz(rads=-3.8652206323796765*np.pi).on(q[7]), cirq.Rz(rads=-1.5516585295358842*np.pi).on(q[8]), cirq.Rz(rads=1.6547680685529413*np.pi).on(q[9]), cirq.Rz(rads=-1.8933072151541963*np.pi).on(q[10]), cirq.Rz(rads=1.6064686215897703*np.pi).on(q[11]), cirq.X(q[0])**0.5, cirq.Y(q[1])**0.5, cirq.X(q[2])**0.5, cirq.Y(q[3])**0.5, cirq.X(q[4])**0.5, cirq.X(q[5])**0.5, cirq.X(q[6])**0.5, [cirq.X(q[7])**0.5, cirq.H(q[7])**0.5, cirq.X(q[7])**-0.5], cirq.X(q[8])**0.5, cirq.X(q[9])**0.5, cirq.X(q[10])**0.5, cirq.X(q[11])**0.5, cirq.Rz(rads=-3.2786928385561493*np.pi).on(q[4]), cirq.Rz(rads=3.339006443218924*np.pi).on(q[8]), cirq.Rz(rads=-5.390755870544794*np.pi).on(q[5]), cirq.Rz(rads=5.4172568990486605*np.pi).on(q[9]), cirq.Rz(rads=-5.620144773112766*np.pi).on(q[6]), cirq.Rz(rads=5.630469153514815*np.pi).on(q[10]), cirq.Rz(rads=4.367652291347506*np.pi).on(q[7]), cirq.Rz(rads=-3.9105776028384707*np.pi).on(q[11]), [ cirq.ISWAP(q[4], q[8])**-1.0121115249769066, cirq.CZ(q[4], q[8])**-0.16059979031178617, ], [ cirq.ISWAP(q[5], q[9])**-0.985003985982119, cirq.CZ(q[5], q[9])**-0.16606010863938203, ], [ cirq.ISWAP(q[6], q[10])**-0.9628319095031052, cirq.CZ(q[6], q[10])**-0.16339300450568622, ], [ cirq.ISWAP(q[7], q[11])**-0.9999941453695372, cirq.CZ(q[7], q[11])**-0.16477879415124544, ], cirq.Rz(rads=2.9425087256630427*np.pi).on(q[4]), cirq.Rz(rads=-2.882195121000268*np.pi).on(q[8]), cirq.Rz(rads=4.466531408750767*np.pi).on(q[5]), cirq.Rz(rads=-4.440030380246901*np.pi).on(q[9]), cirq.Rz(rads=4.486471496440378*np.pi).on(q[6]), cirq.Rz(rads=-4.476147116038329*np.pi).on(q[10]), cirq.Rz(rads=-4.89701654221443*np.pi).on(q[7]), cirq.Rz(rads=5.354091230723465*np.pi).on(q[11]), [cirq.X(q[0])**0.5, cirq.H(q[0])**0.5, cirq.X(q[0])**-0.5], [cirq.X(q[1])**0.5, cirq.H(q[1])**0.5, cirq.X(q[1])**-0.5], [cirq.X(q[2])**0.5, cirq.H(q[2])**0.5, cirq.X(q[2])**-0.5], [cirq.X(q[3])**0.5, cirq.H(q[3])**0.5, cirq.X(q[3])**-0.5], [cirq.X(q[4])**0.5, cirq.H(q[4])**0.5, cirq.X(q[4])**-0.5], [cirq.X(q[5])**0.5, cirq.H(q[5])**0.5, cirq.X(q[5])**-0.5], cirq.Y(q[6])**0.5, cirq.Y(q[7])**0.5, [cirq.X(q[8])**0.5, cirq.H(q[8])**0.5, cirq.X(q[8])**-0.5], [cirq.X(q[9])**0.5, cirq.H(q[9])**0.5, cirq.X(q[9])**-0.5], cirq.Y(q[10])**0.5, [cirq.X(q[11])**0.5, cirq.H(q[11])**0.5, cirq.X(q[11])**-0.5], cirq.Rz(rads=12.703597923836748*np.pi).on(q[0]), cirq.Rz(rads=-12.7869629079138*np.pi).on(q[4]), cirq.Rz(rads=12.184253063938954*np.pi).on(q[1]), cirq.Rz(rads=-12.108584830758572*np.pi).on(q[5]), cirq.Rz(rads=3.782562501914174*np.pi).on(q[2]), cirq.Rz(rads=-3.873596611893716*np.pi).on(q[6]), cirq.Rz(rads=4.772639843256901*np.pi).on(q[3]), cirq.Rz(rads=-4.771314675186062*np.pi).on(q[7]), [ cirq.ISWAP(q[0], q[4])**-0.933831313649303, cirq.CZ(q[0], q[4])**-0.1583933739924931, ], [ cirq.ISWAP(q[1], q[5])**-0.9390847780661252, cirq.CZ(q[1], q[5])**-0.17144555428591543, ], [ cirq.ISWAP(q[2], q[6])**-1.0209160715892363, cirq.CZ(q[2], q[6])**-0.14849009270439747, ], [ cirq.ISWAP(q[3], q[7])**-1.0287988330229174, cirq.CZ(q[3], q[7])**-0.1385888562342036, ], cirq.Rz(rads=-12.477250219528523*np.pi).on(q[0]), cirq.Rz(rads=12.39388523545147*np.pi).on(q[4]), cirq.Rz(rads=-11.31088974563283*np.pi).on(q[1]), cirq.Rz(rads=11.386557978813212*np.pi).on(q[5]), cirq.Rz(rads=-5.4898636407973544*np.pi).on(q[2]), cirq.Rz(rads=5.398829530817813*np.pi).on(q[6]), cirq.Rz(rads=-5.863871460773714*np.pi).on(q[3]), cirq.Rz(rads=5.8651966288445525*np.pi).on(q[7]), cirq.X(q[0])**0.5, cirq.X(q[1])**0.5, cirq.Y(q[2])**0.5, cirq.X(q[3])**0.5, cirq.X(q[4])**0.5, cirq.X(q[5])**0.5, [cirq.X(q[6])**0.5, cirq.H(q[6])**0.5, cirq.X(q[6])**-0.5], [cirq.X(q[7])**0.5, cirq.H(q[7])**0.5, cirq.X(q[7])**-0.5], cirq.Y(q[8])**0.5, cirq.X(q[9])**0.5, cirq.X(q[10])**0.5, cirq.Y(q[11])**0.5, cirq.Rz(rads=5.16073733770325*np.pi).on(q[1]), cirq.Rz(rads=-5.068929415695599*np.pi).on(q[2]), cirq.Rz(rads=-4.701251133883051*np.pi).on(q[5]), cirq.Rz(rads=4.82245467467519*np.pi).on(q[6]), cirq.Rz(rads=-3.587134633961795*np.pi).on(q[9]), cirq.Rz(rads=3.6604070451845887*np.pi).on(q[10]), [ cirq.ISWAP(q[1], q[2])**-1.009868884178167, cirq.CZ(q[1], q[2])**-0.16552586798219657, ], [ cirq.ISWAP(q[5], q[6])**-0.9733750299685556, cirq.CZ(q[5], q[6])**-0.16091330726740966, ], [ cirq.ISWAP(q[9], q[10])**-0.9769678680475263, cirq.CZ(q[9], q[10])**-0.16332605888196952, ], cirq.Rz(rads=-5.556214577494324*np.pi).on(q[1]), cirq.Rz(rads=5.648022499501975*np.pi).on(q[2]), cirq.Rz(rads=4.499075778124728*np.pi).on(q[5]), cirq.Rz(rads=-4.37787223733259*np.pi).on(q[6]), cirq.Rz(rads=3.305341949396799*np.pi).on(q[9]), cirq.Rz(rads=-3.232069538174005*np.pi).on(q[10]), [cirq.X(q[0])**0.5, cirq.H(q[0])**0.5, cirq.X(q[0])**-0.5], [cirq.X(q[1])**0.5, cirq.H(q[1])**0.5, cirq.X(q[1])**-0.5], cirq.X(q[2])**0.5, cirq.Y(q[3])**0.5, cirq.Y(q[4])**0.5, cirq.Y(q[5])**0.5, cirq.Y(q[6])**0.5, cirq.X(q[7])**0.5, [cirq.X(q[8])**0.5, cirq.H(q[8])**0.5, cirq.X(q[8])**-0.5], cirq.Y(q[9])**0.5, cirq.Y(q[10])**0.5, [cirq.X(q[11])**0.5, cirq.H(q[11])**0.5, cirq.X(q[11])**-0.5], cirq.Rz(rads=7.565359127187911*np.pi).on(q[0]), cirq.Rz(rads=-7.506809626368408*np.pi).on(q[1]), cirq.Rz(rads=-15.28470806725993*np.pi).on(q[2]), cirq.Rz(rads=15.329888267898626*np.pi).on(q[3]), cirq.Rz(rads=7.019954522972137*np.pi).on(q[4]), cirq.Rz(rads=-7.066266520580219*np.pi).on(q[5]), cirq.Rz(rads=-13.842047663366333*np.pi).on(q[6]), cirq.Rz(rads=13.881335880513822*np.pi).on(q[7]), cirq.Rz(rads=3.001137480344569*np.pi).on(q[8]), cirq.Rz(rads=-2.8980279413275123*np.pi).on(q[9]), cirq.Rz(rads=5.563573798571002*np.pi).on(q[10]), cirq.Rz(rads=-5.8504123921354285*np.pi).on(q[11]), [ cirq.ISWAP(q[0], q[1])**-0.8242343706275942, cirq.CZ(q[0], q[1])**-0.15468164635790926, ], [ cirq.ISWAP(q[2], q[3])**-0.981653050634976, cirq.CZ(q[2], q[3])**-0.1933349989832593, ], [ cirq.ISWAP(q[4], q[5])**-0.9637565510028211, cirq.CZ(q[4], q[5])**-0.15186761578643612, ], [ cirq.ISWAP(q[6], q[7])**-1.0089894642925605, cirq.CZ(q[6], q[7])**-0.17298943435986638, ], [ cirq.ISWAP(q[8], q[9])**-0.980271915828302, cirq.CZ(q[8], q[9])**-0.16470994863165317, ], [ cirq.ISWAP(q[10], q[11])**-0.9290392306402181, cirq.CZ(q[10], q[11])**-0.1664963204791881, ], cirq.Rz(rads=-7.378072351850649*np.pi).on(q[0]), cirq.Rz(rads=7.436621852670151*np.pi).on(q[1]), cirq.Rz(rads=15.852199817881967*np.pi).on(q[2]), cirq.Rz(rads=-15.80701961724327*np.pi).on(q[3]), cirq.Rz(rads=-7.538336273583833*np.pi).on(q[4]), cirq.Rz(rads=7.492024275975751*np.pi).on(q[5]), cirq.Rz(rads=13.968508849527241*np.pi).on(q[6]), cirq.Rz(rads=-13.929220632379753*np.pi).on(q[7]), cirq.Rz(rads=-3.771658529535837*np.pi).on(q[8]), cirq.Rz(rads=3.874768068552894*np.pi).on(q[9]), cirq.Rz(rads=-5.593307215154117*np.pi).on(q[10]), cirq.Rz(rads=5.30646862158969*np.pi).on(q[11]), cirq.X(q[0])**0.5, cirq.X(q[1])**0.5, [cirq.X(q[2])**0.5, cirq.H(q[2])**0.5, cirq.X(q[2])**-0.5], cirq.X(q[3])**0.5, cirq.X(q[4])**0.5, [cirq.X(q[5])**0.5, cirq.H(q[5])**0.5, cirq.X(q[5])**-0.5], cirq.X(q[6])**0.5, cirq.Y(q[7])**0.5, cirq.X(q[8])**0.5, cirq.X(q[9])**0.5, [cirq.X(q[10])**0.5, cirq.H(q[10])**0.5, cirq.X(q[10])**-0.5], cirq.X(q[11])**0.5, cirq.Rz(rads=-8.162692838556204*np.pi).on(q[4]), cirq.Rz(rads=8.223006443218978*np.pi).on(q[8]), cirq.Rz(rads=-12.938755870544817*np.pi).on(q[5]), cirq.Rz(rads=12.965256899048683*np.pi).on(q[9]), cirq.Rz(rads=-12.724144773112773*np.pi).on(q[6]), cirq.Rz(rads=12.73446915351482*np.pi).on(q[10]), cirq.Rz(rads=11.027652291347495*np.pi).on(q[7]), cirq.Rz(rads=-10.570577602838458*np.pi).on(q[11]), [ cirq.ISWAP(q[4], q[8])**-1.0121115249769066, cirq.CZ(q[4], q[8])**-0.16059979031178617, ], [ cirq.ISWAP(q[5], q[9])**-0.985003985982119, cirq.CZ(q[5], q[9])**-0.16606010863938203, ], [ cirq.ISWAP(q[6], q[10])**-0.9628319095031052, cirq.CZ(q[6], q[10])**-0.16339300450568622, ], [ cirq.ISWAP(q[7], q[11])**-0.9999941453695372, cirq.CZ(q[7], q[11])**-0.16477879415124544, ], cirq.Rz(rads=7.826508725663096*np.pi).on(q[4]), cirq.Rz(rads=-7.7661951210003215*np.pi).on(q[8]), cirq.Rz(rads=12.014531408750791*np.pi).on(q[5]), cirq.Rz(rads=-11.988030380246926*np.pi).on(q[9]), cirq.Rz(rads=11.590471496440383*np.pi).on(q[6]), cirq.Rz(rads=-11.580147116038336*np.pi).on(q[10]), cirq.Rz(rads=-11.55701654221442*np.pi).on(q[7]), cirq.Rz(rads=12.014091230723457*np.pi).on(q[11]), [cirq.X(q[0])**0.5, cirq.H(q[0])**0.5, cirq.X(q[0])**-0.5], [cirq.X(q[1])**0.5, cirq.H(q[1])**0.5, cirq.X(q[1])**-0.5], cirq.Y(q[2])**0.5, [cirq.X(q[3])**0.5, cirq.H(q[3])**0.5, cirq.X(q[3])**-0.5], [cirq.X(q[4])**0.5, cirq.H(q[4])**0.5, cirq.X(q[4])**-0.5], cirq.X(q[5])**0.5, cirq.Y(q[6])**0.5, cirq.X(q[7])**0.5, cirq.Y(q[8])**0.5, [cirq.X(q[9])**0.5, cirq.H(q[9])**0.5, cirq.X(q[9])**-0.5], cirq.X(q[10])**0.5, [cirq.X(q[11])**0.5, cirq.H(q[11])**0.5, cirq.X(q[11])**-0.5], cirq.Rz(rads=26.023597923836856*np.pi).on(q[0]), cirq.Rz(rads=-26.106962907913907*np.pi).on(q[4]), cirq.Rz(rads=25.356253063938887*np.pi).on(q[1]), cirq.Rz(rads=-25.2805848307585*np.pi).on(q[5]), cirq.Rz(rads=8.370562501914259*np.pi).on(q[2]), cirq.Rz(rads=-8.461596611893802*np.pi).on(q[6]), cirq.Rz(rads=10.100639843256841*np.pi).on(q[3]), cirq.Rz(rads=-10.099314675186001*np.pi).on(q[7]), [ cirq.ISWAP(q[0], q[4])**-0.933831313649303, cirq.CZ(q[0], q[4])**-0.1583933739924931, ], [ cirq.ISWAP(q[1], q[5])**-0.9390847780661252, cirq.CZ(q[1], q[5])**-0.17144555428591543, ], [ cirq.ISWAP(q[2], q[6])**-1.0209160715892363, cirq.CZ(q[2], q[6])**-0.14849009270439747, ], [ cirq.ISWAP(q[3], q[7])**-1.0287988330229174, cirq.CZ(q[3], q[7])**-0.1385888562342036, ], cirq.Rz(rads=-25.79725021952863*np.pi).on(q[0]), cirq.Rz(rads=25.713885235451578*np.pi).on(q[4]), cirq.Rz(rads=-24.48288974563276*np.pi).on(q[1]), cirq.Rz(rads=24.55855797881315*np.pi).on(q[5]), cirq.Rz(rads=-10.07786364079744*np.pi).on(q[2]), cirq.Rz(rads=9.986829530817898*np.pi).on(q[6]), cirq.Rz(rads=-11.191871460773655*np.pi).on(q[3]), cirq.Rz(rads=11.193196628844492*np.pi).on(q[7]), cirq.X(q[0])**0.5, cirq.X(q[1])**0.5, cirq.X(q[2])**0.5, cirq.Y(q[3])**0.5, cirq.Y(q[4])**0.5, [cirq.X(q[5])**0.5, cirq.H(q[5])**0.5, cirq.X(q[5])**-0.5], [cirq.X(q[6])**0.5, cirq.H(q[6])**0.5, cirq.X(q[6])**-0.5], [cirq.X(q[7])**0.5, cirq.H(q[7])**0.5, cirq.X(q[7])**-0.5], [cirq.X(q[8])**0.5, cirq.H(q[8])**0.5, cirq.X(q[8])**-0.5], cirq.X(q[9])**0.5, [cirq.X(q[10])**0.5, cirq.H(q[10])**0.5, cirq.X(q[10])**-0.5], cirq.Y(q[11])**0.5, cirq.Rz(rads=10.044737337703173*np.pi).on(q[1]), cirq.Rz(rads=-9.952929415695523*np.pi).on(q[2]), cirq.Rz(rads=-8.401251133882973*np.pi).on(q[5]), cirq.Rz(rads=8.52245467467511*np.pi).on(q[6]), cirq.Rz(rads=-6.843134633961698*np.pi).on(q[9]), cirq.Rz(rads=6.916407045184491*np.pi).on(q[10]), [ cirq.ISWAP(q[1], q[2])**-1.009868884178167, cirq.CZ(q[1], q[2])**-0.16552586798219657, ], [ cirq.ISWAP(q[5], q[6])**-0.9733750299685556, cirq.CZ(q[5], q[6])**-0.16091330726740966, ], [ cirq.ISWAP(q[9], q[10])**-0.9769678680475263, cirq.CZ(q[9], q[10])**-0.16332605888196952, ], cirq.Rz(rads=-10.440214577494247*np.pi).on(q[1]), cirq.Rz(rads=10.5320224995019*np.pi).on(q[2]), cirq.Rz(rads=8.199075778124648*np.pi).on(q[5]), cirq.Rz(rads=-8.07787223733251*np.pi).on(q[6]), cirq.Rz(rads=6.561341949396702*np.pi).on(q[9]), cirq.Rz(rads=-6.48806953817391*np.pi).on(q[10]), cirq.Y(q[0])**0.5, cirq.Y(q[1])**0.5, cirq.Y(q[2])**0.5, cirq.X(q[3])**0.5, cirq.X(q[4])**0.5, cirq.Y(q[5])**0.5, cirq.Y(q[6])**0.5, cirq.X(q[7])**0.5, cirq.X(q[8])**0.5, [cirq.X(q[9])**0.5, cirq.H(q[9])**0.5, cirq.X(q[9])**-0.5], cirq.Y(q[10])**0.5, [cirq.X(q[11])**0.5, cirq.H(q[11])**0.5, cirq.X(q[11])**-0.5], cirq.Rz(rads=12.597359127188014*np.pi).on(q[0]), cirq.Rz(rads=-12.538809626368511*np.pi).on(q[1]), cirq.Rz(rads=-26.08870806725985*np.pi).on(q[2]), cirq.Rz(rads=26.13388826789855*np.pi).on(q[3]), cirq.Rz(rads=11.90395452297206*np.pi).on(q[4]), cirq.Rz(rads=-11.950266520580142*np.pi).on(q[5]), cirq.Rz(rads=-23.906047663366408*np.pi).on(q[6]), cirq.Rz(rads=23.945335880513902*np.pi).on(q[7]), cirq.Rz(rads=5.221137480344522*np.pi).on(q[8]), cirq.Rz(rads=-5.118027941327464*np.pi).on(q[9]), cirq.Rz(rads=9.263573798570924*np.pi).on(q[10]), cirq.Rz(rads=-9.55041239213535*np.pi).on(q[11]), [ cirq.ISWAP(q[0], q[1])**-0.8242343706275942, cirq.CZ(q[0], q[1])**-0.15468164635790926, ], [ cirq.ISWAP(q[2], q[3])**-0.981653050634976, cirq.CZ(q[2], q[3])**-0.1933349989832593, ], [ cirq.ISWAP(q[4], q[5])**-0.9637565510028211, cirq.CZ(q[4], q[5])**-0.15186761578643612, ], [ cirq.ISWAP(q[6], q[7])**-1.0089894642925605, cirq.CZ(q[6], q[7])**-0.17298943435986638, ], [ cirq.ISWAP(q[8], q[9])**-0.980271915828302, cirq.CZ(q[8], q[9])**-0.16470994863165317, ], [ cirq.ISWAP(q[10], q[11])**-0.9290392306402181, cirq.CZ(q[10], q[11])**-0.1664963204791881, ], cirq.Rz(rads=-12.410072351850753*np.pi).on(q[0]), cirq.Rz(rads=12.468621852670255*np.pi).on(q[1]), cirq.Rz(rads=26.656199817881895*np.pi).on(q[2]), cirq.Rz(rads=-26.611019617243198*np.pi).on(q[3]), cirq.Rz(rads=-12.422336273583753*np.pi).on(q[4]), cirq.Rz(rads=12.376024275975672*np.pi).on(q[5]), cirq.Rz(rads=24.032508849527318*np.pi).on(q[6]), cirq.Rz(rads=-23.993220632379824*np.pi).on(q[7]), cirq.Rz(rads=-5.991658529535789*np.pi).on(q[8]), cirq.Rz(rads=6.094768068552847*np.pi).on(q[9]), cirq.Rz(rads=-9.293307215154037*np.pi).on(q[10]), cirq.Rz(rads=9.006468621589612*np.pi).on(q[11]), [cirq.X(q[0])**0.5, cirq.H(q[0])**0.5, cirq.X(q[0])**-0.5], cirq.X(q[1])**0.5, cirq.X(q[2])**0.5, [cirq.X(q[3])**0.5, cirq.H(q[3])**0.5, cirq.X(q[3])**-0.5], [cirq.X(q[4])**0.5, cirq.H(q[4])**0.5, cirq.X(q[4])**-0.5], cirq.X(q[5])**0.5, cirq.X(q[6])**0.5, [cirq.X(q[7])**0.5, cirq.H(q[7])**0.5, cirq.X(q[7])**-0.5], cirq.Y(q[8])**0.5, cirq.Y(q[9])**0.5, cirq.X(q[10])**0.5, cirq.X(q[11])**0.5, cirq.Rz(rads=-13.046692838556257*np.pi).on(q[4]), cirq.Rz(rads=13.107006443219033*np.pi).on(q[8]), cirq.Rz(rads=-20.486755870544844*np.pi).on(q[5]), cirq.Rz(rads=20.51325689904871*np.pi).on(q[9]), cirq.Rz(rads=-19.82814477311278*np.pi).on(q[6]), cirq.Rz(rads=19.838469153514826*np.pi).on(q[10]), cirq.Rz(rads=17.687652291347487*np.pi).on(q[7]), cirq.Rz(rads=-17.230577602838448*np.pi).on(q[11]), [ cirq.ISWAP(q[4], q[8])**-1.0121115249769066, cirq.CZ(q[4], q[8])**-0.16059979031178617, ], [ cirq.ISWAP(q[5], q[9])**-0.985003985982119, cirq.CZ(q[5], q[9])**-0.16606010863938203, ], [ cirq.ISWAP(q[6], q[10])**-0.9628319095031052, cirq.CZ(q[6], q[10])**-0.16339300450568622, ], [ cirq.ISWAP(q[7], q[11])**-0.9999941453695372, cirq.CZ(q[7], q[11])**-0.16477879415124544, ], cirq.Rz(rads=12.71050872566315*np.pi).on(q[4]), cirq.Rz(rads=-12.650195121000372*np.pi).on(q[8]), cirq.Rz(rads=19.562531408750814*np.pi).on(q[5]), cirq.Rz(rads=-19.53603038024695*np.pi).on(q[9]), cirq.Rz(rads=18.69447149644039*np.pi).on(q[6]), cirq.Rz(rads=-18.684147116038343*np.pi).on(q[10]), cirq.Rz(rads=-18.21701654221441*np.pi).on(q[7]), cirq.Rz(rads=18.674091230723448*np.pi).on(q[11]), cirq.Y(q[0])**0.5, cirq.Y(q[1])**0.5, cirq.Y(q[2])**0.5, cirq.Y(q[3])**0.5, cirq.X(q[4])**0.5, cirq.Y(q[5])**0.5, [cirq.X(q[6])**0.5, cirq.H(q[6])**0.5, cirq.X(q[6])**-0.5], cirq.Y(q[7])**0.5, cirq.X(q[8])**0.5, [cirq.X(q[9])**0.5, cirq.H(q[9])**0.5, cirq.X(q[9])**-0.5], cirq.Y(q[10])**0.5, cirq.Y(q[11])**0.5, cirq.Rz(rads=39.34359792383697*np.pi).on(q[0]), cirq.Rz(rads=-39.42696290791402*np.pi).on(q[4]), cirq.Rz(rads=38.52825306393881*np.pi).on(q[1]), cirq.Rz(rads=-38.452584830758425*np.pi).on(q[5]), cirq.Rz(rads=12.958562501914345*np.pi).on(q[2]), cirq.Rz(rads=-13.049596611893888*np.pi).on(q[6]), cirq.Rz(rads=15.428639843256777*np.pi).on(q[3]), cirq.Rz(rads=-15.42731467518594*np.pi).on(q[7]), [ cirq.ISWAP(q[0], q[4])**-0.933831313649303, cirq.CZ(q[0], q[4])**-0.1583933739924931, ], [ cirq.ISWAP(q[1], q[5])**-0.9390847780661252, cirq.CZ(q[1], q[5])**-0.17144555428591543, ], [ cirq.ISWAP(q[2], q[6])**-1.0209160715892363, cirq.CZ(q[2], q[6])**-0.14849009270439747, ], [ cirq.ISWAP(q[3], q[7])**-1.0287988330229174, cirq.CZ(q[3], q[7])**-0.1385888562342036, ], cirq.Rz(rads=-39.11725021952874*np.pi).on(q[0]), cirq.Rz(rads=39.03388523545169*np.pi).on(q[4]), cirq.Rz(rads=-37.65488974563269*np.pi).on(q[1]), cirq.Rz(rads=37.730557978813074*np.pi).on(q[5]), cirq.Rz(rads=-14.665863640797525*np.pi).on(q[2]), cirq.Rz(rads=14.574829530817984*np.pi).on(q[6]), cirq.Rz(rads=-16.519871460773594*np.pi).on(q[3]), cirq.Rz(rads=16.52119662884443*np.pi).on(q[7]), cirq.X(q[0])**0.5, cirq.X(q[1])**0.5, [cirq.X(q[2])**0.5, cirq.H(q[2])**0.5, cirq.X(q[2])**-0.5], cirq.X(q[3])**0.5, [cirq.X(q[4])**0.5, cirq.H(q[4])**0.5, cirq.X(q[4])**-0.5], cirq.X(q[5])**0.5, cirq.X(q[6])**0.5, cirq.X(q[7])**0.5, cirq.Y(q[8])**0.5, cirq.Y(q[9])**0.5, [cirq.X(q[10])**0.5, cirq.H(q[10])**0.5, cirq.X(q[10])**-0.5], cirq.X(q[11])**0.5, cirq.Rz(rads=14.928737337703097*np.pi).on(q[1]), cirq.Rz(rads=-14.836929415695444*np.pi).on(q[2]), cirq.Rz(rads=-12.10125113388289*np.pi).on(q[5]), cirq.Rz(rads=12.22245467467503*np.pi).on(q[6]), cirq.Rz(rads=-10.099134633961603*np.pi).on(q[9]), cirq.Rz(rads=10.172407045184396*np.pi).on(q[10]), [ cirq.ISWAP(q[1], q[2])**-1.009868884178167, cirq.CZ(q[1], q[2])**-0.16552586798219657, ], [ cirq.ISWAP(q[5], q[6])**-0.9733750299685556, cirq.CZ(q[5], q[6])**-0.16091330726740966, ], [ cirq.ISWAP(q[9], q[10])**-0.9769678680475263, cirq.CZ(q[9], q[10])**-0.16332605888196952, ], cirq.Rz(rads=-15.32421457749417*np.pi).on(q[1]), cirq.Rz(rads=15.416022499501823*np.pi).on(q[2]), cirq.Rz(rads=11.899075778124569*np.pi).on(q[5]), cirq.Rz(rads=-11.777872237332431*np.pi).on(q[6]), cirq.Rz(rads=9.817341949396608*np.pi).on(q[9]), cirq.Rz(rads=-9.744069538173814*np.pi).on(q[10]), cirq.Y(q[0])**0.5, cirq.Y(q[1])**0.5, cirq.Y(q[2])**0.5, [cirq.X(q[3])**0.5, cirq.H(q[3])**0.5, cirq.X(q[3])**-0.5], cirq.Y(q[4])**0.5, cirq.Y(q[5])**0.5, [cirq.X(q[6])**0.5, cirq.H(q[6])**0.5, cirq.X(q[6])**-0.5], [cirq.X(q[7])**0.5, cirq.H(q[7])**0.5, cirq.X(q[7])**-0.5], cirq.X(q[8])**0.5, [cirq.X(q[9])**0.5, cirq.H(q[9])**0.5, cirq.X(q[9])**-0.5], cirq.Y(q[10])**0.5, cirq.Y(q[11])**0.5, cirq.Rz(rads=17.629359127188117*np.pi).on(q[0]), cirq.Rz(rads=-17.570809626368614*np.pi).on(q[1]), cirq.Rz(rads=-36.89270806725978*np.pi).on(q[2]), cirq.Rz(rads=36.93788826789848*np.pi).on(q[3]), cirq.Rz(rads=16.787954522971983*np.pi).on(q[4]), cirq.Rz(rads=-16.834266520580062*np.pi).on(q[5]), cirq.Rz(rads=-33.970047663366486*np.pi).on(q[6]), cirq.Rz(rads=34.00933588051398*np.pi).on(q[7]), cirq.Rz(rads=7.441137480344476*np.pi).on(q[8]), cirq.Rz(rads=-7.338027941327417*np.pi).on(q[9]), cirq.Rz(rads=12.963573798570843*np.pi).on(q[10]), cirq.Rz(rads=-13.250412392135269*np.pi).on(q[11]), [ cirq.ISWAP(q[0], q[1])**-0.8242343706275942, cirq.CZ(q[0], q[1])**-0.15468164635790926, ], [ cirq.ISWAP(q[2], q[3])**-0.981653050634976, cirq.CZ(q[2], q[3])**-0.1933349989832593, ], [ cirq.ISWAP(q[4], q[5])**-0.9637565510028211, cirq.CZ(q[4], q[5])**-0.15186761578643612, ], [ cirq.ISWAP(q[6], q[7])**-1.0089894642925605, cirq.CZ(q[6], q[7])**-0.17298943435986638, ], [ cirq.ISWAP(q[8], q[9])**-0.980271915828302, cirq.CZ(q[8], q[9])**-0.16470994863165317, ], [ cirq.ISWAP(q[10], q[11])**-0.9290392306402181, cirq.CZ(q[10], q[11])**-0.1664963204791881, ], cirq.Rz(rads=-17.442072351850854*np.pi).on(q[0]), cirq.Rz(rads=17.500621852670356*np.pi).on(q[1]), cirq.Rz(rads=37.46019981788182*np.pi).on(q[2]), cirq.Rz(rads=-37.415019617243125*np.pi).on(q[3]), cirq.Rz(rads=-17.306336273583675*np.pi).on(q[4]), cirq.Rz(rads=17.260024275975592*np.pi).on(q[5]), cirq.Rz(rads=34.09650884952739*np.pi).on(q[6]), cirq.Rz(rads=-34.057220632379895*np.pi).on(q[7]), cirq.Rz(rads=-8.211658529535743*np.pi).on(q[8]), cirq.Rz(rads=8.3147680685528*np.pi).on(q[9]), cirq.Rz(rads=-12.993307215153958*np.pi).on(q[10]), cirq.Rz(rads=12.706468621589535*np.pi).on(q[11]), [cirq.X(q[0])**0.5, cirq.H(q[0])**0.5, cirq.X(q[0])**-0.5], cirq.X(q[1])**0.5, cirq.X(q[2])**0.5, cirq.X(q[3])**0.5, cirq.X(q[4])**0.5, [cirq.X(q[5])**0.5, cirq.H(q[5])**0.5, cirq.X(q[5])**-0.5], cirq.X(q[6])**0.5, cirq.Y(q[7])**0.5, cirq.Y(q[8])**0.5, cirq.Y(q[9])**0.5, [cirq.X(q[10])**0.5, cirq.H(q[10])**0.5, cirq.X(q[10])**-0.5], cirq.X(q[11])**0.5, ], strategy=cirq.InsertStrategy.EARLIEST) return circuit