From 13022c5028c4877f45b71cf646fe08cf3dbae4a4 Mon Sep 17 00:00:00 2001 From: "REDMOND\\ivanbaso" Date: Thu, 20 Jul 2023 09:39:18 -0700 Subject: [PATCH] fixing test --- .../azure/quantum/target/microsoft/target.py | 17 +++++++++++++++-- azure-quantum/tests/unit/test_microsoft_qc.py | 14 ++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/azure-quantum/azure/quantum/target/microsoft/target.py b/azure-quantum/azure/quantum/target/microsoft/target.py index 0b393405d..417e9c98a 100644 --- a/azure-quantum/azure/quantum/target/microsoft/target.py +++ b/azure-quantum/azure/quantum/target/microsoft/target.py @@ -50,7 +50,7 @@ def _check_error_rate_or_process_and_readout(name, value): class MeasurementErrorRate(AutoValidatingParams): process: float = field(metadata={"validate": _check_error_rate}) readout: float = field(metadata={"validate": _check_error_rate}) - + @dataclass class MicrosoftEstimatorQubitParams(AutoValidatingParams): @@ -118,6 +118,19 @@ def post_validation(self, result): if self.one_qubit_gate_time is None: raise LookupError("one_qubit_gate_time must be set") + def as_dict(self, validate=True) -> Dict[str, Any]: + qubit_params = super().as_dict(validate) + if len(qubit_params) != 0: + if isinstance(self.one_qubit_measurement_error_rate, MeasurementErrorRate): + qubit_params["oneQubitMeasurementErrorRate"] = \ + self.one_qubit_measurement_error_rate.as_dict(validate) + + if isinstance(self.two_qubit_joint_measurement_error_rate, MeasurementErrorRate): + qubit_params["twoQubitJointMeasurementErrorRate"] = \ + self.two_qubit_joint_measurement_error_rate.as_dict(validate) + + return qubit_params + @dataclass class MicrosoftEstimatorQecScheme(AutoValidatingParams): @@ -203,7 +216,7 @@ def post_validation(self, result): if self.logical_qubit_specification_first_round_override is not None: self.logical_qubit_specification_first_round_override.post_validation(result) - def as_dict(self, validate): + def as_dict(self, validate=True) -> Dict[str, Any]: specification_dict = super().as_dict(validate) if len(specification_dict) != 0: if self.physical_qubit_specification is not None: diff --git a/azure-quantum/tests/unit/test_microsoft_qc.py b/azure-quantum/tests/unit/test_microsoft_qc.py index 5ee5640bc..7b8acfa0d 100644 --- a/azure-quantum/tests/unit/test_microsoft_qc.py +++ b/azure-quantum/tests/unit/test_microsoft_qc.py @@ -264,11 +264,21 @@ def test_estimator_params_validation_measurement_error_rates_valid(self): params.qubit_params.t_gate_error_rate = 0.03 params.qubit_params.t_gate_time = "10 ns" params.qubit_params.idle_error_rate = 0.02 - params.one_qubit_measurement_error_rate = 0.01 + params.qubit_params.one_qubit_measurement_error_rate = 0.01 params.qubit_params.two_qubit_joint_measurement_error_rate = \ MeasurementErrorRate(process = 0.02, readout = 0.03) - params.as_dict() + assert params.as_dict() == { + "errorBudget": 0.1, + "qubitParams": {"name": "qubit_gate_ns_e3", + "instructionSet": "gate_based", + "tGateErrorRate": 0.03, + "tGateTime": "10 ns", + "idleErrorRate": 0.02, + "oneQubitMeasurementErrorRate": 0.01, + "twoQubitJointMeasurementErrorRate": + {"process": 0.02, "readout": 0.03}} + } def test_estimator_error_budget_float(self):