def test_phase_calibrated_fsim_gate_as_characterized_phased_fsim_gate( 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) phased_gate = calibrated.as_characterized_phased_fsim_gate(parameters).on( a, b) assert np.allclose( cirq.unitary(phased_gate), cirq.unitary( cirq.Circuit([ [cirq.Z(a)**-phase_exponent, cirq.Z(b)**phase_exponent], characterized_gate.on(a, b), [cirq.Z(a)**phase_exponent, cirq.Z(b)**-phase_exponent], ])), )
def create_gate_with_drift( self, a: cirq.Qid, b: cirq.Qid, gate_calibration: PhaseCalibratedFSimGate ) -> cirq.PhasedFSimGate: """Generates a gate with drift for a given gate. Args: a: The first qubit. b: The second qubit. gate_calibration: Reference gate together with a phase information. Returns: A modified gate that includes the drifts induced by internal state of the simulator. """ gate = gate_calibration.engine_gate if (a, b, gate) in self._drifted_parameters: parameters = self._drifted_parameters[(a, b, gate)] elif (b, a, gate) in self._drifted_parameters: parameters = self._drifted_parameters[(b, a, gate)].parameters_for_qubits_swapped() else: parameters = self._drift_generator(a, b, gate) self._drifted_parameters[(a, b, gate)] = parameters return gate_calibration.as_characterized_phased_fsim_gate(parameters)