Skip to content
32 changes: 7 additions & 25 deletions qiskit/dagcircuit/dagcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,22 +384,11 @@ def apply_operation_back(self, op, qargs=None, cargs=None, condition=None):
# Add new in-edges from predecessors of the output nodes to the
# operation node while deleting the old in-edges of the output nodes
# and adding new edges from the operation node to each output node
al = [qargs, all_cbits]
for q in itertools.chain(*al):
ie = self._multi_graph.predecessors(self.output_map[q]._node_id)

if len(ie) != 1:
raise DAGCircuitError("output node has multiple in-edges")

self._multi_graph.add_edge(
ie[0]._node_id, node_index,
{'name': "%s[%s]" % (q.register.name, q.index), 'wire': q})

self._multi_graph.remove_edge(ie[0]._node_id, self.output_map[q]._node_id)
self._multi_graph.add_edge(
node_index, self.output_map[q]._node_id,
dict(name="%s[%s]" % (q.register.name, q.index), wire=q))

al = [qargs, all_cbits]
self._multi_graph.insert_node_on_in_edges_multiple(
node_index,
[self.output_map[q]._node_id for q in itertools.chain(*al)])
return self._multi_graph[node_index]

def apply_operation_front(self, op, qargs, cargs, condition=None):
Expand Down Expand Up @@ -433,16 +422,9 @@ def apply_operation_front(self, op, qargs, cargs, condition=None):
# operation node while deleting the old out-edges of the input nodes
# and adding new edges to the operation node from each input node
al = [qargs, all_cbits]
for q in itertools.chain(*al):
ie = self._multi_graph.successors(self.input_map[q]._node_id)
if len(ie) != 1:
raise DAGCircuitError("input node has multiple out-edges")
self._multi_graph.add_edge(node_index, ie[0]._node_id,
dict(name="%s[%s]" % (q.register.name, q.index), wire=q))
self._multi_graph.remove_edge(self.input_map[q]._node_id, ie[0]._node_id)
self._multi_graph.add_edge(self.input_map[q]._node_id, node_index,
dict(name="%s[%s]" % (q.register.name, q.index), wire=q))

self._multi_graph.insert_node_on_out_edges_multiple(
node_index,
[self.input_map[q]._node_id for q in itertools.chain(*al)])
return self._multi_graph[node_index]

def _check_edgemap_registers(self, edge_map, keyregs, valregs, valreg=True):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
contextvars>=2.4;python_version<'3.7'
jsonschema>=2.6
networkx>=2.2
retworkx>=0.5.0
retworkx>=0.6.0
numpy>=1.17
ply>=3.10
psutil>=5
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"contextvars>=2.4;python_version<'3.7'",
"jsonschema>=2.6",
"networkx>=2.2",
"retworkx>=0.5.0",
"retworkx>=0.6.0",
"numpy>=1.17",
"ply>=3.10",
"psutil>=5",
Expand Down