def test_ideal_sqrt_iswap_simulates_correctly_invalid_circuit_fails() -> None: engine_simulator = PhasedFSimEngineSimulator.create_with_ideal_sqrt_iswap() with pytest.raises(IncompatibleMomentError): a, b = cirq.LineQubit.range(2) circuit = cirq.Circuit([cirq.CZ.on(a, b)]) engine_simulator.simulate(circuit) with pytest.raises(IncompatibleMomentError): circuit = cirq.Circuit(cirq.GlobalPhaseOperation(coefficient=1.0)) engine_simulator.simulate(circuit)
def test_ideal_sqrt_iswap_simulates_correctly() -> None: a, b, c, d = cirq.LineQubit.range(4) circuit = cirq.Circuit( [ [cirq.X(a), cirq.Y(c)], [cirq.FSimGate(np.pi / 4, 0.0).on(a, b), cirq.FSimGate(np.pi / 4, 0.0).on(c, d)], [cirq.FSimGate(np.pi / 4, 0.0).on(b, c)], ] ) engine_simulator = PhasedFSimEngineSimulator.create_with_ideal_sqrt_iswap() actual = engine_simulator.final_state_vector(circuit) expected = cirq.final_state_vector(circuit) assert cirq.allclose_up_to_global_phase(actual, expected)
def test_run_characterization_with_simulator(): q_00, q_01, q_02, q_03 = [cirq.GridQubit(0, index) for index in range(4)] gate = SQRT_ISWAP_GATE request = FloquetPhasedFSimCalibrationRequest( gate=gate, pairs=((q_00, q_01), (q_02, q_03)), options=FloquetPhasedFSimCalibrationOptions( characterize_theta=True, characterize_zeta=True, characterize_chi=False, characterize_gamma=False, characterize_phi=True, ), ) simulator = PhasedFSimEngineSimulator.create_with_ideal_sqrt_iswap() actual = workflow.run_characterizations([request], simulator) assert actual == [ PhasedFSimCalibrationResult( parameters={ (q_00, q_01): PhasedFSimCharacterization(theta=np.pi / 4, zeta=0.0, chi=None, gamma=None, phi=0.0), (q_02, q_03): PhasedFSimCharacterization(theta=np.pi / 4, zeta=0.0, chi=None, gamma=None, phi=0.0), }, gate=SQRT_ISWAP_GATE, options=FloquetPhasedFSimCalibrationOptions( characterize_theta=True, characterize_zeta=True, characterize_chi=False, characterize_gamma=False, characterize_phi=True, ), ) ]