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

Add Rustiq-based synthesis for PauliEvolutionGate #13301

Merged
merged 48 commits into from
Nov 7, 2024

Conversation

alexanderivrii
Copy link
Contributor

@alexanderivrii alexanderivrii commented Oct 9, 2024

Summary

Calls the Rustiq's synthesis algorithm for pauli networks natively from within Qiskit.

Together with #13295 addresses #12789.
This should be rebased on top of #13295, in order to support the plugin interface structure for PauliEvolutionGates.

Rustiq is available at https://github.com/smartiel/rustiq-core

How to experiment

One can experiment with the new functionality by creating a PauliEvolutionGate and directly calling the new PauliEvolutionSynthesisRustiq on this gate:

from qiskit.transpiler.passes.synthesis.hls_plugins import PauliEvolutionSynthesisRustiq

terms = ["IX", "ZZ"]
evo_gate = PauliEvolutionGate(SparsePauliOp(terms), time=0.12)
qct = PauliEvolutionSynthesisRustiq().run(evo_gate)

Alternatively, one can create a circuit with PauliEvolutionGates and specify "rustiq" via the synthesis config interface:

terms = ["IX", "ZZ"]
evo_gate = PauliEvolutionGate(SparsePauliOp(terms), time=0.12)
qc = QuantumCircuit(3)
qc.append(evo_gate, [1, 2])
config = HLSConfig(PauliEvolution=["rustiq"])
qct = transpile(qc, hls_config=config)

Details:

The Qiskit Rust function pauli_network_synthesis calls the greedy_pauli_network function from the rustiq-core (in particular, most of the code is fully in Rust). However, the latter function only returns a sequence of Clifford gates, without the single-qubit rotations. So pauli_network_synthesis also adapts the code from Simon's private rustiq-plugin repository that simulates the circuit and inserts rotations wherever required.

Preliminary Experiments:

To be updated (or maybe it would be even best to move this discussion to the issue #12789). After running some preliminary experiments on some specific examples (e.g. see #13285) and some hamlib examples (taken from https://github.com/Qiskit/benchpress/blob/main/benchpress/hamiltonian/hamlib/), rustiq can be amazingly powerful in many cases, greatly reducing the two-qubits gate-count and depth of the resulting circuit. On the other hand, there are also cases where Rustiq performs worse, i.e. creating a circuit with more gates.

Some Concerns:

  • On some of the hamlib examples Rustiq is extremely fast, yet there are also examples where it takes more than 1 hour to complete.
  • In some cases the resulting circuit is not fully deterministic. I am currently trying to understand why this happens.
  • So far in all the cases the circuit produced by Rustiq is equivalent to the circuit produced by the default synthesis algorithm in Qiskit, up to the global phase, however the global phase difference is not always 0. This is after taking care of global phase updates related to all-I pauli rotation gates. I am also trying to understand why this happens.

It is possible that some additional changes to Rustiq itself might be required.

ToDo:

  • Docstring improvements, release notes, new plugin documentation, documenting rustiq-specific options, etc.
  • Tests: make sure that the output circuits are correct and are equivalent to the circuits produced by the default algorithm, make sure that the plugins run as intended

@alexanderivrii alexanderivrii added this to the 1.3.0 milestone Oct 9, 2024
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Cryoris
  • @Qiskit/terra-core
  • @ajavadia

@alexanderivrii alexanderivrii marked this pull request as draft October 9, 2024 08:03
Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just had a brief look, but overall this looks good to me -- I'll give a detailed review later 🙂

crates/accelerate/src/synthesis/evolution/mod.rs Outdated Show resolved Hide resolved
crates/accelerate/src/synthesis/evolution/mod.rs Outdated Show resolved Hide resolved
crates/accelerate/src/synthesis/evolution/mod.rs Outdated Show resolved Hide resolved
crates/accelerate/src/synthesis/evolution/mod.rs Outdated Show resolved Hide resolved
crates/accelerate/src/synthesis/permutation/mod.rs Outdated Show resolved Hide resolved
qiskit/synthesis/evolution/__init__.py Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Oct 12, 2024

Pull Request Test Coverage Report for Build 11722744591

Details

  • 226 of 278 (81.29%) changed or added relevant lines in 9 files are covered.
  • 16 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.006%) to 88.794%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/transpiler/passes/synthesis/hls_plugins.py 16 20 80.0%
crates/accelerate/src/synthesis/clifford/utils.rs 2 26 7.69%
crates/accelerate/src/synthesis/evolution/pauli_network.rs 161 185 87.03%
Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/two_qubit_decompose.rs 1 92.12%
crates/qasm2/src/expr.rs 1 94.02%
crates/qasm2/src/lex.rs 2 92.23%
crates/qasm2/src/parse.rs 12 97.15%
Totals Coverage Status
Change from base Build 11719787153: -0.006%
Covered Lines: 78038
Relevant Lines: 87887

💛 - Coveralls

@raynelfss raynelfss linked an issue Oct 15, 2024 that may be closed by this pull request
@ShellyGarion ShellyGarion self-requested a review November 5, 2024 15:13
ShellyGarion
ShellyGarion previously approved these changes Nov 5, 2024
Copy link
Member

@ShellyGarion ShellyGarion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks!

@ShellyGarion ShellyGarion added the Changelog: New Feature Include in the "Added" section of the changelog label Nov 5, 2024
Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good to me! I've left a bunch of comments but they are all very small 🙂

crates/accelerate/src/synthesis/evolution/mod.rs Outdated Show resolved Hide resolved
crates/accelerate/src/synthesis/evolution/mod.rs Outdated Show resolved Hide resolved
crates/accelerate/src/synthesis/evolution/mod.rs Outdated Show resolved Hide resolved
qiskit/transpiler/passes/synthesis/hls_plugins.py Outdated Show resolved Hide resolved
test/python/transpiler/test_high_level_synthesis.py Outdated Show resolved Hide resolved
test/python/transpiler/test_high_level_synthesis.py Outdated Show resolved Hide resolved
@alexanderivrii
Copy link
Contributor Author

Thanks @Cryoris for a thorough review! I think I have addressed all of your review comments (and in a few cases explained why I don't want to address it). To keep track of your comments, I was marking them as resolved as I was going through them, so you will probably want to unresolve them to see if a deeper discussion is required.

Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks for the updates!

@raynelfss raynelfss added this pull request to the merge queue Nov 7, 2024
Merged via the queue into Qiskit:main with commit 58997a5 Nov 7, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog priority: high synthesis
Projects
Status: done
Development

Successfully merging this pull request may close these issues.

Add PauliEvolutionGate synthesis plugin using rustiq
7 participants