Open weucode opened 2 years ago
I know @1ucian0 and @alexanderivrii have been looking a bit at unifying some logic in CommutativeAnalysis
and a couple of other places in Qiskit, so this might be something they can sensible wrap up into that work. That said, I have a feeling that the issues with simulation at low optimisation levels might be a bug in Aer that was fixed in Qiskit/qiskit-aer#1519 - unfortunately you'll either need to build Aer from source, or wait for Aer 0.11 to be released for those bits to work, sorry.
The problem persists even without simulator, that is the following code
qc = QuantumCircuit(3)
qc.initialize("001", qc.qubits)
qc.cx(0, 1)
qc.measure_all()
print(qc)
qc2 = transpile(qc, optimization_level=2)
still produces the same error.
BTW, does it make sense that when transpiling with optimization_level
= 0 or 1, the Initialize
gate still remains in the circuit? Don't we want it to be expanded into the basic gates?
Your call doesn't specify any basis gates there, so there's nothing to expand to. The errors with Aer I was talkig about were for the cases in the original post where the transpilation succeeded, but simulation then failed.
Environment
What is happening?
When initialize the qubits in a circuit as follows,it will fail to simulate with
optimization_level=0,1
,and fail to transpile withoptimization_level=2
,and run successfully withoptimization_level=3
.The reasons are as follows.When
optimization_level=0,1
,the transpilation step will not modify initialize into other operator,so it failed in simulation step.When
optimization_level=2
,it fail to transpile the circuit when run theCommutationAnalysisza
pass.The code snippet to trigger transpile error is in the operator.py.The
defination
attribution of theinitialize
operator in this program is shown below:In the CommutationAnalysisza pass,it tried to get defination of every object,but the defination in
reset
object isNone
,so it raise a QiskitError.When
optimization_level=3
,it replaceinitialize
operator intoX
gate,so it run successfully.How can we reproduce the issue?
What should happen?
The results should be consistent with different
optimization_level
.Any suggestions?
Maybe it is feasible to add
initialize
into the check in line 94~96 in commutation_analysis.py,or give reset a defination.