Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Replace shallow copy with deepcopy in QV circuit generation #462

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions qiskit/ignis/verification/quantum_volume/circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,32 @@ def qv_circuits(qubit_lists, ntrials=1,
"a physical layout is deprecated and will be "
"removed in a future release. Instead use "
"''qiskit.transpile' with the "
"'initial_layout' parameter")
"'initial_layout' parameter",
DeprecationWarning)
depth_list = [len(qubit_list) for qubit_list in qubit_lists]

if seed:
rng = np.random.default_rng(seed)
else:
_seed = None

circuits = [[] for e in range(ntrials)]
circuits_nomeas = [[] for e in range(ntrials)]

for trial in range(ntrials):
for depthidx, depth in enumerate(depth_list):
n_q_max = np.max(qubit_lists[depthidx])
qv_circ = QuantumVolume(depth, depth, seed=seed)
if seed:
_seed = rng.integers(1000)
qv_circ = QuantumVolume(depth, depth, seed=_seed)
qc2 = copy.deepcopy(qv_circ)
# TODO: Remove this when we remove support for doing pseudo-layout
# via qubit lists
if n_q_max != depth:
qc = QuantumCircuit(int(n_q_max + 1))
qc2 = copy.copy(qv_circ)
qc.compose(qv_circ, qubit_lists[depthidx], inplace=True)
else:
qc = qv_circ
qc2 = copy.copy(qc)
qc.measure_active()
qc.name = 'qv_depth_%d_trial_%d' % (depth, trial)
qc2.name = qc.name
Expand Down
14 changes: 12 additions & 2 deletions test/quantum_volume/test_qv.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def test_qv_circuits_with_seed(self):
meas_name = qv_circs[0][0].data[0][0].name
no_meas_name = qv_circs_no_meas[0][0].data[0][0].name

self.assertEqual(int(meas_name.split(',')[-1].rstrip(']')), 3)
self.assertEqual(int(no_meas_name.split(',')[-1].rstrip(']')), 3)
self.assertEqual(int(meas_name.split(',')[-1].rstrip(']')), 811)
self.assertEqual(int(no_meas_name.split(',')[-1].rstrip(']')), 811)

def test_measurements_in_circuits(self):
"""Ensure measurements are set or not on output circuits."""
Expand All @@ -112,6 +112,16 @@ def test_measurements_in_circuits(self):
[x[0].name for x in qv_circs_no_meas[0][0].data])
self.assertEqual([0, 1, 2, 3], qv_circs_measure_qubits)

def test_measurements_in_circuits_qubit_list_gap(self):
"""Test that there are no measurement instructions in output nomeas circuits."""
qubit_lists = [[1, 3, 5, 7]]
qv_circs, qv_circs_no_meas = qv.qv_circuits(qubit_lists)
qv_circs_measure_qubits = [
x[1][0].index for x in qv_circs[0][0].data if x[0].name == 'measure']
self.assertNotIn('measure',
[x[0].name for x in qv_circs_no_meas[0][0].data])
self.assertEqual([1, 3, 5, 7], qv_circs_measure_qubits)

def test_qv_fitter(self):
""" Test the fitter"""
qubit_lists = [[0, 1, 3], [0, 1, 3, 5], [0, 1, 3, 5, 7],
Expand Down