Skip to content

Commit

Permalink
Fix naming of sqrt(iswap) gate constants (#4051)
Browse files Browse the repository at this point in the history
* Rename SQRT_ISWAP_PARAMETERS

* Fix serialization tests and do further renaming.
  • Loading branch information
mrwojtek committed Apr 27, 2021
1 parent 0df0cdc commit 7aeab3b
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 134 deletions.
2 changes: 1 addition & 1 deletion cirq-google/cirq_google/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
PhasedFSimEngineSimulator,
XEBPhasedFSimCalibrationOptions,
XEBPhasedFSimCalibrationRequest,
SQRT_ISWAP_PARAMETERS,
SQRT_ISWAP_INV_PARAMETERS,
THETA_ZETA_GAMMA_FLOQUET_PHASED_FSIM_CHARACTERIZATION,
make_zeta_chi_gamma_compensation_for_moments,
make_zeta_chi_gamma_compensation_for_operations,
Expand Down
2 changes: 1 addition & 1 deletion cirq-google/cirq_google/calibration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
PhasedFSimCharacterization,
XEBPhasedFSimCalibrationOptions,
XEBPhasedFSimCalibrationRequest,
SQRT_ISWAP_PARAMETERS,
SQRT_ISWAP_INV_PARAMETERS,
THETA_ZETA_GAMMA_FLOQUET_PHASED_FSIM_CHARACTERIZATION,
WITHOUT_CHI_FLOQUET_PHASED_FSIM_CHARACTERIZATION,
merge_matching_results,
Expand Down
8 changes: 4 additions & 4 deletions cirq-google/cirq_google/calibration/engine_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
PhasedFSimCalibrationRequest,
PhasedFSimCalibrationResult,
PhasedFSimCharacterization,
SQRT_ISWAP_PARAMETERS,
SQRT_ISWAP_INV_PARAMETERS,
try_convert_sqrt_iswap_to_fsim,
)

Expand Down Expand Up @@ -124,7 +124,7 @@ def sample_gate(_1: Qid, _2: Qid, gate: FSimGate) -> PhasedFSimCharacterization:
@classmethod
def create_with_random_gaussian_sqrt_iswap(
cls,
mean: PhasedFSimCharacterization = SQRT_ISWAP_PARAMETERS,
mean: PhasedFSimCharacterization = SQRT_ISWAP_INV_PARAMETERS,
*,
simulator: Optional[Simulator] = None,
sigma: PhasedFSimCharacterization = PhasedFSimCharacterization(
Expand Down Expand Up @@ -228,7 +228,7 @@ def sample_gate(a: Qid, b: Qid, gate: FSimGate) -> PhasedFSimCharacterization:
pair_parameters = PhasedFSimCharacterization(**pair_parameters)
pair_parameters = pair_parameters.parameters_for_qubits_swapped()
elif ideal_when_missing_gate:
pair_parameters = SQRT_ISWAP_PARAMETERS
pair_parameters = SQRT_ISWAP_INV_PARAMETERS
else:
raise ValueError(f'Missing parameters for pair {(a, b)}')

Expand All @@ -238,7 +238,7 @@ def sample_gate(a: Qid, b: Qid, gate: FSimGate) -> PhasedFSimCharacterization:
f'Missing parameter value for pair {(a, b)}, '
f'parameters={pair_parameters}'
)
pair_parameters = pair_parameters.merge_with(SQRT_ISWAP_PARAMETERS)
pair_parameters = pair_parameters.merge_with(SQRT_ISWAP_INV_PARAMETERS)

return pair_parameters

Expand Down
20 changes: 10 additions & 10 deletions cirq-google/cirq_google/calibration/engine_simulator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import cirq_google
from cirq_google.calibration.engine_simulator import (
PhasedFSimEngineSimulator,
SQRT_ISWAP_PARAMETERS,
SQRT_ISWAP_INV_PARAMETERS,
)
from cirq_google.calibration import (
FloquetPhasedFSimCalibrationOptions,
Expand All @@ -23,7 +23,7 @@
import cirq


class TestPhasedFSimCalibrationRequest(PhasedFSimCalibrationRequest):
class DummyPhasedFSimCalibrationRequest(PhasedFSimCalibrationRequest):
def to_calibration_layer(self) -> cirq_google.CalibrationLayer:
return NotImplemented

Expand All @@ -33,7 +33,7 @@ def parse_result(self, result: cirq_google.CalibrationResult) -> PhasedFSimCalib

def test_test_calibration_request():
a, b = cirq.LineQubit.range(2)
request = TestPhasedFSimCalibrationRequest(
request = DummyPhasedFSimCalibrationRequest(
gate=cirq.FSimGate(np.pi / 4, 0.5),
pairs=((a, b),),
options=ALL_ANGLES_FLOQUET_PHASED_FSIM_CHARACTERIZATION,
Expand Down Expand Up @@ -104,7 +104,7 @@ def test_floquet_get_calibrations_when_invalid_request_fails() -> None:
with pytest.raises(ValueError):
engine_simulator.get_calibrations(
[
TestPhasedFSimCalibrationRequest(
DummyPhasedFSimCalibrationRequest(
gate=cirq.FSimGate(np.pi / 4, 0.5),
pairs=((a, b),),
options=ALL_ANGLES_FLOQUET_PHASED_FSIM_CHARACTERIZATION,
Expand Down Expand Up @@ -164,7 +164,7 @@ def test_ideal_sqrt_iswap_simulates_correctly_invalid_circuit_fails() -> None:

def test_with_random_gaussian_sqrt_iswap_simulates_correctly() -> None:
engine_simulator = PhasedFSimEngineSimulator.create_with_random_gaussian_sqrt_iswap(
mean=SQRT_ISWAP_PARAMETERS,
mean=SQRT_ISWAP_INV_PARAMETERS,
sigma=PhasedFSimCharacterization(theta=0.02, zeta=0.05, chi=0.05, gamma=None, phi=0.02),
)

Expand Down Expand Up @@ -217,7 +217,7 @@ def test_with_random_gaussian_runs_correctly() -> None:

simulator = cirq.Simulator()
engine_simulator = PhasedFSimEngineSimulator.create_with_random_gaussian_sqrt_iswap(
SQRT_ISWAP_PARAMETERS, simulator=simulator
SQRT_ISWAP_INV_PARAMETERS, simulator=simulator
)

actual = engine_simulator.run(circuit, repetitions=20000).measurements['z']
Expand Down Expand Up @@ -319,12 +319,12 @@ def test_from_dictionary_sqrt_iswap_ideal_when_missing_simulates_correctly() ->
[cirq.X(a), cirq.X(c)],
[
cirq.PhasedFSimGate(**parameters_ab.asdict()).on(a, b),
cirq.PhasedFSimGate(**SQRT_ISWAP_PARAMETERS.asdict()).on(c, d),
cirq.PhasedFSimGate(**SQRT_ISWAP_INV_PARAMETERS.asdict()).on(c, d),
],
[
cirq.PhasedFSimGate(**parameters_bc.merge_with(SQRT_ISWAP_PARAMETERS).asdict()).on(
b, c
)
cirq.PhasedFSimGate(
**parameters_bc.merge_with(SQRT_ISWAP_INV_PARAMETERS).asdict()
).on(b, c)
],
]
)
Expand Down
2 changes: 1 addition & 1 deletion cirq-google/cirq_google/calibration/phased_fsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def override_by(self, other: 'PhasedFSimCharacterization') -> 'PhasedFSimCharact
return other.merge_with(self)


SQRT_ISWAP_PARAMETERS = PhasedFSimCharacterization(
SQRT_ISWAP_INV_PARAMETERS = PhasedFSimCharacterization(
theta=np.pi / 4, zeta=0.0, chi=0.0, gamma=0.0, phi=0.0
)

Expand Down

0 comments on commit 7aeab3b

Please sign in to comment.