Fixes #2858 by checking all gates in the subinstruction for registers (#2998)

* Fixes #2858 by checking the entire instruction for classical registers, not just the first gate in it.

* lint decompose.py

* Update unroll_3q_or_more.py

* lint unroller.py
This commit is contained in:
bcamorrison 2019-08-19 08:50:56 -06:00 committed by Ali Javadi-Abhari
parent de5a2a613a
commit 16dcbe259b
3 changed files with 18 additions and 5 deletions

View File

@ -49,9 +49,12 @@ class Decompose(TransformationPass):
# hacky way to build a dag on the same register as the rule is defined
# TODO: need anonymous rules to address wires by index
decomposition = DAGCircuit()
decomposition.add_qreg(rule[0][1][0].register)
if rule[0][2]:
decomposition.add_creg(rule[0][2][0].register)
qregs = {qb.register for inst in rule for qb in inst[1]}
cregs = {cb.register for inst in rule for cb in inst[2]}
for qreg in qregs:
decomposition.add_qreg(qreg)
for creg in cregs:
decomposition.add_creg(creg)
for inst in rule:
decomposition.apply_operation_back(*inst)
dag.substitute_node_with_dag(node, decomposition)

View File

@ -46,7 +46,12 @@ class Unroll3qOrMore(TransformationPass):
# hacky way to build a dag on the same register as the rule is defined
# TODO: need anonymous rules to address wires by index
decomposition = DAGCircuit()
decomposition.add_qreg(rule[0][1][0].register)
qregs = {qb.register for inst in rule for qb in inst[1]}
cregs = {cb.register for inst in rule for cb in inst[2]}
for qreg in qregs:
decomposition.add_qreg(qreg)
for creg in cregs:
decomposition.add_creg(creg)
for inst in rule:
decomposition.apply_operation_back(*inst)
decomposition = self.run(decomposition) # recursively unroll

View File

@ -75,7 +75,12 @@ class Unroller(TransformationPass):
# hacky way to build a dag on the same register as the rule is defined
# TODO: need anonymous rules to address wires by index
decomposition = DAGCircuit()
decomposition.add_qreg(rule[0][1][0].register)
qregs = {qb.register for inst in rule for qb in inst[1]}
cregs = {cb.register for inst in rule for cb in inst[2]}
for qreg in qregs:
decomposition.add_qreg(qreg)
for creg in cregs:
decomposition.add_creg(creg)
for inst in rule:
decomposition.apply_operation_back(*inst)