You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
File ~/projects/qiskit-terra/qiskit/circuit/parameterexpression.py:449, in ParameterExpression.__complex__(self)
448 try:
--> 449 return complex(self._symbol_expr)
450 # TypeError is for sympy, RuntimeError for symengine
File symengine_wrapper.pyx:1163, in symengine.lib.symengine_wrapper.Basic.__complex__()
File symengine_wrapper.pyx:976, in symengine.lib.symengine_wrapper.Basic.n()
File symengine_wrapper.pyx:4346, in symengine.lib.symengine_wrapper.evalf()
RuntimeError: Symbol cannot be evaluated.
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
Cell In [23], line 7
5 paulis = PauliList(labels)
6 coeffs = [1, 2, 3, 4, 5, Parameter("a")]
----> 7 spp_op = SparsePauliOp(paulis, coeffs)
File ~/projects/qiskit-terra/qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py:119, in SparsePauliOp.__init__(self, data, coeffs, ignore_pauli_phase, copy)
117 coeffs = np.ones(pauli_list.size, dtype=dtype)
118 else:
--> 119 coeffs = np.array(coeffs, copy=copy, dtype=dtype)
121 if ignore_pauli_phase:
122 # Fast path used in copy operations, where the phase of the PauliList is already known
123 # to be zero. This path only works if the input data is compatible with the internal
124 # ZX-phase convention.
125 self._pauli_list = pauli_list
File ~/projects/qiskit-terra/qiskit/circuit/parameterexpression.py:452, in ParameterExpression.__complex__(self)
450 # TypeError is for sympy, RuntimeError for symengine
451 except (TypeError, RuntimeError) as exc:
--> 452 raise TypeError(
453 "ParameterExpression with unbound parameters ({}) "
454 "cannot be cast to a complex.".format(self.parameters)
455 ) from exc
TypeError: ParameterExpression with unbound parameters ({Parameter(a)}) cannot be cast to a complex.
What should happen?
It should work (??)
Any suggestions?
This can be fixed by checking the type of the coefficients in the list. However, this incurs some overhead. So I'm actually not sure whether this behavior is intentional. @ikko
The text was updated successfully, but these errors were encountered:
I would actually also expect @kevinsung's example to work, it seems unintuitive if we have to wrap the coefficients in an array -- and that wouldn't work if I used from_list or from_sparse_list, right?
Is there an overhead to allowing Parameters directly or could we add that efficiently?
The overhead would be iterating through the list and checking the type of the elements.
An alternative to making the user wrap the coefficients in an array would be to allow them to specify the dtype. That may be slightly easier to discover.
Linking #8896 where this was also discussed. Personally, I would be in favor of supporting Parameters as they pretty much native numeric types in Qiskit and it would make life of users easier if one doesn't have to remember to explicitly set dtype=object.
Environment
What is happening?
See title.
How can we reproduce the issue?
What should happen?
It should work (??)
Any suggestions?
This can be fixed by checking the type of the coefficients in the list. However, this incurs some overhead. So I'm actually not sure whether this behavior is intentional. @ikko
The text was updated successfully, but these errors were encountered: