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

sympy can't handle symbolic Sum of JzKets #23820

Open
James471 opened this issue Jul 23, 2022 · 3 comments
Open

sympy can't handle symbolic Sum of JzKets #23820

James471 opened this issue Jul 23, 2022 · 3 comments

Comments

@James471
Copy link

I tried to create a linear combination of sympy.physics.quantum.spin.JzKets using
state = sm.Sum((2**m)*qt.spin.JzKet(J, m), (m, -J, J)) and tried to find it's norm using
(sympy.physics.quantum.qapply(qt.Dagger(state)*state).doit())
The output is
image
which is clearly incorrect. Cleary qapply() doesn't understand a Sum object.

@oscarbenjamin
Copy link
Contributor

Can you show a complete code example to reproduce this including imports? What should the correct answer be?

It might be a bug in Sum rather than qapply.

The quantum module is currently unmaintained. Feel free to submit a PR to fix this.

@kushagrasachan
Copy link

Following are the imports I used to reproduce this issue:

import sympy as sp
from sympy.abc import k,m,J

import sympy.physics.quantum as qt

import sympy.concrete.summations as sm

The OP's statement state = sm.Sum((2**m)*qt.spin.JzKet(J, m), (m, -J, J)) produces the output to be:
Screenshot 2023-05-15 at 6 47 43 PM
which, while "looks" correct to our expectation, is not, as is indicated by:
Screenshot 2023-05-15 at 6 51 36 PM

This shows that the object is not behaving as a quantum state, but instead the $\sum_m 2^m$ chunk of the expression is being interpreted by sympy as a separate, geometric summation. The kets $|J,m\rangle$ ought to be part of the summation as well.

Hence, I do believe that it's an inadequacy of Sum, as suggested—an incompatibility of Sum and Quantum objects' implementations.

Above,state is a <class 'sympy.concrete.summations.Sum'> object, while one would expect a correct implementation to return an object of perhaps some subclass of <class 'sympy.physics.quantum.state'>.

These seem to be the reasons (or more) for the OP's issue, hereby seen reproduced with a slight deviation (suspected to be from some update ever since):
Screenshot 2023-05-15 at 7 37 48 PM

Attempting to calculate OP's desired norm expression by alternatively using the innerproduct method, hints that we should perhaps somehow try to implement returning a sympy.physics.quantum.state.KetBase object.
Screenshot 2023-05-15 at 8 03 50 PM

@travlight
Copy link

travlight commented Mar 5, 2024

I am wondering if this issue can be solved, because I also confront the same problem when I want to define a thermal state in Fock basis.
image
The problem here is that the summation function cannot recognize the dummy index inside the braket notation like sum over k for |k><k|.

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

No branches or pull requests

4 participants