Skip to content

Commit

Permalink
coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
NoureldinYosri committed Sep 19, 2024
1 parent 552b7df commit 6f71abf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
14 changes: 7 additions & 7 deletions cirq-core/cirq/experiments/z_phase_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def z_phase_calibration_workflow(
)

if options is None:
options = xeb_fitting.XEBPhasedFSimCharacterizationOptions(characterize_chi=False, characterize_gamma=False, characterize_zeta=False).with_defaults_from_gate(
two_qubit_gate
)
options = xeb_fitting.XEBPhasedFSimCharacterizationOptions(
characterize_chi=False, characterize_gamma=False, characterize_zeta=False
).with_defaults_from_gate(two_qubit_gate)

p_circuits = [
xeb_fitting.parameterize_circuit(circuit, options, ops.GateFamily(two_qubit_gate))
Expand Down Expand Up @@ -164,9 +164,9 @@ def calibrate_z_phases(
"""

if options is None:
options = xeb_fitting.XEBPhasedFSimCharacterizationOptions(characterize_chi=False, characterize_gamma=False, characterize_zeta=False).with_defaults_from_gate(
two_qubit_gate
)
options = xeb_fitting.XEBPhasedFSimCharacterizationOptions(
characterize_chi=False, characterize_gamma=False, characterize_zeta=False
).with_defaults_from_gate(two_qubit_gate)

result, _ = z_phase_calibration_workflow(
sampler=sampler,
Expand All @@ -187,7 +187,7 @@ def calibrate_z_phases(
params['theta'] = params.get('theta', options.theta_default or 0)
params['phi'] = params.get('phi', options.phi_default or 0)
params['zeta'] = params.get('zeta', options.zeta_default or 0)
params['chi'] = params.get('eta', options.chi_default or 0)
params['chi'] = params.get('chi', options.chi_default or 0)
params['gamma'] = params.get('gamma', options.gamma_default or 0)
gates[pair] = ops.PhasedFSimGate(**params)
return gates
27 changes: 26 additions & 1 deletion cirq-core/cirq/experiments/z_phase_calibration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import cirq

from cirq.experiments.z_phase_calibration import calibrate_z_phases
from cirq.experiments.z_phase_calibration import calibrate_z_phases, z_phase_calibration_workflow
from cirq.experiments.xeb_fitting import XEBPhasedFSimCharacterizationOptions

_ANGLES = ['theta', 'phi', 'chi', 'zeta', 'gamma']
Expand Down Expand Up @@ -137,3 +137,28 @@ def test_calibrate_z_phases_no_options(angles, error):

# Either we reduced the error or the error is small enough.
assert new_dist < original_dist or new_dist < 1e-6


@pytest.mark.parametrize(['angles', 'error'], _create_tests(n=10, seed=32432432))
def test_calibrate_z_phases_workflow_no_options(angles, error):

original_gate = cirq.PhasedFSimGate(**{k: v for k, v in zip(_ANGLES, angles)})
actual_gate = cirq.PhasedFSimGate(**{k: v + e for k, v, e in zip(_ANGLES, angles, error)})

sampler = _TestSimulator(original_gate, actual_gate, seed=0)
qubits = cirq.q(0, 0), cirq.q(0, 1)
result, _ = z_phase_calibration_workflow(
sampler,
qubits,
original_gate,
options=None,
n_repetitions=1,
n_combinations=1,
n_circuits=1,
cycle_depths=(1, 2),
)

for params in result.final_params.values():
assert 'zeta' not in params
assert 'chi' not in params
assert 'gamma' not in params

0 comments on commit 6f71abf

Please sign in to comment.