Skip to content
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

Avoid DivisionByZero error when TensorNetwork simplifies to a scalar #6586

Merged

Conversation

pavoljuhas
Copy link
Collaborator

Problem: Python 3.12 requires quimb-1.8.0, but quimb-1.8.0 cannot
evaluate path-info for TensorNetwork consisting of a scalar Tensor.

Solution: Skip path-info evaluation for scalar TensorNetwork.
Path-info is used for RAM estimation only which is not a problem
for scalar TensorNetwork-s.

This fixes unit test failure for
cirq-core/cirq/contrib/quimb/grid_circuits_test.py::test_tensor_expectation_value

Ref: jcmgray/quimb#231

Problem: Python 3.12 requires quimb-1.8.0, but quimb-1.8.0 cannot
evaluate path-info for TensorNetwork consisting of a scalar Tensor.

Solution: Skip path-info evaluation for scalar TensorNetwork.
Path-info is used for RAM estimation only which is not a problem
for scalar TensorNetwork-s.

This fixes unit test failure for
cirq-core/cirq/contrib/quimb/grid_circuits_test.py::test_tensor_expectation_value

Ref: jcmgray/quimb#231
@pavoljuhas pavoljuhas requested review from vtomole, cduck and a team as code owners May 6, 2024 22:34
@CirqBot CirqBot added the size: S 10< lines changed <50 label May 6, 2024
@pavoljuhas pavoljuhas requested a review from NoureldinYosri May 7, 2024 20:37
path_info = tn.contract(get='path-info')
ram_gb = path_info.largest_intermediate * 128 / 8 / 1024 / 1024 / 1024
else:
ram_gb = 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we raise an error or log a warning?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is needed. The error happens for a trivial TensorNetwork([Tensor()]) for which the memory requirements will be tiny.
The bug was BTW already fixed upstream, but I think we should still merge this so we support the current quimb-1.8.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a TODO to remove this when we upgrade quimb ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done.

Copy link

codecov bot commented May 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.79%. Comparing base (69e3de1) to head (016b758).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6586   +/-   ##
=======================================
  Coverage   97.79%   97.79%           
=======================================
  Files        1124     1124           
  Lines       95703    95705    +2     
=======================================
+ Hits        93589    93595    +6     
+ Misses       2114     2110    -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pavoljuhas pavoljuhas merged commit bfba965 into quantumlib:main May 7, 2024
31 checks passed
@pavoljuhas pavoljuhas deleted the handle-divzero-error-in-quimb branch May 7, 2024 21:11
jselig-rigetti pushed a commit to jselig-rigetti/Cirq that referenced this pull request May 28, 2024
…uantumlib#6586)

Problem: Python 3.12 requires quimb-1.8.0, but quimb-1.8.0 cannot
evaluate path-info for TensorNetwork consisting of a scalar Tensor.

Solution: Skip path-info evaluation for scalar TensorNetwork.
Path-info is used for RAM estimation only which is not a problem
for scalar TensorNetwork-s.

This fixes unit test failure for
cirq-core/cirq/contrib/quimb/grid_circuits_test.py::test_tensor_expectation_value

Ref: jcmgray/quimb#231
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
…uantumlib#6586)

Problem: Python 3.12 requires quimb-1.8.0, but quimb-1.8.0 cannot
evaluate path-info for TensorNetwork consisting of a scalar Tensor.

Solution: Skip path-info evaluation for scalar TensorNetwork.
Path-info is used for RAM estimation only which is not a problem
for scalar TensorNetwork-s.

This fixes unit test failure for
cirq-core/cirq/contrib/quimb/grid_circuits_test.py::test_tensor_expectation_value

Ref: jcmgray/quimb#231
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: S 10< lines changed <50
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants