-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Description
Environment
- Qiskit version: 1.3.0rc1, main
- Python version: 3.12.7
- Operating system: macOS 15.1.1
What is happening?
The number of CZ gates after transpilation with optimization_level 2 and 3 increases drastically for 1.3.0rc1 and main branch compared with 1.2.4
How can we reproduce the issue?
I attach a zip file with qaoa.qpy
that includes the target circuit generated from QAOA.
I tried to make a minimal example, but I could not do it unfortunately.
Need to unzip the attachment file qaoa.zip to extract qaoa.qpy
.
from qiskit import generate_preset_pass_manager, qpy, __version__
from qiskit_ibm_runtime.fake_provider import FakeTorino
with open("qaoa.qpy", "rb") as file:
circuit = qpy.load(file)[0]
print(__version__)
print("before")
print(circuit.count_ops(), "\n")
backend = FakeTorino()
layout = [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 27, 26, 25, 24, 23, 22, 21]
for level in [1, 2, 3]:
pm = generate_preset_pass_manager(
optimization_level=level,
backend=backend,
initial_layout=layout,
layout_method="trivial",
routing_method="none",
)
tcircuit = pm.run(circuit)
print("optimization_level", level)
print(tcircuit.count_ops(), "\n")
1.2.4
before
OrderedDict({'PauliEvolution': 91, 'swap': 90, 'h': 17, 'rz': 17, 'rx': 17, 'measure': 17})
optimization_level 1
OrderedDict({'rz': 901, 'sx': 860, 'cz': 452, 'measure': 17})
optimization_level 2
OrderedDict({'rz': 701, 'sx': 697, 'cz': 308, 'measure': 17, 'x': 3})
optimization_level 3
OrderedDict({'rz': 701, 'sx': 697, 'cz': 308, 'measure': 17, 'x': 3})
1.3.0rc1
before
OrderedDict({'PauliEvolution': 91, 'swap': 90, 'h': 17, 'rz': 17, 'rx': 17, 'measure': 17})
optimization_level 1
OrderedDict({'rz': 901, 'sx': 860, 'cz': 452, 'measure': 17})
optimization_level 2
OrderedDict({'sx': 848, 'rz': 595, 'cz': 444, 'measure': 17})
optimization_level 3
OrderedDict({'sx': 848, 'rz': 595, 'cz': 444, 'measure': 17})
2.0.0.dev0+94cea41
before
OrderedDict({'PauliEvolution': 91, 'swap': 90, 'h': 17, 'rz': 17, 'rx': 17, 'measure': 17})
optimization_level 1
OrderedDict({'rz': 901, 'sx': 860, 'cz': 452, 'measure': 17})
optimization_level 2
OrderedDict({'sx': 848, 'rz': 595, 'cz': 444, 'measure': 17})
optimization_level 3
OrderedDict({'sx': 848, 'rz': 595, 'cz': 444, 'measure': 17})
What should happen?
The number of CZ gates should be as same as that of 1.2.4.
Any suggestions?
I tried callback to check the count ops for each pass and found that something is happening around ConsolidateBlocks
.
Collect2qBlocks
seems to disappear for the main branch.
from qiskit import generate_preset_pass_manager, qpy, __version__
from qiskit_ibm_runtime.fake_provider import FakeTorino
with open("qaoa.qpy", "rb") as file:
circuit = qpy.load(file)[0]
print(__version__)
backend = FakeTorino()
layout = [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 27, 26, 25, 24, 23, 22, 21]
def callback(**kwargs):
print(kwargs["pass_"])
print(kwargs["dag"].count_ops())
pm = generate_preset_pass_manager(
optimization_level=2,
backend=backend,
initial_layout=layout,
layout_method="trivial",
routing_method="none",
)
tcircuit = pm.run(circuit, callback=callback)
1.2.4
...
<qiskit.transpiler.passes.basis.basis_translator.BasisTranslator object at 0x114984b90>
{'rz': 921, 'sx': 955, 'cz': 452, 'measure': 17}
<qiskit.transpiler.passes.optimization.collect_2q_blocks.Collect2qBlocks object at 0x11494ce90>
{'rz': 921, 'sx': 955, 'cz': 452, 'measure': 17}
<qiskit.transpiler.passes.optimization.consolidate_blocks.ConsolidateBlocks object at 0x114a28bc0>
{'rz': 517, 'sx': 302, 'cz': 164, 'measure': 17, 'unitary': 72}
<qiskit.transpiler.passes.synthesis.unitary_synthesis.UnitarySynthesis object at 0x1142a54f0>
{'rz': 1141, 'sx': 720, 'cz': 308, 'x': 3, 'measure': 17}
...
2.0.0.dev0+94cea41
...
<qiskit.transpiler.passes.basis.basis_translator.BasisTranslator object at 0x13ba103b0>
{'rz': 921, 'sx': 955, 'cz': 452, 'measure': 17}
<qiskit.transpiler.passes.optimization.consolidate_blocks.ConsolidateBlocks object at 0x139e60ad0>
{'rz': 889, 'sx': 915, 'cz': 436, 'measure': 17, 'unitary': 4}
<qiskit.transpiler.passes.synthesis.unitary_synthesis.UnitarySynthesis object at 0x138c8f5f0>
{'rz': 933, 'sx': 939, 'cz': 444, 'measure': 17}
...
full log is available at https://gist.github.com/t-imamichi/eb35f536117e45dd89293e7e979132cb
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working