def test_from_characterizations_sqrt_iswap_simulates_correctly() -> None: parameters_ab = cirq.google.PhasedFSimCharacterization(theta=0.6, zeta=0.5, chi=0.4, gamma=0.3, phi=0.2) parameters_bc = cirq.google.PhasedFSimCharacterization(theta=0.8, zeta=-0.5, chi=-0.4, gamma=-0.3, phi=-0.2) parameters_cd = cirq.google.PhasedFSimCharacterization(theta=0.1, zeta=0.2, chi=0.3, gamma=0.4, phi=0.5) 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(c, b)], ]) expected_circuit = cirq.Circuit([ [cirq.X(a), cirq.X(c)], [ cirq.PhasedFSimGate(**parameters_ab.asdict()).on(a, b), cirq.PhasedFSimGate(**parameters_cd.asdict()).on(c, d), ], [cirq.PhasedFSimGate(**parameters_bc.asdict()).on(b, c)], ]) engine_simulator = PhasedFSimEngineSimulator.create_from_characterizations_sqrt_iswap( characterizations=[ cirq.google.PhasedFSimCalibrationResult( gate=cirq.FSimGate(np.pi / 4, 0.0), parameters={ (a, b): parameters_ab, (c, d): parameters_cd }, options=ALL_ANGLES_FLOQUET_PHASED_FSIM_CHARACTERIZATION, ), cirq.google.PhasedFSimCalibrationResult( gate=cirq.FSimGate(np.pi / 4, 0.0), parameters={ (c, b): parameters_bc.parameters_for_qubits_swapped() }, options=ALL_ANGLES_FLOQUET_PHASED_FSIM_CHARACTERIZATION, ), ]) actual = engine_simulator.final_state_vector(circuit) expected = cirq.final_state_vector(expected_circuit) assert cirq.allclose_up_to_global_phase(actual, expected)
def test_from_characterizations_sqrt_iswap_when_invalid_arguments_fails( ) -> None: parameters_ab = cirq.google.PhasedFSimCharacterization(theta=0.6, zeta=0.5, chi=0.4, gamma=0.3, phi=0.2) parameters_bc = cirq.google.PhasedFSimCharacterization(theta=0.8, zeta=-0.5, chi=-0.4, gamma=-0.3, phi=-0.2) a, b = cirq.LineQubit.range(2) with pytest.raises(ValueError): PhasedFSimEngineSimulator.create_from_characterizations_sqrt_iswap( characterizations=[ cirq.google.PhasedFSimCalibrationResult( gate=cirq.FSimGate(np.pi / 4, 0.0), parameters={(a, b): parameters_ab}, options=ALL_ANGLES_FLOQUET_PHASED_FSIM_CHARACTERIZATION, ), cirq.google.PhasedFSimCalibrationResult( gate=cirq.FSimGate(np.pi / 4, 0.0), parameters={(a, b): parameters_bc}, options=ALL_ANGLES_FLOQUET_PHASED_FSIM_CHARACTERIZATION, ), ]) with pytest.raises(ValueError): PhasedFSimEngineSimulator.create_from_characterizations_sqrt_iswap( characterizations=[ cirq.google.PhasedFSimCalibrationResult( gate=cirq.FSimGate(np.pi / 4, 0.2), parameters={(a, b): parameters_ab}, options=ALL_ANGLES_FLOQUET_PHASED_FSIM_CHARACTERIZATION, ) ])