-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Information
- Qiskit Terra version: master
- Python version: 3.7.8
- Operating system: MacOS
What is the current behavior?
Consider the following program, where circuit_in
is optimized by HoareOptimizer
pass as circuit_out
:
from numpy import pi
from qiskit import *
from qiskit.converters import *
from qiskit.transpiler.passes import HoareOptimizer
from qiskit.transpiler.passmanager import PassManager
circuit_in = QuantumCircuit(2)
circuit_in.h(0)
circuit_in.x(1)
circuit_in.cz(0, 1)
circuit_in.h(0)
circuit_in.measure_all()
def print_circuit_and_counts(circuit):
print(circuit)
backend = BasicAer.get_backend('qasm_simulator')
print(execute(circuit, backend=backend, optimization_level=0).result().get_counts())
print_circuit_and_counts(circuit_in)
pm = PassManager()
pm.append(HoareOptimizer(size=10))
circuit_out = pm.run(circuit_in)
print_circuit_and_counts(circuit_out)
┌───┐ ┌───┐ ░ ┌─┐
q_0: ┤ H ├─■─┤ H ├─░─┤M├───
├───┤ │ └───┘ ░ └╥┘┌─┐
q_1: ┤ X ├─■───────░──╫─┤M├
└───┘ ░ ║ └╥┘
meas: 2/═════════════════╩══╩═
0 1
{'11': 1024}
░ ┌─┐
q_0: ──────░─┤M├───
┌───┐ ░ └╥┘┌─┐
q_1: ┤ X ├─░──╫─┤M├
└───┘ ░ ║ └╥┘
meas: 2/═════════╩══╩═
0 1
{'10': 1024}
The optimization fully removes the H-CZ-H
sequence wrongly, breaking the semantics equivalence of the transformation.
What is the expected behavior?
I'm not fully sure if the original paper deals with phase (maybe the root of the problem). From what I remember, it seems to me that the qubit q_1
falls into a "trivial condition" and the CZ should be replaced by a Z gate in q_0
.
Notice that circuit_in.cz(1, 0)
(instead of circuit_in.cz(0, 1)
does not break the counting, since HoareOptimizer
does not detect any optimization, which is also unexpected. Maybe the problem is related to #4980?
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working