From a6c81e2cabfeee306ce28d9d45a2cf85ae3e9658 Mon Sep 17 00:00:00 2001 From: Christopher Wood Date: Fri, 3 Dec 2021 17:11:57 -0500 Subject: [PATCH] Change config from property to method --- .../calibration_management/basis_gate_library.py | 3 +-- qiskit_experiments/framework/base_experiment.py | 4 +--- test/base.py | 4 ++-- test/calibration/experiments/test_drag.py | 4 ++-- test/calibration/experiments/test_fine_amplitude.py | 2 +- test/calibration/experiments/test_fine_drag.py | 8 ++++---- test/calibration/experiments/test_rabi.py | 4 ++-- test/calibration/experiments/test_ramsey_xy.py | 4 ++-- test/calibration/experiments/test_rough_amplitude.py | 4 ++-- test/calibration/experiments/test_rough_frequency.py | 2 +- test/calibration/test_setup_library.py | 2 +- test/quantum_volume/test_qv.py | 2 +- test/randomized_benchmarking/test_rb.py | 4 ++-- test/test_cross_resonance_hamiltonian.py | 2 +- test/test_half_angle.py | 4 ++-- test/test_qubit_spectroscopy.py | 2 +- test/test_t1.py | 2 +- test/test_t2ramsey.py | 2 +- test/test_tomography.py | 4 ++-- 19 files changed, 30 insertions(+), 33 deletions(-) diff --git a/qiskit_experiments/calibration_management/basis_gate_library.py b/qiskit_experiments/calibration_management/basis_gate_library.py index ea8c8071ce..a5f262a047 100644 --- a/qiskit_experiments/calibration_management/basis_gate_library.py +++ b/qiskit_experiments/calibration_management/basis_gate_library.py @@ -140,7 +140,6 @@ def _build_schedules(self, basis_gates: Set[str]) -> Dict[str, ScheduleBlock]: are the corresponding schedules. """ - @property def config(self) -> Dict[str, Any]: """Return the settings used to initialize the library.""" @@ -169,7 +168,7 @@ def from_config(cls, config: Dict) -> "BasisGateLibrary": def __json_encode__(self): """Convert to format that can be JSON serialized.""" - return self.config + return self.config() @classmethod def __json_decode__(cls, value: Dict[str, Any]) -> "BasisGateLibrary": diff --git a/qiskit_experiments/framework/base_experiment.py b/qiskit_experiments/framework/base_experiment.py index af73003eaa..2d3f6735f0 100644 --- a/qiskit_experiments/framework/base_experiment.py +++ b/qiskit_experiments/framework/base_experiment.py @@ -52,7 +52,6 @@ class method of the appropriate experiment. run_options: Dict[str, Any] = dataclasses.field(default_factory=dict) version: str = __version__ - @property def experiment(self) -> "BaseExperiment": """Return the experiment constructed from this config. @@ -187,7 +186,6 @@ def copy(self) -> "BaseExperiment": ret._analysis_options = copy.copy(self._analysis_options) return ret - @property def config(self) -> ExperimentConfig: """Return the config dataclass for this experiment""" args = tuple(getattr(self, "__init_args__", OrderedDict()).values()) @@ -515,7 +513,7 @@ def _add_job_metadata(self, metadata: Dict[str, Any], jobs: BaseJob, **run_optio def __json_encode__(self): """Convert to format that can be JSON serialized""" - return self.config + return self.config() @classmethod def __json_decode__(cls, value): diff --git a/test/base.py b/test/base.py index 572906afc3..7bf3bbdc74 100644 --- a/test/base.py +++ b/test/base.py @@ -51,8 +51,8 @@ def assertRoundTripSerializable(self, obj: Any, check_func: Optional[Callable] = def experiments_equiv(exp1, exp2) -> bool: """Check if two experiments are equivalent by comparing their configs""" # pylint: disable = too-many-boolean-expressions, too-many-return-statements - config1 = exp1.config - config2 = exp2.config + config1 = exp1.config() + config2 = exp2.config() try: if config1 == config2: return True diff --git a/test/calibration/experiments/test_drag.py b/test/calibration/experiments/test_drag.py index 17c23c934e..0892e1ccb9 100644 --- a/test/calibration/experiments/test_drag.py +++ b/test/calibration/experiments/test_drag.py @@ -164,7 +164,7 @@ def test_update(self): def test_dragcal_experiment_config(self): """Test RoughDragCal config can round trip""" exp = RoughDragCal(0, self.cals, backend=self.backend) - loaded_exp = RoughDragCal.from_config(exp.config) + loaded_exp = RoughDragCal.from_config(exp.config()) self.assertNotEqual(exp, loaded_exp) self.assertTrue(self.experiments_equiv(exp, loaded_exp)) @@ -179,7 +179,7 @@ def test_drag_experiment_config(self): with pulse.build(name="xp") as sched: pulse.play(pulse.Drag(160, 0.5, 40, Parameter("β")), pulse.DriveChannel(0)) exp = RoughDrag(0, backend=self.backend, schedule=sched) - loaded_exp = RoughDrag.from_config(exp.config) + loaded_exp = RoughDrag.from_config(exp.config()) self.assertNotEqual(exp, loaded_exp) self.assertTrue(self.experiments_equiv(exp, loaded_exp)) diff --git a/test/calibration/experiments/test_fine_amplitude.py b/test/calibration/experiments/test_fine_amplitude.py index 46b41eb79f..b411cb5f85 100644 --- a/test/calibration/experiments/test_fine_amplitude.py +++ b/test/calibration/experiments/test_fine_amplitude.py @@ -269,7 +269,7 @@ def test_run_sx_cal(self): def test_experiment_config(self): """Test converting to and from config works""" exp = FineSXAmplitudeCal(0, self.cals, "sx") - loaded_exp = FineSXAmplitudeCal.from_config(exp.config) + loaded_exp = FineSXAmplitudeCal.from_config(exp.config()) self.assertNotEqual(exp, loaded_exp) self.assertTrue(self.experiments_equiv(exp, loaded_exp)) diff --git a/test/calibration/experiments/test_fine_drag.py b/test/calibration/experiments/test_fine_drag.py index 881ab4fc28..2115a2e43f 100644 --- a/test/calibration/experiments/test_fine_drag.py +++ b/test/calibration/experiments/test_fine_drag.py @@ -79,10 +79,10 @@ def test_end_to_end_no_schedule(self): def test_experiment_config(self): """Test converting to and from config works""" exp = FineDrag(0, Gate("Drag", num_qubits=1, params=[])) - config = exp.config + config = exp.config() loaded_exp = FineDrag.from_config(config) self.assertNotEqual(exp, loaded_exp) - self.assertEqual(config, loaded_exp.config) + self.assertEqual(config, loaded_exp.config()) class TestFineDragCal(QiskitExperimentsTestCase): @@ -100,10 +100,10 @@ def setUp(self): def test_experiment_config(self): """Test converting to and from config works""" exp = FineDragCal(0, self.cals, schedule_name="x") - config = exp.config + config = exp.config() loaded_exp = FineDragCal.from_config(config) self.assertNotEqual(exp, loaded_exp) - self.assertEqual(config, loaded_exp.config) + self.assertEqual(config, loaded_exp.config()) def test_update_cals(self): """Test that the calibrations are updated.""" diff --git a/test/calibration/experiments/test_rabi.py b/test/calibration/experiments/test_rabi.py index cd49762809..2249d8e113 100644 --- a/test/calibration/experiments/test_rabi.py +++ b/test/calibration/experiments/test_rabi.py @@ -96,7 +96,7 @@ def test_wrong_processor(self): def test_experiment_config(self): """Test converting to and from config works""" exp = Rabi(0, self.sched) - loaded_exp = Rabi.from_config(exp.config) + loaded_exp = Rabi.from_config(exp.config()) self.assertNotEqual(exp, loaded_exp) self.assertTrue(self.experiments_equiv(exp, loaded_exp)) @@ -165,7 +165,7 @@ def test_ef_rabi_circuit(self): def test_experiment_config(self): """Test converting to and from config works""" exp = EFRabi(0, self.sched) - loaded_exp = EFRabi.from_config(exp.config) + loaded_exp = EFRabi.from_config(exp.config()) self.assertNotEqual(exp, loaded_exp) self.assertTrue(self.experiments_equiv(exp, loaded_exp)) diff --git a/test/calibration/experiments/test_ramsey_xy.py b/test/calibration/experiments/test_ramsey_xy.py index 118a5168fe..4aa5bf0e02 100644 --- a/test/calibration/experiments/test_ramsey_xy.py +++ b/test/calibration/experiments/test_ramsey_xy.py @@ -70,7 +70,7 @@ def test_update_calibrations(self): def test_ramseyxy_experiment_config(self): """Test RamseyXY config roundtrips""" exp = RamseyXY(0) - loaded_exp = RamseyXY.from_config(exp.config) + loaded_exp = RamseyXY.from_config(exp.config()) self.assertNotEqual(exp, loaded_exp) self.assertTrue(self.experiments_equiv(exp, loaded_exp)) @@ -82,7 +82,7 @@ def test_ramseyxy_roundtrip_serializable(self): def test_cal_experiment_config(self): """Test FrequencyCal config roundtrips""" exp = FrequencyCal(0, self.cals) - loaded_exp = FrequencyCal.from_config(exp.config) + loaded_exp = FrequencyCal.from_config(exp.config()) self.assertNotEqual(exp, loaded_exp) self.assertTrue(self.experiments_equiv(exp, loaded_exp)) diff --git a/test/calibration/experiments/test_rough_amplitude.py b/test/calibration/experiments/test_rough_amplitude.py index ab986c9a8f..14fd602355 100644 --- a/test/calibration/experiments/test_rough_amplitude.py +++ b/test/calibration/experiments/test_rough_amplitude.py @@ -69,10 +69,10 @@ def test_update(self): def test_experiment_config(self): """Test converting to and from config works""" exp = RoughXSXAmplitudeCal(0, self.cals) - config = exp.config + config = exp.config() loaded_exp = RoughXSXAmplitudeCal.from_config(config) self.assertNotEqual(exp, loaded_exp) - self.assertEqual(config, loaded_exp.config) + self.assertEqual(config, loaded_exp.config()) class TestSpecializations(QiskitExperimentsTestCase): diff --git a/test/calibration/experiments/test_rough_frequency.py b/test/calibration/experiments/test_rough_frequency.py index 4a0551500b..c040be4309 100644 --- a/test/calibration/experiments/test_rough_frequency.py +++ b/test/calibration/experiments/test_rough_frequency.py @@ -72,6 +72,6 @@ def test_experiment_config(self): cals = BackendCalibrations(FakeArmonk()) frequencies = [1, 2, 3] exp = RoughFrequencyCal(0, cals, frequencies) - loaded_exp = RoughFrequencyCal.from_config(exp.config) + loaded_exp = RoughFrequencyCal.from_config(exp.config()) self.assertNotEqual(exp, loaded_exp) self.assertTrue(self.experiments_equiv(exp, loaded_exp)) diff --git a/test/calibration/test_setup_library.py b/test/calibration/test_setup_library.py index c559d9401f..1747d20b26 100644 --- a/test/calibration/test_setup_library.py +++ b/test/calibration/test_setup_library.py @@ -144,7 +144,7 @@ def test_serialization(self): link_parameters=False, ) - lib2 = FixedFrequencyTransmon.from_config(lib1.config) + lib2 = FixedFrequencyTransmon.from_config(lib1.config()) self.assertEqual(lib2.basis_gates, lib1.basis_gates) diff --git a/test/quantum_volume/test_qv.py b/test/quantum_volume/test_qv.py index 0eb7bbcf82..6e3ed839b2 100644 --- a/test/quantum_volume/test_qv.py +++ b/test/quantum_volume/test_qv.py @@ -245,7 +245,7 @@ def test_qv_success(self): def test_experiment_config(self): """Test converting to and from config works""" exp = QuantumVolume([0, 1, 2], seed=42) - loaded_exp = QuantumVolume.from_config(exp.config) + loaded_exp = QuantumVolume.from_config(exp.config()) self.assertNotEqual(exp, loaded_exp) self.assertTrue(self.experiments_equiv(exp, loaded_exp)) diff --git a/test/randomized_benchmarking/test_rb.py b/test/randomized_benchmarking/test_rb.py index 6938fb3fe7..bd9ba47c25 100644 --- a/test/randomized_benchmarking/test_rb.py +++ b/test/randomized_benchmarking/test_rb.py @@ -161,7 +161,7 @@ def test_input(self): def test_experiment_config(self): """Test converting to and from config works""" exp = StandardRB([0, 1], lengths=[10, 20, 30, 40], num_samples=10) - loaded_exp = StandardRB.from_config(exp.config) + loaded_exp = StandardRB.from_config(exp.config()) self.assertNotEqual(exp, loaded_exp) self.assertTrue(self.experiments_equiv(exp, loaded_exp)) @@ -261,7 +261,7 @@ def test_non_clifford_interleaved_element(self): def test_experiment_config(self): """Test converting to and from config works""" exp = InterleavedRB(CXGate(), [0, 1], lengths=[10, 20, 30, 40], num_samples=10) - loaded_exp = InterleavedRB.from_config(exp.config) + loaded_exp = InterleavedRB.from_config(exp.config()) self.assertNotEqual(exp, loaded_exp) self.assertTrue(self.experiments_equiv(exp, loaded_exp)) diff --git a/test/test_cross_resonance_hamiltonian.py b/test/test_cross_resonance_hamiltonian.py index fb4bf26c06..33796df702 100644 --- a/test/test_cross_resonance_hamiltonian.py +++ b/test/test_cross_resonance_hamiltonian.py @@ -337,7 +337,7 @@ def test_experiment_config(self): sigma=20, risefall=2, ) - loaded_exp = cr_hamiltonian.CrossResonanceHamiltonian.from_config(exp.config) + loaded_exp = cr_hamiltonian.CrossResonanceHamiltonian.from_config(exp.config()) self.assertNotEqual(exp, loaded_exp) self.assertTrue(self.experiments_equiv(exp, loaded_exp)) diff --git a/test/test_half_angle.py b/test/test_half_angle.py index 95b7a09081..02c80a0cad 100644 --- a/test/test_half_angle.py +++ b/test/test_half_angle.py @@ -82,7 +82,7 @@ def test_circuits(self): def test_experiment_config(self): """Test converting to and from config works""" exp = HalfAngle(1) - config = exp.config + config = exp.config() loaded_exp = HalfAngle.from_config(config) self.assertNotEqual(exp, loaded_exp) - self.assertEqual(config, loaded_exp.config) + self.assertEqual(config, loaded_exp.config()) diff --git a/test/test_qubit_spectroscopy.py b/test/test_qubit_spectroscopy.py index 092359cdbe..814a9d0db8 100644 --- a/test/test_qubit_spectroscopy.py +++ b/test/test_qubit_spectroscopy.py @@ -145,7 +145,7 @@ def test_spectroscopy12_end2end_classified(self): def test_experiment_config(self): """Test converting to and from config works""" exp = QubitSpectroscopy(1, np.linspace(100, 150, 20), unit="MHz") - loaded_exp = QubitSpectroscopy.from_config(exp.config) + loaded_exp = QubitSpectroscopy.from_config(exp.config()) self.assertNotEqual(exp, loaded_exp) self.assertTrue(self.experiments_equiv(exp, loaded_exp)) diff --git a/test/test_t1.py b/test/test_t1.py index 5499fec60b..ae79e6a87e 100644 --- a/test/test_t1.py +++ b/test/test_t1.py @@ -216,7 +216,7 @@ def test_t1_low_quality(self): def test_experiment_config(self): """Test converting to and from config works""" exp = T1(0, [1, 2, 3, 4, 5], unit="s") - loaded_exp = T1.from_config(exp.config) + loaded_exp = T1.from_config(exp.config()) self.assertNotEqual(exp, loaded_exp) self.assertTrue(self.experiments_equiv(exp, loaded_exp)) diff --git a/test/test_t2ramsey.py b/test/test_t2ramsey.py index bcabb3f60c..373eb8eb1b 100644 --- a/test/test_t2ramsey.py +++ b/test/test_t2ramsey.py @@ -202,7 +202,7 @@ def test_t2ramsey_concat_2_experiments(self): def test_experiment_config(self): """Test converting to and from config works""" exp = T2Ramsey(0, [1, 2, 3, 4, 5], unit="s") - loaded_exp = T2Ramsey.from_config(exp.config) + loaded_exp = T2Ramsey.from_config(exp.config()) self.assertNotEqual(exp, loaded_exp) self.assertTrue(self.experiments_equiv(exp, loaded_exp)) diff --git a/test/test_tomography.py b/test/test_tomography.py index e44ba72344..4f16f66b2f 100644 --- a/test/test_tomography.py +++ b/test/test_tomography.py @@ -269,7 +269,7 @@ def test_parallel_exp(self): def test_experiment_config(self): """Test converting to and from config works""" exp = StateTomography(QuantumCircuit(3), measurement_qubits=[0, 2], qubits=[5, 7, 1]) - loaded_exp = StateTomography.from_config(exp.config) + loaded_exp = StateTomography.from_config(exp.config()) self.assertNotEqual(exp, loaded_exp) self.assertTrue(self.experiments_equiv(exp, loaded_exp)) @@ -481,7 +481,7 @@ def test_parallel_exp(self): def test_experiment_config(self): """Test converting to and from config works""" exp = ProcessTomography(teleport_circuit(), measurement_qubits=[2], preparation_qubits=[0]) - loaded_exp = ProcessTomography.from_config(exp.config) + loaded_exp = ProcessTomography.from_config(exp.config()) self.assertNotEqual(exp, loaded_exp) self.assertTrue(self.experiments_equiv(exp, loaded_exp))