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

AttributeError: 'complex' object has no attribute 'norm' #162

Open
gsteele13 opened this issue Nov 6, 2024 · 7 comments
Open

AttributeError: 'complex' object has no attribute 'norm' #162

gsteele13 opened this issue Nov 6, 2024 · 7 comments

Comments

@gsteele13
Copy link
Contributor

In a recnet install, I ran into this error:

File ~\AppData\Local\miniforge3\envs\qiskit-metal-pip\lib\site-packages\pyEPR\calcs\back_box_numeric.py:225, in make_dispersive.<locals>.closest_state_to.<locals>.distance(s2)
    224 def distance(s2):
--> 225     return (s.dag() * s2[1]).norm()

AttributeError: 'complex' object has no attribute 'norm'

Some googling suggests that this is related to problems with changes in numpy between 1.19 and 1.20:

https://groups.google.com/g/qutip/c/R0kXhv1rtO8
https://www.reddit.com/r/QuantumComputing/comments/1dll5gh/pyepr_tutorial_1_questions/

It looks like a pretty simple fix? I may look into fixing it and submitting a pull request.

Copy link

github-actions bot commented Nov 6, 2024

👏👏👏 You are awesome! Thank you for making your first issue to pyEPR ' first issue

@gsteele13
Copy link
Contributor Author

ok, to my great sadness, reinstalling everything and downgrading to numpy 1.19 did not get my code to run. i will indeed have to pull the pyepr code and fix the bug.

@gsteele13
Copy link
Contributor Author

OK, I realise that I am too much of a noob to figure out how to create a pull request. But in any case, this diff fixed my problem:

image

I see .norm() used a few more times in the file, but I have not yet run into issues with it causing errors.

@gsteele13 gsteele13 changed the title incompatibility with numpy > 1.19? (AttributeError: 'complex' object has no attribute 'norm') AttributeError: 'complex' object has no attribute 'norm' Nov 6, 2024
@zlatko-minev
Copy link
Owner

zlatko-minev commented Nov 7, 2024 via email

@gsteele13
Copy link
Contributor Author

gsteele13 commented Nov 7, 2024

Hi Zlatko,

Yes, in fact, during the pip install ., it upgraded already numpy to 1.24. I also just did some testing and it works fine, this was my test:

mamba create -n qiskit-metal-pip python=3.10 pint=0.23
mamba activate qiskit-metal-pip
mamba install qiskit-metal notebook
pip install git+https://github.com/gsteele13/pyEPR.git
jupyter notebook

then Open 4.02 Eigenmode and EPR.ipynb => Make sure all cells run

Python 3.12 does not work with qiskit metal (kernel crashes on import) so I rolled back to 3.10 there. And, furthermore, pint 0.24 also breaks qiskit metal, I found that rolling back to 0.23 solves the issue. I should probably make some issues in the qiskit-metal repo (may do that when I have time...)

In any case, with a pretty fresh install based on a constraint to python 3.10, the code in this pull request works fine.

@zlatko-minev
Copy link
Owner

Thanks @gsteele13
Yes we can update the requirements if we are confident what new ones will work

@ball199578
Copy link

Thanks.I use Gary‘s to solve this problem and it works.But if numpy>=2.0(my numpy=2.1.3),I meet another problem:np.mat was removed in the NumPy 2.0 release. Use np.asmatrix instead.(core_quantum_analysis.py:788),my coding ability is very poor,cannot change it.So I change numpy2.1.3 to numpy1.25.It works and can run all the code of Startup example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants