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

from_polynomial_tensor constructor creates 0d array instead of scalar for constant coefficient #1258

Closed
grossardt opened this issue Sep 24, 2023 · 0 comments · Fixed by #1259
Labels

Comments

@grossardt
Copy link
Contributor

Environment

  • Qiskit Nature version: 0.7.0
  • Python version: 3.10.12
  • Operating system: Linux

What is happening?

from_polynomial_tensor constructor for

  • BosonicOp
  • FermionicOp
  • SpinOp
  • VibrationalOp

produces constant part (empty string key) with coefficient a 0d numpy array (should be number, as for the rest of coefficients)

How can we reproduce the issue?

from qiskit_nature.second_q.operators import BosonicOp, PolynomialTensor
import numpy as np
data = {'': 1, '+': np.array([1,0])}
t = PolynomialTensor(data)
b = BosonicOp.from_polynomial_tensor(t)
print(b._data)

Output:

{'': array(1), '+_0': 1}

What should happen?

Output should be:

{'': 1, '+_0': 1}

Any suggestions?

In line 246 of bosonic_op.py (and equivalent lines for fermionic_op.py, spin_op.py, vibrational_op.py):

data[""] = tensor[key]

cast rhs to scalar, e.g. by applying sum method to 0d tensor:

data[""] = tensor[key].sum()
@grossardt grossardt added the bug label Sep 24, 2023
@mrossinek mrossinek linked a pull request Sep 25, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant