-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
Labels
bugSomething isn't workingSomething isn't workingmod: quantum infoRelated to the Quantum Info module (States & Operators)Related to the Quantum Info module (States & Operators)
Description
Environment
- Qiskit version: any that has
SparsePauliOp.from_sparse_list - Python version: 3.11
- Operating system: macOS
What is happening?
From @BryceFuller:
Another question, what is the proper way to instantiate a SparsePauliOp with parameterized coefficients?
I'm running into a curious snag where I have an already parameterized operator, which I then want to apply transformations to.
I'm exporting to a sparse list, making some changes, then trying to re-instantiate the operator, but I observe an error with the parameterized coefficients.
How can we reproduce the issue?
Here's a MWE
param = Parameter('a')
# In my situation, this parameterized operator is given to me after being
# made through composition of smaller parameterized operators
op1 = SparsePauliOp.from_sparse_list([('IX', [0,1], 2),('ZI', [0,1], 3)], num_qubits = 2)
op1 *= param
# This breaks because there are parameter expressions in the coeffs
op2 = SparsePauliOp.from_sparse_list(op1.to_sparse_list(), num_qubits=2)What should happen?
Like the SparsePauliOp initializer, we should determine the dtype from the input coefficients. The dtype can already be set manually, via
op2 = SparsePauliOp.from_sparse_list(op1.to_sparse_list(), num_qubits=2, dtype=object)but it would be nice to automate this, given that the class initializer does the same thing.
Any suggestions?
No response
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingmod: quantum infoRelated to the Quantum Info module (States & Operators)Related to the Quantum Info module (States & Operators)