-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Improve OpenQASM 3 exporter performance for hardware-like circuits #13343
Conversation
This reorganises the variable lookups and internal AST generation slightly to improve the OpenQASM 3 exporter performance for the common case of circuits with many singly parametric 1q gates, parametrised by a single `Parameter` expression. This is quite common in high-throughput cases, where the circuit is being used as a parametric template for a backend compiler.
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 11633949120Details
💛 - 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.
Looks mostly good, just a few minor comments.
Thanks for doing this :)
@@ -1145,9 +1145,11 @@ def _rebind_scoped_parameters(self, expression): | |||
# missing, pending a new system in Terra to replace it (2022-03-07). | |||
if not isinstance(expression, ParameterExpression): | |||
return expression | |||
if isinstance(expression, Parameter): | |||
return self.symbols.get_variable(expression).string |
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.
Is this a different behavior here? I've not looked too much at ParameterExpression
, but is it odd for this to return a string rather than an Expression
? Perhaps I'm missing something 🙂
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.
You're not missing anything, it's just abuse of the complete absence of handling for ParameterExpression
in the exporter - we literally just call str
and hope for the best.
The reason not to construct a ParameterExpression
is because the case of a standalone Parameter
is very common on the performance critical path, and ParameterExpression
(and Parameter
) are both very expensive to construct.
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.
Looks good.
Thanks for the comments / clarifications!
…cuits (Qiskit#13343)" This reverts commit 8b21013.
Summary
This reorganises the variable lookups and internal AST generation slightly to improve the OpenQASM 3 exporter performance for the common case of circuits with many singly parametric 1q gates, parametrised by a single
Parameter
expression. This is quite common in high-throughput cases, where the circuit is being used as a parametric template for a backend compiler.Details and comments
Similar to #13342, this was a couple of very easy tweaks I could make within Python space to slightly improve the runtime performance of the OQ3 importer. It's still pretty slow for what it does, but there's little point focussing on its performance while it's still pure Python, and the majority of our data models are moving to Rust.