Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustiq results in deeper circuits #13756

Open
t-imamichi opened this issue Jan 29, 2025 · 1 comment
Open

Rustiq results in deeper circuits #13756

t-imamichi opened this issue Jan 29, 2025 · 1 comment
Labels

Comments

@t-imamichi
Copy link
Member

What should we add?

I found an example that rustiq does not work well. It generates a circuit with twice the number of CZ gates compared without rustiq.
I conducted the following experiments on macOS 15.2 and Python 3.12.8.

from qiskit import QuantumCircuit, __version__, generate_preset_pass_manager
from qiskit.circuit.library import PauliEvolutionGate
from qiskit.quantum_info import SparsePauliOp
from qiskit.transpiler.passes import HLSConfig
from qiskit_ibm_runtime.fake_provider import FakeTorino

print(__version__)

config = HLSConfig(PauliEvolution=[("rustiq", {"upto_phase": True})])

backend = FakeTorino()
pm = generate_preset_pass_manager(optimization_level=3, backend=backend)
pm_rustiq = generate_preset_pass_manager(optimization_level=3, backend=backend, hls_config=config)

qc = QuantumCircuit(3)
op = SparsePauliOp(["XXI", "YYI", "ZZI", "IXX", "IYY", "IZZ"])
print(op)
evo = PauliEvolutionGate(op, 1)
qc.append(evo, qargs=qc.qubits)
tqc = pm.run(qc)
print("optimization_level 3")
print(tqc.draw(idle_wires=False))
print(tqc.count_ops())

tqc = pm_rustiq.run(qc)
print("\noptimization_level 3 + Rustiq")
print(tqc.draw(idle_wires=False))
print(tqc.count_ops())
# qiskit 1.3.2
1.3.2
SparsePauliOp(['XXI', 'YYI', 'ZZI', 'IXX', 'IYY', 'IZZ'],
              coeffs=[1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j])
optimization_level 3
global phase: 3π/2
           ┌─────────┐    ┌────┐      ┌─────────┐    ┌────┐    ┌────────┐┌────┐   ┌────┐┌────────┐┌────┐   ┌──────────┐   ┌────┐  ┌────────┐  ┌────┐   »
q_1 -> 126 ┤ Rz(π/2) ├────┤ √X ├────■─┤ Rz(π/2) ├────┤ √X ├────┤ Rz(-2) ├┤ √X ├─■─┤ √X ├┤ Rz(-2) ├┤ √X ├─■─┤ Rz(-π/2) ├─■─┤ √X ├──┤ Rz(-2) ├──┤ √X ├─■─»
           └──┬────┬─┘┌───┴────┴──┐ │ └──┬────┬─┘┌───┴────┴───┐└────────┘└────┘ │ ├────┤└────────┘└────┘ │ ├─────────┬┘ │ └────┘  └────────┘  └────┘ │ »
q_2 -> 127 ───┤ √X ├──┤ Rz(-3π/2) ├─■────┤ √X ├──┤ Rz(0.4292) ├─────────────────■─┤ √X ├─────────────────■─┤ Rz(π/2) ├──┼────────────────────────────┼─»
              ├────┤  ├───────────┤      └────┘  └────────────┘                   └────┘                   └─────────┘  │ ┌────┐┌────────────┐       │ »
q_0 -> 132 ───┤ √X ├──┤ Rz(-3π/2) ├─────────────────────────────────────────────────────────────────────────────────────■─┤ √X ├┤ Rz(0.4292) ├───────■─»
              └────┘  └───────────┘                                                                                       └────┘└────────────┘         »
«           ┌────┐┌────────┐┌────┐      ┌────┐  ┌─────────┐
«q_1 -> 126 ┤ √X ├┤ Rz(-2) ├┤ √X ├─■────┤ √X ├──┤ Rz(π/2) ├
«           └────┘└────────┘└────┘ │    └────┘  └─────────┘
«q_2 -> 127 ───────────────────────┼───────────────────────
«           ┌────┐                 │ ┌─────────┐
«q_0 -> 132 ┤ √X ├─────────────────■─┤ Rz(π/2) ├───────────
«           └────┘                   └─────────┘
OrderedDict({'sx': 16, 'rz': 14, 'cz': 6})

optimization_level 3 + Rustiq
global phase: π
           ┌────────┐┌───┐              ┌─────────┐    ┌────┐    ┌────────────┐┌────┐   ┌────┐   ┌───────┐    ┌────┐┌───────┐                         »
q_2 -> 37 ─┤ Rz(-π) ├┤ X ├────────────■─┤ Rz(π/2) ├────┤ √X ├────┤ Rz(1.1416) ├┤ √X ├─■─┤ √X ├───┤ Rz(2) ├────┤ √X ├┤ Rz(π) ├─────────────────────────»
           └────────┘└───┘            │ └─────────┘    └────┘    └────────────┘└────┘ │ └────┘   └───────┘    └────┘└───────┘┌────┐┌──────────────┐   »
q_0 -> 51 ────────────────────────────┼───────────────────────────────────────────────┼─────────────────────────────────■────┤ √X ├┤ Rz(-0.92457) ├─■─»
          ┌─────────┐┌────┐┌────────┐ │    ┌────┐  ┌────────────┐                     │ ┌────┐┌──────────────┐┌────┐    │    ├────┤└──────────────┘ │ »
q_1 -> 52 ┤ Rz(π/2) ├┤ √X ├┤ Rz(-π) ├─■────┤ √X ├──┤ Rz(4.2832) ├─────────────────────■─┤ √X ├┤ Rz(-0.35245) ├┤ √X ├────■────┤ √X ├─────────────────■─»
          └─────────┘└────┘└────────┘      └────┘  └────────────┘                       └────┘└──────────────┘└────┘         └────┘                   »
«                                                                                                                                                        »
«q_2 -> 37 ────────────────────────────■──────────────────────────────────■──────────────────────────────────────────────────────────────────────────────»
«          ┌────┐┌─────────────┐┌────┐ │ ┌────────────┐                   │ ┌────┐┌─────────────┐┌────┐┌──────────┐   ┌────┐   ┌────┐                    »
«q_0 -> 51 ┤ √X ├┤ Rz(-2.5933) ├┤ √X ├─┼─┤ Rz(2.4178) ├────────────────■──┼─┤ √X ├┤ Rz(-2.7124) ├┤ √X ├┤ Rz(-π/2) ├─■─┤ √X ├─■─┤ √X ├─■──────────────────»
«          ├────┤└─┬──────────┬┘└────┘ │ └───┬────┬───┘┌─────────────┐ │  │ ├────┤└─┬─────────┬─┘└────┘└──────────┘ │ ├────┤ │ ├────┤ │ ┌─────────┐┌────┐»
«q_1 -> 52 ┤ √X ├──┤ Rz(-π/2) ├────────■─────┤ √X ├────┤ Rz(-5.1416) ├─■──■─┤ √X ├──┤ Rz(π/2) ├─────────────────────■─┤ √X ├─■─┤ √X ├─■─┤ Rz(π/2) ├┤ √X ├»
«          └────┘  └──────────┘              └────┘    └─────────────┘      └────┘  └─────────┘                       └────┘   └────┘   └─────────┘└────┘»
«
«q_2 -> 37 ──────────■──────────────────────────────
«                    │          ┌───────┐
«q_0 -> 51 ──────────┼────────■─┤ Rz(π) ├───────────
«          ┌───────┐ │ ┌────┐ │ └─┬────┬┘┌─────────┐
«q_1 -> 52 ┤ Rz(π) ├─■─┤ √X ├─■───┤ √X ├─┤ Rz(π/2) ├
«          └───────┘   └────┘     └────┘ └─────────┘
OrderedDict({'sx': 24, 'rz': 21, 'cz': 12, 'x': 1})
# main branch
2.0.0.dev0+e9ccd3f
SparsePauliOp(['XXI', 'YYI', 'ZZI', 'IXX', 'IYY', 'IZZ'],
              coeffs=[1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j])
optimization_level 3
global phase: 3π/2
           ┌─────────┐    ┌────┐      ┌─────────┐    ┌────┐    ┌────────┐┌────┐   ┌────┐┌────────┐┌────┐   ┌──────────┐   ┌────┐  ┌────────┐  ┌────┐   »
q_1 -> 126 ┤ Rz(π/2) ├────┤ √X ├────■─┤ Rz(π/2) ├────┤ √X ├────┤ Rz(-2) ├┤ √X ├─■─┤ √X ├┤ Rz(-2) ├┤ √X ├─■─┤ Rz(-π/2) ├─■─┤ √X ├──┤ Rz(-2) ├──┤ √X ├─■─»
           └──┬────┬─┘┌───┴────┴──┐ │ └──┬────┬─┘┌───┴────┴───┐└────────┘└────┘ │ ├────┤└────────┘└────┘ │ ├─────────┬┘ │ └────┘  └────────┘  └────┘ │ »
q_2 -> 127 ───┤ √X ├──┤ Rz(-3π/2) ├─■────┤ √X ├──┤ Rz(0.4292) ├─────────────────■─┤ √X ├─────────────────■─┤ Rz(π/2) ├──┼────────────────────────────┼─»
              ├────┤  ├───────────┤      └────┘  └────────────┘                   └────┘                   └─────────┘  │ ┌────┐┌────────────┐       │ »
q_0 -> 132 ───┤ √X ├──┤ Rz(-3π/2) ├─────────────────────────────────────────────────────────────────────────────────────■─┤ √X ├┤ Rz(0.4292) ├───────■─»
              └────┘  └───────────┘                                                                                       └────┘└────────────┘         »
«           ┌────┐┌────────┐┌────┐      ┌────┐  ┌─────────┐
«q_1 -> 126 ┤ √X ├┤ Rz(-2) ├┤ √X ├─■────┤ √X ├──┤ Rz(π/2) ├
«           └────┘└────────┘└────┘ │    └────┘  └─────────┘
«q_2 -> 127 ───────────────────────┼───────────────────────
«           ┌────┐                 │ ┌─────────┐
«q_0 -> 132 ┤ √X ├─────────────────■─┤ Rz(π/2) ├───────────
«           └────┘                   └─────────┘
OrderedDict({'sx': 16, 'rz': 14, 'cz': 6})

optimization_level 3 + Rustiq
global phase: 3π/4
          ┌─────────┐ ┌────┐                                                                                               ┌────┐     ┌────┐              »
q_0 -> 37 ┤ Rz(π/2) ├─┤ √X ├──────────────────────────────────────────────────────────────────────────────────────────■────┤ √X ├───■─┤ √X ├─■────────────»
          └──┬────┬─┘ └────┘               ┌─────────┐    ┌────┐    ┌────────────┐┌────┐   ┌────┐┌────────────┐┌────┐ │ ┌──┴────┴─┐ │ └────┘ │            »
q_1 -> 51 ───┤ √X ├──────────────────────■─┤ Rz(π/2) ├────┤ √X ├────┤ Rz(1.1416) ├┤ √X ├─■─┤ √X ├┤ Rz(0.4292) ├┤ √X ├─┼─┤ Rz(π/2) ├─┼────────┼────────────»
          ┌──┴────┴──┐┌────┐┌──────────┐ │ └──┬────┬─┘┌───┴────┴───┐└────────────┘└────┘ │ ├────┤└┬─────────┬─┘└────┘ │ └──┬────┬─┘ │ ┌────┐ │ ┌─────────┐»
q_2 -> 52 ┤ Rz(-π/2) ├┤ √X ├┤ Rz(-π/2) ├─■────┤ √X ├──┤ Rz(4.2832) ├─────────────────────■─┤ √X ├─┤ Rz(π/2) ├─────────■────┤ √X ├───■─┤ √X ├─■─┤ Rz(π/2) ├»
          └──────────┘└────┘└──────────┘      └────┘  └────────────┘                       └────┘ └─────────┘              └────┘     └────┘   └─────────┘»
«                                 ┌──────────┐                                                                                                            »
«q_0 -> 37 ─────────────────────■─┤ Rz(3π/2) ├───────────────────────────────────■────────────────────────────────────────────────────────────────────────»
«                               │ └──┬────┬──┘ ┌────────────┐┌────┐┌────────┐    │ ┌────┐┌─────────────┐┌────┐┌──────────┐   ┌────┐   ┌────┐              »
«q_1 -> 51 ──────────────────■──┼────┤ √X ├────┤ Rz(5.1416) ├┤ √X ├┤ Rz(3π) ├─■──┼─┤ √X ├┤ Rz(-2.7124) ├┤ √X ├┤ Rz(-π/2) ├─■─┤ √X ├─■─┤ √X ├─■────────────»
«          ┌────┐┌─────────┐ │  │    ├────┤   ┌┴────────────┤└────┘└────────┘ │  │ ├────┤└─┬─────────┬─┘└────┘└──────────┘ │ ├────┤ │ ├────┤ │ ┌─────────┐»
«q_2 -> 52 ┤ √X ├┤ Rz(π/2) ├─■──■────┤ √X ├───┤ Rz(-5.1416) ├─────────────────■──■─┤ √X ├──┤ Rz(π/2) ├─────────────────────■─┤ √X ├─■─┤ √X ├─■─┤ Rz(π/2) ├»
«          └────┘└─────────┘         └────┘   └─────────────┘                      └────┘  └─────────┘                       └────┘   └────┘   └─────────┘»
«
«q_0 -> 37 ────────────────■──────────────────────────────
«                          │          ┌───────┐
«q_1 -> 51 ────────────────┼────────■─┤ Rz(π) ├───────────
«          ┌────┐┌───────┐ │ ┌────┐ │ └─┬────┬┘┌─────────┐
«q_2 -> 52 ┤ √X ├┤ Rz(π) ├─■─┤ √X ├─■───┤ √X ├─┤ Rz(π/2) ├
«          └────┘└───────┘   └────┘     └────┘ └─────────┘
OrderedDict({'sx': 27, 'rz': 22, 'cz': 14})
@Cryoris
Copy link
Contributor

Cryoris commented Jan 30, 2025

Thanks for the report @t-imamichi 🙂 Rustiq can struggle with 2-local terms, it will have a better improvement for denser Hamiltonians. Afaik @smartiel and @alexanderivrii are looking into how to improve the heuristics here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants