small improvement to DAGCircuit.replace_block_with_op()
See original GitHub issueWhat should we add?
Short version:
- Add the line
return new_nodeto the end ofDAGCircuit.replace_block_with_op().
Details:
DAGCircuit.replace_block_with_op(block, op, ...) internally creates a new_node containing op, and replaces the block of DAG nodes by this new_node.
I think replace_block_with_op() should return new_node. (Currently there is no return statement). This change would be in line with the behavior of DAGCircuit.substitute_node(), which does return its internal new_node. Otherwise, the user does not know the node_id or even the name of the new node, so finding the new node for further manipulations is difficult. (All I can think of is to look along one of the wires for the one node in the new DAG that wasn’t in the old DAG… obviously this is cumbersome.) Since the function already has new_node available internally, seems like we may as well return it.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)

Top Related StackOverflow Question
Thanks @enavarro51 , that would be great! (Sorry @jakelishman , I kept intending to come back to this but never found the time)
No worries at all - there’s no rush from our side!