From ba9a32c4a791cc54e98018917a78ae76b222c8ba Mon Sep 17 00:00:00 2001 From: Kevin Hartman Date: Wed, 31 Jan 2024 14:21:38 -0500 Subject: [PATCH] Test copy, pickle. Validate cregs. --- .../python/circuit/test_circuit_operations.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/python/circuit/test_circuit_operations.py b/test/python/circuit/test_circuit_operations.py index 4b50f2a0ba92..f15fbed010c5 100644 --- a/test/python/circuit/test_circuit_operations.py +++ b/test/python/circuit/test_circuit_operations.py @@ -13,6 +13,7 @@ """Test Qiskit's QuantumCircuit class.""" import copy +import pickle import numpy as np from ddt import data, ddt @@ -639,6 +640,23 @@ def test_measure_all(self): self.assertEqual(expected, circuit) + def test_measure_all_after_copy(self): + """ + Test measure_all on a circuit that has been copied. + """ + qc = QuantumCircuit(2) + qc.h(1) + + qc2 = qc.copy() + + qc.measure_all() + qc2.measure_all() + + expected_cregs = [ClassicalRegister(2, "meas")] + self.assertEqual(qc.cregs, expected_cregs) + self.assertEqual(qc2.cregs, expected_cregs) + self.assertEqual(qc, qc2) + def test_measure_all_after_deepcopy(self): """ Test measure_all on a circuit that has been deep-copied. @@ -651,6 +669,26 @@ def test_measure_all_after_deepcopy(self): qc.measure_all() qc2.measure_all() + expected_cregs = [ClassicalRegister(2, "meas")] + self.assertEqual(qc.cregs, expected_cregs) + self.assertEqual(qc2.cregs, expected_cregs) + self.assertEqual(qc, qc2) + + def test_measure_all_after_pickle(self): + """ + Test measure_all on a circuit that has been pickled. + """ + qc = QuantumCircuit(2) + qc.h(1) + + qc2 = pickle.loads(pickle.dumps(qc)) + + qc.measure_all() + qc2.measure_all() + + expected_cregs = [ClassicalRegister(2, "meas")] + self.assertEqual(qc.cregs, expected_cregs) + self.assertEqual(qc2.cregs, expected_cregs) self.assertEqual(qc, qc2) def test_measure_all_not_add_bits_equal(self):