-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Speed up parameter resolution by checking if val is parameterized and caching the boolean #6023
Conversation
… caching the boolean
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
@@ -35,16 +35,16 @@ def __init__(self, var): | |||
self.parameter = var | |||
|
|||
def _is_parameterized_(self) -> bool: | |||
return self.parameter == 0 | |||
return self.parameter != 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.
Just curious, why this change?
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.
Because in the existing test, the _is_paramaterized_
returns True
when the class is actually not paramaterized (i.e. self.parameter is 0
and there's nothing to resolve).
As a result cirq.is_parameterized(val)
returns False when val
is actually parameterized and therefore the output of cirq.resolve_parameters(val)
changes.
So this change fixes the test to make the behavior of _is_paramaterized_
and resolve_parameters
consistent.
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.
Addressed nits @maffoo
PTAL
@@ -35,16 +35,16 @@ def __init__(self, var): | |||
self.parameter = var | |||
|
|||
def _is_parameterized_(self) -> bool: | |||
return self.parameter == 0 | |||
return self.parameter != 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.
Because in the existing test, the _is_paramaterized_
returns True
when the class is actually not paramaterized (i.e. self.parameter is 0
and there's nothing to resolve).
As a result cirq.is_parameterized(val)
returns False when val
is actually parameterized and therefore the output of cirq.resolve_parameters(val)
changes.
So this change fixes the test to make the behavior of _is_paramaterized_
and resolve_parameters
consistent.
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.
Minor comment, then LGTM.
Co-authored-by: Matthew Neeley <[email protected]>
… caching the boolean (quantumlib#6023)
Fixes #6001
cc @maffoo @zchen088 PTAL!