-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add method to compute estimated duration of scheduled circuit #13783
Conversation
This commit adds a new QuantumCircuit method to compute the estimated duration of a scheduled circuit. This is to replace the deprecated duration attribute that the transpiler was potentially setting during the scheduling stage. This method computes the longest duration path in the dag view of the circuit internally. This method should have been included in the 1.2.0 release prior to the deprecation of the `QuantumCircuit.duration` attribute in 1.3.0. But, this was an oversight in the path to deprecation, as it was part of larger deprecation of numerous scheduling pieces in the 1.3.0. We should definitely backport this for the 1.4.0 release for inclusion in that release prior to the Qiskit 2.0.0 release which removes the deprecated attribute
@Mergifyio backport stable/1.4 |
✅ Backports have been created
|
Pull Request Test Coverage Report for Build 13400631790Details
💛 - Coveralls |
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 for doing this.
This feels like we probably ought to have a migration guide or something to both explain ourselves a bit more and to include a couple more worked examples to help the transition?
available through the :attr:`duration`, :attr:`unit` and :attr:`op_start_times` attributes. | ||
available through the :meth:`estimate_duration` method and :attr:`op_start_times` attribute. |
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.
Are we leaving op_start_times
as a valid attribute of QuantumCircuit
post deprecation?
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 didn't think that we deprecated it as part of 1.3.0. There are also a bunch of associated methods with it too. We can deprecate it for 1.4.0 as falls into the same category as duration though and we should probably remove it from the circuit object. But we can look at that in a separate pr.
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 looked into doing this and don't think we should for 2.0. The timeline visualizer depends on this data and methods. I need to figure out a more complete mechanism to rewrite the drawer without this, and rushing it in the week of 1.4.0 doesn't seem ideal. We should update the docstrings in 2.0 though to make it more explicit that this is an estimate etc, like what this method does for the duration.
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 added an issue to keep track of the docstring update: #13880, it's very small but I am afraid that without it we might forget to do it
let get_duration = | ||
|edge: <&StableDiGraph<NodeType, Wire> as IntoEdgeReferences>::EdgeRef| -> PyResult<f64> { | ||
let node_weight = &dag.dag()[edge.target()]; | ||
match node_weight { |
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.
The nesting's got a bit out of control in this function - I think we reach 11 levels of indentation at the deepest point? Some of the if let
s might want to become let ... else
or anything else we can 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 dropped an indent level as part of refactoring for the rust standard instruction in: 0fe8e0d (I'll have to rewrite it for 1.4 backport though since StandardInstruction is only in 2.0).
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.
ups.. it was already that name. my bad.compute_estimated_duration
sounds like a verbose name. @nonhermitian suggested estimate_duration
and I think it is much better.
One or more of the following people are relevant to this code:
|
This should be ready for review now. I'll have to rewrite the rust implementation when it's backported to 1.4 because the rust internals on |
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.
LGTM! My only concern here is how to make sure that this new utility reaches users I think that at least we can make sure to include it in the 2.0 migration guide (added a comment in the issue).
* Add method to compute estimated duration of scheduled circuit This commit adds a new QuantumCircuit method to compute the estimated duration of a scheduled circuit. This is to replace the deprecated duration attribute that the transpiler was potentially setting during the scheduling stage. This method computes the longest duration path in the dag view of the circuit internally. This method should have been included in the 1.2.0 release prior to the deprecation of the `QuantumCircuit.duration` attribute in 1.3.0. But, this was an oversight in the path to deprecation, as it was part of larger deprecation of numerous scheduling pieces in the 1.3.0. We should definitely backport this for the 1.4.0 release for inclusion in that release prior to the Qiskit 2.0.0 release which removes the deprecated attribute * Simplify dag node indexing * Expand docs * Fix handling for StandardInstruction in rust and add first test * Expand test coverage * Fix lint (cherry picked from commit 8c50ce4)
In the recently merged Qiskit#13783 a bug slipped in an unexercised code path where we were dividing by dt instead of multiplying. This was fixed in the common code path where dt is an int, but nothing in the data model disallows float durations for dt units despite it not being real. Since the data model allowed it the rust code needed to support it and that path did the wrong operation. This commit fixes that oversight in the rust code and adds a test for it.
In the recently merged #13783 a bug slipped in an unexercised code path where we were dividing by dt instead of multiplying. This was fixed in the common code path where dt is an int, but nothing in the data model disallows float durations for dt units despite it not being real. Since the data model allowed it the rust code needed to support it and that path did the wrong operation. This commit fixes that oversight in the rust code and adds a test for it.
#13783) (#13881) * Add method to compute estimated duration of scheduled circuit (#13783) * Add method to compute estimated duration of scheduled circuit This commit adds a new QuantumCircuit method to compute the estimated duration of a scheduled circuit. This is to replace the deprecated duration attribute that the transpiler was potentially setting during the scheduling stage. This method computes the longest duration path in the dag view of the circuit internally. This method should have been included in the 1.2.0 release prior to the deprecation of the `QuantumCircuit.duration` attribute in 1.3.0. But, this was an oversight in the path to deprecation, as it was part of larger deprecation of numerous scheduling pieces in the 1.3.0. We should definitely backport this for the 1.4.0 release for inclusion in that release prior to the Qiskit 2.0.0 release which removes the deprecated attribute * Simplify dag node indexing * Expand docs * Fix handling for StandardInstruction in rust and add first test * Expand test coverage * Fix lint (cherry picked from commit 8c50ce4) * Update rust code to work with 1.4.0 rust data model * Fix bug in arithmetic for converting dt to sec * Add fix test * Fix lint --------- Co-authored-by: Matthew Treinish <[email protected]> Co-authored-by: Elena Peña Tapia <[email protected]> Co-authored-by: Elena Peña Tapia <[email protected]>
Summary
This commit adds a new QuantumCircuit method to compute the estimated duration of a scheduled circuit. This is to replace the deprecated duration attribute that the transpiler was potentially setting during the scheduling stage. This method computes the longest duration path in the dag view of the circuit internally.
This method should have been included in the 1.2.0 release prior to the deprecation of the
QuantumCircuit.duration
attribute in 1.3.0. But, this was an oversight in the path to deprecation, as it was part of larger deprecation of numerous scheduling pieces in the 1.3.0. We should definitely backport this for the 1.4.0 release for inclusion in that release prior to the Qiskit 2.0.0 release which removes the deprecated attributeDetails and comments
TODO: