-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix condition in BasisTranslator and change node.condition to @property #6040
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 condition in BasisTranslator and change node.condition to @property #6040
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall lgtm, just a couple quick comments and questions inline.
Also, are there places elsewhere in the code where we were doing something like
node.condition = node.op.condition
or
node.condition = foo
node.op.condition = foo
if so it might be good to update those here too.
In DAGCircuit.substitute_node_with_dag, this code happens
but I think that works fine with this change. The only other place node.condition was set was in DAGDepNode. Again think that should work fine with this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mostly LGTM now, thanks for the quick updates. I just have one small comment on the wording in the release note, once that's resolved I think this is ready.
The previously deprecated ``condition`` attribute for :class:`qiskit.dagcircuit.DAGNode` has been removed. | ||
It was deprecated in the 0.15.0 release. The :attr:`qiskit.dagcircuit.DAGNode.op.condition` attribute | ||
should be used instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would tweak this a bit, it's the condition
kwarg on the constructor for DAGNode that was previously deprecated and removed. The condition
attribute, ie DAGNode.condition
still exists and works as expected it's just changed under the covers to be property function now that returns the inner op node's condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Got it. Will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the release note, but wasn't sure if there needs to be a 'use instead' in this case. Let me know if it needs refining.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @enavarro51 . Looks good.
Summary
Fixes #6016
Details and comments
From the example in #6016, a condition could be dropped when transpiling with
optimization_level=3
. This was a dual problem. The first was inDAGCircuit.substitute_node
where thenode.condition
andnode.op.condition
were getting out of sync. The second was in theBasisTranslator
where an instance of aU2
gate was being reused, resulting in 2U2
's in the circuit either having the same condition or no condition.As part of this change,
DAGNode.condition
has been changed from an attribute to an@property
, which will guarantee thatnode.condition
always matchesnode.op.condition
for op nodes.