-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Moment.resolve_parameter not resolving all the expressions #6778
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
Comments
@pavoljuhas can you please assign this to me .. |
@dv8081 the issue that happens is that Cirq/cirq-core/cirq/circuits/moment.py Lines 277 to 280 in fd95547
this doesn't work because
|
@NoureldinYosri Thanks for pointing this out for me. |
Fixes quantumlib#6778 Fix Moment.resolve_parameters to properly resolve symbolic expressions Changed equality check from '!=' to 'is not' to handle cases where symbolic parameters are equivalent but not identical objects Ensured that the method returns a new object only when a variable is resolved, maintaining efficient behavior. Tested the fix with existing cases for Rx, Ry, and Rz gates to confirm correct behavior when parameters are resolved or remain unchanged.
Hi @NoureldinYosri |
@NoureldinYosri - Looking at it again, quite a few Perhaps we can change the fix in Cirq/cirq-core/cirq/circuits/moment.py to
This will skip checks for operation change if a changed operation was already found before, and it would detect resolution of sympy constant to python numbers. |
This is why I want to the gates/operations to decide whether a change happended or not without using comparison
This won't work is the resolver is doing a partial resolution (i.e. resolving some parameters and leaving others) |
The corner case we are trying to solve here is of constant sympy expressions (without any free parameters) getting resolved to Python numbers passing the I am bit reluctant to make extra changes to gates |
@pavoljuhas if you want to just patch the problem, that's fine. but lets keep the issue open |
@pavoljuhas Thank you for reviewing and suggesting the changes. I have committed the updates. |
Problem: `Moment._resolve_parameters_` might keep constant sympy expression if its resolved value is numerically equal. Solution: Check if parameterization changed for the resolved operation and if so replace the original operation with resolved (even if equal). Fixes #6778 --------- Co-authored-by: Pavol Juhas <[email protected]> Co-authored-by: Noureldin <[email protected]>
The original example bug is fixed by #6794. If there are other cases which still fail, please reopen with such example. |
Description of the issue
How to reproduce the issue
results in:
as per discussion with @NoureldinYosri,
Moment.resolve_parameter
has a bug which can be bypassed by:results in the expected:
Cirq version
'1.5.0.dev'
The text was updated successfully, but these errors were encountered: