def test_merge_matching_results_when_incompatible_fails(): q_00, q_01, q_02, q_03 = [cirq.GridQubit(0, index) for index in range(4)] gate = cirq.FSimGate(theta=np.pi / 4, phi=0.0) options = WITHOUT_CHI_FLOQUET_PHASED_FSIM_CHARACTERIZATION parameters_1 = { (q_00, q_01): PhasedFSimCharacterization(theta=0.1, zeta=0.2, chi=None, gamma=None, phi=0.3) } parameters_2 = { (q_02, q_03): PhasedFSimCharacterization(theta=0.4, zeta=0.5, chi=None, gamma=None, phi=0.6) } with pytest.raises(ValueError): results = [ PhasedFSimCalibrationResult(parameters=parameters_1, gate=gate, options=options), PhasedFSimCalibrationResult(parameters=parameters_1, gate=gate, options=options), ] assert merge_matching_results(results) with pytest.raises(ValueError): results = [ PhasedFSimCalibrationResult(parameters=parameters_1, gate=gate, options=options), PhasedFSimCalibrationResult(parameters=parameters_2, gate=cirq.CZ, options=options), ] assert merge_matching_results(results) with pytest.raises(ValueError): results = [ PhasedFSimCalibrationResult(parameters=parameters_1, gate=gate, options=options), PhasedFSimCalibrationResult( parameters=parameters_2, gate=gate, options=ALL_ANGLES_FLOQUET_PHASED_FSIM_CHARACTERIZATION, ), ] assert merge_matching_results(results)
def make_zeta_chi_gamma_compensation_for_operations( circuit: Circuit, characterizations: List[PhasedFSimCalibrationResult], gates_translator: Callable[ [Gate], Optional[PhaseCalibratedFSimGate]] = try_convert_sqrt_iswap_to_fsim, permit_mixed_moments: bool = False, ) -> Circuit: """Compensates circuit operations against errors in zeta, chi and gamma angles. This method creates a new circuit with a single-qubit Z gates added in a such way so that zeta, chi and gamma angles discovered by characterizations are cancelled-out and set to 0. Contrary to make_zeta_chi_gamma_compensation_for_moments this method does not match characterizations to the moment structure of the circuits and thus is less accurate because some errors caused by cross-talks are not mitigated. The major advantage of this method over make_zeta_chi_gamma_compensation_for_moments is that it can work with arbitrary set of characterizations that cover all the interactions of the circuit (up to assumptions of merge_matching_results method). In particular, for grid-like devices the number of characterizations is bounded by four, where in the case of make_zeta_chi_gamma_compensation_for_moments the number of characterizations is bounded by number of moments in a circuit. This function preserves a moment structure of the circuit. All single qubit gates appear on new moments in the final circuit. Args: circuit: Circuit to calibrate. characterizations: List of characterization results (likely returned from run_calibrations). All the characterizations must be compatible in sense of merge_matching_results, they will be merged together. gates_translator: Function that translates a gate to a supported FSimGate which will undergo characterization. Defaults to sqrt_iswap_gates_translator. permit_mixed_moments: Whether to allow mixing single-qubit and two-qubit gates in a single moment. Returns: Calibrated circuit with a single-qubit Z gates added which compensates for the true gates imperfections. """ characterization = merge_matching_results(characterizations) moment_to_calibration = [0] * len(circuit) calibrated = _make_zeta_chi_gamma_compensation( CircuitWithCalibration(circuit, moment_to_calibration), [characterization] if characterization is not None else [], gates_translator, permit_mixed_moments=permit_mixed_moments, ) return calibrated.circuit
def test_merge_matching_results(): q_00, q_01, q_02, q_03 = [cirq.GridQubit(0, index) for index in range(4)] gate = cirq.FSimGate(theta=np.pi / 4, phi=0.0) options = WITHOUT_CHI_FLOQUET_PHASED_FSIM_CHARACTERIZATION parameters_1 = { (q_00, q_01): PhasedFSimCharacterization(theta=0.1, zeta=0.2, chi=None, gamma=None, phi=0.3), } parameters_2 = { (q_02, q_03): PhasedFSimCharacterization(theta=0.4, zeta=0.5, chi=None, gamma=None, phi=0.6), } results = [ PhasedFSimCalibrationResult( parameters=parameters_1, gate=gate, options=options, ), PhasedFSimCalibrationResult( parameters=parameters_2, gate=gate, options=options, ), ] assert merge_matching_results(results) == PhasedFSimCalibrationResult( parameters={ **parameters_1, **parameters_2 }, gate=gate, options=options, )
def test_merge_matching_results_when_empty_none(): assert merge_matching_results([]) is None