Skip to content

Commit 07ba30a

Browse files
Add test
1 parent eadda56 commit 07ba30a

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

cirq-core/cirq/experiments/z_phase_calibration.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ def z_phase_calibration_workflow(
9090
)
9191

9292
if options is None:
93-
options = xeb_fitting.XEBPhasedFSimCharacterizationOptions(
94-
characterize_theta=False, characterize_phi=False
95-
).with_defaults_from_gate(two_qubit_gate)
93+
options = xeb_fitting.XEBPhasedFSimCharacterizationOptions().with_defaults_from_gate(
94+
two_qubit_gate
95+
)
9696

9797
p_circuits = [
9898
xeb_fitting.parameterize_circuit(circuit, options, ops.GateFamily(two_qubit_gate))
@@ -164,9 +164,9 @@ def calibrate_z_phases(
164164
"""
165165

166166
if options is None:
167-
options = xeb_fitting.XEBPhasedFSimCharacterizationOptions(
168-
characterize_theta=False, characterize_phi=False
169-
).with_defaults_from_gate(two_qubit_gate)
167+
options = xeb_fitting.XEBPhasedFSimCharacterizationOptions().with_defaults_from_gate(
168+
two_qubit_gate
169+
)
170170

171171
result, _ = z_phase_calibration_workflow(
172172
sampler=sampler,

cirq-core/cirq/experiments/z_phase_calibration_test.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,38 @@ def test_calibrate_z_phases(angles, error):
103103

104104
# Either we reduced the error or the error is small enough.
105105
assert new_dist < original_dist or new_dist < 1e-6
106+
107+
108+
@pytest.mark.slow
109+
@pytest.mark.parametrize(['angles', 'error'], _create_tests(n=10, seed=32432432))
110+
def test_calibrate_z_phases_no_options(angles, error):
111+
112+
original_gate = cirq.PhasedFSimGate(**{k: v for k, v in zip(_ANGLES, angles)})
113+
actual_gate = cirq.PhasedFSimGate(**{k: v + e for k, v, e in zip(_ANGLES, angles, error)})
114+
115+
sampler = _TestSimulator(original_gate, actual_gate, seed=0)
116+
qubits = cirq.q(0, 0), cirq.q(0, 1)
117+
calibrated_gate = calibrate_z_phases(
118+
sampler,
119+
qubits,
120+
original_gate,
121+
options=None,
122+
n_repetitions=10,
123+
n_combinations=10,
124+
n_circuits=10,
125+
cycle_depths=range(3, 10),
126+
)[qubits]
127+
128+
initial_unitary = cirq.unitary(original_gate)
129+
final_unitary = cirq.unitary(calibrated_gate)
130+
target_unitary = cirq.unitary(actual_gate)
131+
maximally_mixed_state = np.eye(4) / 2
132+
dm_initial = initial_unitary @ maximally_mixed_state @ initial_unitary.T.conj()
133+
dm_final = final_unitary @ maximally_mixed_state @ final_unitary.T.conj()
134+
dm_target = target_unitary @ maximally_mixed_state @ target_unitary.T.conj()
135+
136+
original_dist = _trace_distance(dm_initial, dm_target)
137+
new_dist = _trace_distance(dm_final, dm_target)
138+
139+
# Either we reduced the error or the error is small enough.
140+
assert new_dist < original_dist or new_dist < 1e-6

0 commit comments

Comments
 (0)