Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
NoureldinYosri committed Sep 13, 2024
1 parent 6d43f1d commit 894581c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
12 changes: 6 additions & 6 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_theta=False, characterize_phi=False
).with_defaults_from_gate(two_qubit_gate)
options = xeb_fitting.XEBPhasedFSimCharacterizationOptions().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_theta=False, characterize_phi=False
).with_defaults_from_gate(two_qubit_gate)
options = xeb_fitting.XEBPhasedFSimCharacterizationOptions().with_defaults_from_gate(
two_qubit_gate
)

result, _ = z_phase_calibration_workflow(
sampler=sampler,
Expand Down
35 changes: 35 additions & 0 deletions cirq-core/cirq/experiments/z_phase_calibration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,38 @@ def test_calibrate_z_phases(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.slow
@pytest.mark.parametrize(['angles', 'error'], _create_tests(n=10, seed=32432432))
def test_calibrate_z_phases_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)
calibrated_gate = calibrate_z_phases(
sampler,
qubits,
original_gate,
options=None,
n_repetitions=10,
n_combinations=10,
n_circuits=10,
cycle_depths=range(3, 10),
)[qubits]

initial_unitary = cirq.unitary(original_gate)
final_unitary = cirq.unitary(calibrated_gate)
target_unitary = cirq.unitary(actual_gate)
maximally_mixed_state = np.eye(4) / 2
dm_initial = initial_unitary @ maximally_mixed_state @ initial_unitary.T.conj()
dm_final = final_unitary @ maximally_mixed_state @ final_unitary.T.conj()
dm_target = target_unitary @ maximally_mixed_state @ target_unitary.T.conj()

original_dist = _trace_distance(dm_initial, dm_target)
new_dist = _trace_distance(dm_final, dm_target)

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

0 comments on commit 894581c

Please sign in to comment.