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
I'm not certain but for large SparsePauliOp objects, it seems like the type-checking is a bottleneck for initializing the object (which also happens inside various SPO methods such as compose()):
In the most common case, we can avoid calling isinstance thousands of times by changing the logic to:
if isinstance(coeffs, np.ndarray):
if coeffs.dtype == object:
dtype = object
else:
dtype = complex
elif coeffs is not None:
if not isinstance(coeffs, (np.ndarray, Sequence)):
coeffs = [coeffs]
if any(isinstance(coeff, ParameterExpression) for coeff in coeffs):
dtype = object
else:
dtype = complex
Very crude timing test (seconds indicated at lower left); may want to confirm benchmark before committing. I repeated with seed=2 (not shown).
The text was updated successfully, but these errors were encountered:
What should we add?
I'm not certain but for large SparsePauliOp objects, it seems like the type-checking is a bottleneck for initializing the object (which also happens inside various SPO methods such as
compose()
):qiskit/qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py
Lines 134 to 142 in 02cb814
In the most common case, we can avoid calling
isinstance
thousands of times by changing the logic to:Very crude timing test (seconds indicated at lower left); may want to confirm benchmark before committing. I repeated with
seed=2
(not shown).The text was updated successfully, but these errors were encountered: