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

physics.normalize not working for all states #518

Open
1 task done
JacobHast opened this issue Nov 5, 2024 · 2 comments
Open
1 task done

physics.normalize not working for all states #518

JacobHast opened this issue Nov 5, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@JacobHast
Copy link
Contributor

JacobHast commented Nov 5, 2024

Before posting a bug report

  • I have searched exisisting GitHub issues to make sure the issue does not already exist.

Expected behavior

I expect physics.normalize to return a normalized state for all representations

Actual behavior

The following code produces an error:

from mrmustard.physics import normalize
import mrmustard.lab_dev as mm
state = mm.Vacuum(modes=[0])
normalize(state)

Reproduces how often

Always

System information

Mr Mustard: a differentiable bridge between phase space and Fock space.
Copyright 2021 Xanadu Quantum Technologies Inc.

Python version:            3.10.14
Platform info:             Windows-10-10.0.19045-SP0
Installation path:         
c:\Users\jacob\miniconda3\envs\mrmustard_dev\lib\site-packages\mrmustard
Mr Mustard version:        0.7.3
Numpy version:             1.23.5
Numba version:             0.59.1
Scipy version:             1.14.1
The Walrus version:        0.21.0
TensorFlow version:        2.17.0

Source code

from mrmustard.physics import normalize
import mrmustard.lab_dev as mm
state = mm.Vacuum(modes=[0])
normalize(state)


### Tracebacks

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], [line 4](vscode-notebook-cell:?execution_count=2&line=4)
      [2](vscode-notebook-cell:?execution_count=2&line=2) import mrmustard.lab_dev as mm
      [3](vscode-notebook-cell:?execution_count=2&line=3) state = mm.Vacuum(modes=[0])
----> [4](vscode-notebook-cell:?execution_count=2&line=4) normalize(state)

File c:\Users\jacob\miniconda3\envs\mrmustard_dev\lib\site-packages\mrmustard\physics\__init__.py:51, in normalize(A)
     [42](file:///C:/Users/jacob/miniconda3/envs/mrmustard_dev/lib/site-packages/mrmustard/physics/__init__.py:42) def normalize(A):
     [43](file:///C:/Users/jacob/miniconda3/envs/mrmustard_dev/lib/site-packages/mrmustard/physics/__init__.py:43)     r"""Returns the normalized state.
     [44](file:///C:/Users/jacob/miniconda3/envs/mrmustard_dev/lib/site-packages/mrmustard/physics/__init__.py:44) 
     [45](file:///C:/Users/jacob/miniconda3/envs/mrmustard_dev/lib/site-packages/mrmustard/physics/__init__.py:45)     Args:
   (...)
     [49](file:///C:/Users/jacob/miniconda3/envs/mrmustard_dev/lib/site-packages/mrmustard/physics/__init__.py:49)         State: the normalized state
     [50](file:///C:/Users/jacob/miniconda3/envs/mrmustard_dev/lib/site-packages/mrmustard/physics/__init__.py:50)     """
---> [51](file:///C:/Users/jacob/miniconda3/envs/mrmustard_dev/lib/site-packages/mrmustard/physics/__init__.py:51)     if A.is_gaussian:
     [52](file:///C:/Users/jacob/miniconda3/envs/mrmustard_dev/lib/site-packages/mrmustard/physics/__init__.py:52)         A._norm = 1.0
     [53](file:///C:/Users/jacob/miniconda3/envs/mrmustard_dev/lib/site-packages/mrmustard/physics/__init__.py:53)         return A

AttributeError: 'Vacuum' object has no attribute 'is_gaussian'

### Additional information

_No response_
@JacobHast JacobHast added the bug Something isn't working label Nov 5, 2024
@JacobHast
Copy link
Contributor Author

I understand now that one should use the .normalize state method instead. Perhaps then the fix is instead to add a legacy tag in the docstring or elsewhere on this function, pointing to the .normalize method

@ziofil
Copy link
Collaborator

ziofil commented Nov 5, 2024

Hi Jacob, yes indeed, the .normalize method is the new way to do things. We are going to remove all the old lab stuff soon. Thanks for your patience :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants