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
Aersimulator run and estimator do not work when method=extended_stabilizer
Steps to reproduce the problem
This small script shows what is happening:
importnumpyasnpfromqiskit_aerimportAerSimulatorfromqiskit.circuit.libraryimportEfficientSU2fromqiskit_aer.primitivesimportEstimatorasaer_estimatorfromqiskitimporttranspilebackend=AerSimulator(method="extended_stabilizer")
ansatz=EfficientSU2(1)
print(ansatz.decompose())
num_parameters=ansatz.num_parametersparameters=np.random.rand(num_parameters)
parameters=np.reshape(parameters, (-1, num_parameters)).tolist()
batch_size=len(parameters)
# RUNtry:
# This does not work ..._ansatz=transpile(ansatz, backend=backend, basis_gates=backend.configuration().basis_gates, optimization_level=2)
print(_ansatz.decompose())
job=backend.run(_ansatz, parameter_binds=[{k: [0] forkin_ansatz.parameters}])
print(job.result())
except:
# ... however this doesprint(ansatz.decompose())
job=backend.run(ansatz.decompose(), parameter_binds=[{k: [0] forkin_ansatz.parameters}])
print(job.result())
# PRIMITIVEestimator=aer_estimator(
backend_options=backend.options._fields,
transpile_options={"optimization_level": 2},
run_options=None,
approximation=False,
skip_transpilation=False,
)
try:
print("Estimator 1")
# This does not work ...operator="X"job=estimator.run(batch_size* [ansatz], batch_size* [operator], parameters)
print(job.result())
except:
print("Estimator 2")
# neither this ...job=estimator.run(batch_size* [ansatz.decompose()], batch_size* [operator], parameters)
print(job.result())
finally:
# nor this ...print("Estimator 3")
estimator=aer_estimator(
backend_options=backend.options._fields,
transpile_options={"optimization_level": 3},
run_options=None,
approximation=False,
skip_transpilation=True,
)
_ansatz=transpile(ansatz, backend=backend, basis_gates=backend.configuration().basis_gates, optimization_level=2)
job=estimator.run(batch_size* [_ansatz], batch_size* [operator], parameters)
print(job.result())
What is the expected behavior?
All of the above cases should run without any problem.
Suggested solutions
In all failure cases, the problem appears when trying to get the global phase of the circuit at a point when the parameters are unbound:
File "qiskit_aer/backends/aer_compiler.py", line 376, in assemble_circuit
global_phase = float(circuit.global_phase)
File "/qiskit/circuit/parameterexpression.py", line 477, in __float__
raise TypeError(
TypeError: ParameterExpression with unbound parameters ({ParameterVectorElement(θ[5]), ParameterVectorElement(θ[1]), ParameterVectorElement(θ[6]), ParameterVectorElement(θ[7]), ParameterVectorElement(θ[2]), ParameterVectorElement(θ[3]), ParameterVectorElement(θ[4]), ParameterVectorElement(θ[0])}) cannot be cast to a float.
So probably it needs to be done before explicitly, note however, this would not explain why with other methods is working.
The text was updated successfully, but these errors were encountered:
Thank you for your report. @ikkoham thankfully identified the root cause of this issue with a small test case as follows:
from qiskit import QuantumCircuit
from qiskit.circuit import Parameter
from qiskit_aer import AerSimulator
backend = AerSimulator(method="stabilizer")
a = Parameter("a")
qc = QuantumCircuit(1)
qc.global_phase = a
print(qc)
backend.run(qc).result()
In transpliation with extended_stabilizer method, this global _phase is modified with parameterized values, but current Aer does not have implementation for this parameterization. I guess that this bug is since Aer began :-). Thank you for your reporting.
Informations
What is the current behavior?
Aersimulator run and estimator do not work when method=extended_stabilizer
Steps to reproduce the problem
This small script shows what is happening:
What is the expected behavior?
All of the above cases should run without any problem.
Suggested solutions
In all failure cases, the problem appears when trying to get the global phase of the circuit at a point when the parameters are unbound:
So probably it needs to be done before explicitly, note however, this would not explain why with other methods is working.
The text was updated successfully, but these errors were encountered: