Skip to content

Commit

Permalink
Fix disassemble of isometry and added test_disassemble_isometry (#4402)
Browse files Browse the repository at this point in the history
* Treat call to isometry in disassemble as special case

* Added test_disassemble_isometry

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
enavarro51 and mergify[bot] authored May 18, 2020
1 parent 3f724fc commit ebc28cd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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

0 comments on commit ebc28cd

Please sign in to comment.