def test_decompose_two_qubit_matrix_gate(): q0, q1 = cirq.LineQubit.range(2) device = ionq.IonQAPIDevice(qubits=[q0, q1]) for _ in range(10): gate = cirq.MatrixGate(cirq.testing.random_unitary(4)) circuit = cirq.Circuit(gate(q0, q1)) decomposed_circuit = cirq.Circuit(*device.decompose_operation(gate(q0, q1))) cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent( circuit, decomposed_circuit, atol=1e-8 )
def test_validate_moment_valid(): moment = cirq.Moment() q = 0 all_qubits = [] for gate in VALID_GATES: qubits = cirq.LineQubit.range(q, q + gate.num_qubits()) all_qubits.extend(qubits) moment += [gate(*qubits)] q += gate.num_qubits() device = ionq.IonQAPIDevice(len(all_qubits)) device.validate_moment(moment)
def test_validate_circuit_valid(): qubits = cirq.LineQubit.range(10) device = ionq.IonQAPIDevice(qubits) for _ in range(100): circuit = cirq.testing.random_circuit( qubits=qubits, n_moments=3, op_density=0.5, gate_domain={gate: gate.num_qubits() for gate in VALID_GATES}, ) device.validate_circuit(circuit)
def test_validate_moment_invalid(gate): qubits = cirq.LineQubit.range(gate.num_qubits()) moment = cirq.Moment([gate(*qubits)]) device = ionq.IonQAPIDevice(qubits=qubits) with pytest.raises(ValueError, match='unsupported gate'): device.validate_moment(moment)
def test_validate_operation_qubit_not_on_device(): device = ionq.IonQAPIDevice(qubits=[cirq.LineQubit(0)]) with pytest.raises(ValueError, match='not on the device'): device.validate_operation(cirq.H(cirq.LineQubit(1)))
def test_validate_operation_no_gate(): device = ionq.IonQAPIDevice(qubits=[]) with pytest.raises(ValueError, match='no gates'): device.validate_operation(cirq.GlobalPhaseOperation(1j))
def test_validate_operation_invalid(gate): qubits = cirq.LineQubit.range(gate.num_qubits()) device = ionq.IonQAPIDevice(qubits=qubits) operation = gate(*qubits) with pytest.raises(ValueError, match='unsupported gate'): device.validate_operation(operation)
def test_validate_operation_valid(gate): qubits = cirq.LineQubit.range(gate.num_qubits()) device = ionq.IonQAPIDevice(qubits=qubits) operation = gate(*qubits) device.validate_operation(operation)
def test_decompose_unsupported_gate(): q0, q1, q2 = cirq.LineQubit.range(3) device = ionq.IonQAPIDevice(qubits=[q0, q1, q2]) op = cirq.CCZ(q0, q1, q2) with pytest.raises(ValueError, match='not supported'): _ = device.decompose_operation(op)
def test_decompose_leaves_supported_alone(gate): qubits = cirq.LineQubit.range(gate.num_qubits()) device = ionq.IonQAPIDevice(qubits=qubits) operation = gate(*qubits) assert device.decompose_operation(operation) == operation