def test_phase_calibrated_fsim_gate_compensated(phase_exponent: float): a, b = cirq.LineQubit.range(2) ideal_gate = cirq.FSimGate(theta=np.pi / 4, phi=0.0) characterized_gate = cirq.PhasedFSimGate(theta=ideal_gate.theta, zeta=0.1, chi=0.2, gamma=0.3, phi=ideal_gate.phi) parameters = PhasedFSimCharacterization( theta=ideal_gate.theta, zeta=characterized_gate.zeta, chi=characterized_gate.chi, gamma=characterized_gate.gamma, phi=ideal_gate.phi, ) calibrated = PhaseCalibratedFSimGate(ideal_gate, phase_exponent=phase_exponent) # Passing characterized_gate as engine_gate simulates the hardware execution. operations = calibrated.with_zeta_chi_gamma_compensated( (a, b), parameters, engine_gate=characterized_gate) cirq.testing.assert_allclose_up_to_global_phase( cirq.unitary(cirq.Circuit(operations)), cirq.unitary( cirq.Circuit([ [cirq.Z(a)**-phase_exponent, cirq.Z(b)**phase_exponent], ideal_gate.on(a, b), [cirq.Z(a)**phase_exponent, cirq.Z(b)**-phase_exponent], ])), atol=1e-8, )
def from_characterization( cls, qubits: Tuple[Qid, Qid], gate_calibration: PhaseCalibratedFSimGate, parameters: PhasedFSimCharacterization, characterization_index: Optional[int], ) -> 'FSimPhaseCorrections': """Creates an operation that compensates for zeta, chi and gamma angles of the supplied gate and characterization. Args: qubits: Qubits that the gate should act on. gate_calibration: Original, imperfect gate that is supposed to run on the hardware together with phase information. parameters: The real parameters of the supplied gate. characterization_index: characterization index to use at each moment with gate. """ operations = gate_calibration.with_zeta_chi_gamma_compensated( qubits, parameters) moment_to_calibration = [None, characterization_index, None] return cls(operations, moment_to_calibration)