From e3c4b6d1aa570dab1621a43cb1298c5a424bf8f2 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Thu, 16 Jan 2025 15:17:47 -0500 Subject: [PATCH 1/3] Set default logging level for tests --- test/ibm_test_case.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/ibm_test_case.py b/test/ibm_test_case.py index 3f4e92d6d..322018029 100644 --- a/test/ibm_test_case.py +++ b/test/ibm_test_case.py @@ -44,7 +44,9 @@ class IBMTestCase(TestCase): @classmethod def setUpClass(cls): super().setUpClass() - cls.log = logging.getLogger(cls.__name__) + default_logger = logging.getLogger(cls.__name__) + default_logger.setLevel(logging.INFO) + cls.log = default_logger filename = "%s.log" % os.path.splitext(inspect.getfile(cls))[0] setup_test_logging(cls.log, filename) cls._set_logging_level(logging.getLogger(QISKIT_IBM_RUNTIME_LOGGER_NAME)) From 82224f1b04920b341a42baa1890053b0e80cefca Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Tue, 21 Jan 2025 10:03:58 -0500 Subject: [PATCH 2/3] Set default test log to info --- test/ibm_test_case.py | 4 +--- test/utils.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/test/ibm_test_case.py b/test/ibm_test_case.py index 322018029..3f4e92d6d 100644 --- a/test/ibm_test_case.py +++ b/test/ibm_test_case.py @@ -44,9 +44,7 @@ class IBMTestCase(TestCase): @classmethod def setUpClass(cls): super().setUpClass() - default_logger = logging.getLogger(cls.__name__) - default_logger.setLevel(logging.INFO) - cls.log = default_logger + cls.log = logging.getLogger(cls.__name__) filename = "%s.log" % os.path.splitext(inspect.getfile(cls))[0] setup_test_logging(cls.log, filename) cls._set_logging_level(logging.getLogger(QISKIT_IBM_RUNTIME_LOGGER_NAME)) diff --git a/test/utils.py b/test/utils.py index 0abf9d7bb..1738fb28a 100644 --- a/test/utils.py +++ b/test/utils.py @@ -68,7 +68,7 @@ def setup_test_logging(logger: logging.Logger, filename: str) -> None: file_handler.setFormatter(formatter) logger.addHandler(file_handler) - logger.setLevel(os.getenv("LOG_LEVEL", "DEBUG")) + logger.setLevel(os.getenv("LOG_LEVEL", "INFO")) def most_busy_backend( From bb90b9e4c4ea46dfacb9be2ef1e3f439bdf2e41e Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Tue, 21 Jan 2025 11:33:17 -0500 Subject: [PATCH 3/3] Add measurements --- test/unit/test_sampler.py | 8 ++++++++ test/utils.py | 1 + 2 files changed, 9 insertions(+) diff --git a/test/unit/test_sampler.py b/test/unit/test_sampler.py index 1b5a2a300..8503df21d 100644 --- a/test/unit/test_sampler.py +++ b/test/unit/test_sampler.py @@ -92,6 +92,7 @@ def test_unsupported_dynamical_decoupling_with_dynamic_circuits(self): dynamic_circuit.if_else( (0, True), QuantumCircuit(3, 1), QuantumCircuit(3, 1), [0, 1, 2], [0] ) + dynamic_circuit.measure_all() in_pubs = [(dynamic_circuit,)] backend = get_mocked_backend() @@ -144,11 +145,13 @@ def test_sampler_validations(self): ) as session: inst = SamplerV2(mode=session) circ = QuantumCircuit(QuantumRegister(2), ClassicalRegister(0)) + circ.measure_all() with self.assertRaisesRegex(ValueError, "Classical register .* is of size 0"): inst.run([(circ,)]) creg = ClassicalRegister(2, "not-an-identifier") circ = QuantumCircuit(QuantumRegister(2), creg) + circ.measure_all() with self.assertRaisesRegex( ValueError, "Classical register names must be valid identifiers" ): @@ -156,6 +159,7 @@ def test_sampler_validations(self): creg = ClassicalRegister(2, "lambda") circ = QuantumCircuit(QuantumRegister(2), creg) + circ.measure_all() with self.assertRaisesRegex( ValueError, "Classical register names cannot be Python keywords" ): @@ -175,6 +179,7 @@ def test_run_dynamic_circuit_with_fractional_opted(self): dynamic_circuit.if_else( (0, True), QuantumCircuit(3, 1), QuantumCircuit(3, 1), [0, 1, 2], [0] ) + dynamic_circuit.measure_all() inst = SamplerV2(mode=backend) with self.assertRaises(IBMInputValueError): @@ -292,6 +297,7 @@ def test_rzz_fixed_angle_validation(self, angle): circ = QuantumCircuit(2) circ.rzz(angle, 0, 1) + circ.measure_all() if angle == 1: SamplerV2(backend).run(pubs=[(circ)]) @@ -308,6 +314,7 @@ def test_rzz_parametrized_angle_validation(self, angle): circ = QuantumCircuit(2) circ.rzz(param, 0, 1) + circ.measure_all() if angle == 1: SamplerV2(backend).run(pubs=[(circ, [angle])]) @@ -387,6 +394,7 @@ def test_rzz_validation_skips_param_exp(self): circ = QuantumCircuit(2) circ.rzz(2 * param, 0, 1) + circ.measure_all() # Since we currently don't validate parameter expressions, the following line should run # without an error, in spite of the angle being larger than pi/2 diff --git a/test/utils.py b/test/utils.py index 1738fb28a..eef7ce484 100644 --- a/test/utils.py +++ b/test/utils.py @@ -459,6 +459,7 @@ def transpile_pubs(in_pubs, backend, program): """Return pubs with transformed circuits and observables.""" t_pubs = [] for pub in in_pubs: + pub[0].measure_all() t_circ = transpile(pub[0], backend=backend) if program == "estimator": t_obs = remap_observables(pub[1], t_circ)