Skip to content

Commit

Permalink
Test copy, pickle. Validate cregs.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhartman committed Jan 31, 2024
1 parent 3b2c239 commit ba9a32c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/python/circuit/test_circuit_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

"""Test Qiskit's QuantumCircuit class."""
import copy
import pickle

import numpy as np
from ddt import data, ddt
Expand Down Expand Up @@ -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.
Expand All @@ -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):
Expand Down

0 comments on commit ba9a32c

Please sign in to comment.