Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix disassemble of isometry and added test_disassemble_isometry #4402

Merged
merged 4 commits into from
May 18, 2020
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
2 changes: 2 additions & 0 deletions qiskit/assembler/disassemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def _experiments_to_circuits(qobj):
params=params)
elif i.name == 'initialize':
_inst = instr_method(params, qubits)
elif i.name == 'isometry':
_inst = instr_method(*params, qubits, clbits)
else:
_inst = instr_method(*params, *qubits, *clbits)
elif name == 'bfunc':
Expand Down
22 changes: 22 additions & 0 deletions test/python/compiler/test_disassembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
import unittest

import numpy as np
from numpy.testing import assert_allclose

from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.circuit import Instruction
from qiskit.compiler.assemble import assemble
from qiskit.assembler.disassemble import disassemble
from qiskit.assembler.run_config import RunConfig
from qiskit.test import QiskitTestCase
import qiskit.quantum_info as qi


class TestAssembler(QiskitTestCase):
Expand Down Expand Up @@ -116,6 +118,26 @@ def test_assemble_initialize(self):
self.assertEqual(circuits[0], circ)
self.assertEqual({}, header)

def test_disassemble_isometry(self):
"""Test disassembling a circuit with an isometry.
"""
q = QuantumRegister(2, name='q')
circ = QuantumCircuit(q, name='circ')
circ.iso(qi.random_unitary(4).data, circ.qubits, [])
qobj = assemble(circ)
circuits, run_config_out, header = disassemble(qobj)
run_config_out = RunConfig(**run_config_out)
self.assertEqual(run_config_out.n_qubits, 2)
self.assertEqual(run_config_out.memory_slots, 0)
self.assertEqual(len(circuits), 1)
# params array
assert_allclose(circuits[0]._data[0][0].params[0], circ._data[0][0].params[0])
# all other data
self.assertEqual(circuits[0]._data[0][0].params[1:], circ._data[0][0].params[1:])
self.assertEqual(circuits[0]._data[0][1:], circ._data[0][1:])
self.assertEqual(circuits[0]._data[1:], circ._data[1:])
self.assertEqual({}, header)

def test_opaque_instruction(self):
"""Test the disassembler handles opaque instructions correctly."""
opaque_inst = Instruction(name='my_inst', num_qubits=4,
Expand Down