jcmgray / quimb

A python library for quantum information and many-body calculations including tensor networks.
http://quimb.readthedocs.io
Other
455 stars 107 forks source link

Fix `parse_constant_arg` for lists, tuples of `TensorNetwork`s #146

Closed mofeing closed 1 year ago

mofeing commented 1 year ago

I'm trying to optimize a TensorNetwork with a list of TensorNetworks as loss_constant, but it fails to parse them to constants.

The problem is that parse_constant_arg expects only a container of arrays (i.e. a TensorNetwork, a Tensor, a list/tuple/dict of arrays, or an array) and does not descend recursively.

This PR should fix it while keeping previous functionality intact.

codecov[bot] commented 1 year ago

Codecov Report

Merging #146 (dc5cf97) into develop (335b1d6) will decrease coverage by 0.02%. The diff coverage is 33.33%.

@@             Coverage Diff             @@
##           develop     #146      +/-   ##
===========================================
- Coverage    79.06%   79.03%   -0.03%     
===========================================
  Files           40       39       -1     
  Lines        15657    15639      -18     
===========================================
- Hits         12379    12361      -18     
  Misses        3278     3278              
Impacted Files Coverage Δ
quimb/tensor/optimize.py 66.38% <33.33%> (ø)
quimb/__init__.py

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

jcmgray commented 1 year ago

LGTM, thanks!

This reminds me it would be good to have the same kind of 'pytree' support for the actual optimized variables as well.

mofeing commented 1 year ago

This reminds me it would be good to have the same kind of 'pytree' support for the actual optimized variables as well.

Actually, I was already trying this because I have run into problems when JIT-compiling or using jax.vmap. I can open a new issue and discuss it.