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

Ensure translation stage always outputs ISA circuits #13792

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

jakelishman
Copy link
Member

Summary

This shifts the responsibility of the translation stage slightly to always output ISA circuits. It previously was not 100% required that they did this, at least implicitly because Qiskit's built-in plugins didn't always respect 2q direction.

The builtin translation plugins now always respect 2q direction, which removes the need for the pre_optimization implicit stage, freeing it up for better user customisation.

This (in theory) shouldn't have runtime impacts because the optimisation loop was already having to do this afterwards anyway. For potential plugins that do respect gate direction (like the upcoming BasisConstructor), it can be a speedup in the default pipeline, since they won't need to run the gate-direction check any more.

Details and comments

Built on top of #13620, since it will need to change documentation in that PR.

Fix #13787.

@jakelishman jakelishman added Changelog: Deprecation Include in "Deprecated" section of changelog Changelog: API Change Include in the "Changed" section of the changelog mod: transpiler Issues and PRs related to Transpiler labels Feb 5, 2025
@jakelishman jakelishman added this to the 2.0.0 milestone Feb 5, 2025
@jakelishman jakelishman requested a review from a team as a code owner February 5, 2025 18:22
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

@jakelishman jakelishman added the on hold Can not fix yet label Feb 5, 2025
@coveralls
Copy link

coveralls commented Feb 5, 2025

Pull Request Test Coverage Report for Build 13168271554

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 10 of 10 (100.0%) changed or added relevant lines in 1 file are covered.
  • 15 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.005%) to 88.646%

Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/euler_one_qubit_decomposer.rs 1 91.5%
crates/qasm2/src/lex.rs 6 92.23%
qiskit/transpiler/preset_passmanagers/common.py 8 85.94%
Totals Coverage Status
Change from base Build 13165103262: -0.005%
Covered Lines: 79222
Relevant Lines: 89369

💛 - Coveralls

This shifts the responsibility of the `translation` stage slightly to
always output ISA circuits.  It previously was not 100% required that
they did this, at least implicitly because Qiskit's built-in plugins
didn't always respect 2q direction.

The builtin translation plugins now always respect 2q direction, which
removes the need for the `pre_optimization` implicit stage, freeing it
up for better user customisation.

This (in theory) shouldn't have runtime impacts because the optimisation
loop was already having to do this afterwards anyway.  For potential
plugins that _do_ respect gate direction (like the upcoming
`BasisConstructor`), it can be a speedup in the default pipeline, since
they won't need to run the gate-direction check any more.
@jakelishman jakelishman force-pushed the translation-stage-direction branch from 0caf0c9 to 92f30cd Compare February 5, 2025 23:08
@jakelishman jakelishman removed the on hold Can not fix yet label Feb 5, 2025
@jakelishman
Copy link
Member Author

jakelishman commented Feb 5, 2025

Now rebased over main. I'll run the benchmark suite overnight.

@jakelishman
Copy link
Member Author

I ran the full benchmark suite, and there (as mostly expected) doesn't seem to be much change from this. There's a small positive improvement in a couple of places of runtime, though I'm not convinced it wasn't just fluctuations on my machine. There's depth improvements in QUEKO, perhaps because in cases where the optimisation loop is entered twice, there's a bit more information available to it? Or maybe it's just because there's the knock-on effect of some changes to the randomisation.

| Change   | Before [4d2265f6] <dag-module^2>   | After [92f30cdf] <translation-stage-direction>   |   Ratio | Benchmark (Parameter)                                                    |
|----------|------------------------------------|--------------------------------------------------|---------|--------------------------------------------------------------------------|
| -        | 1.24±0.04ms                        | 1.07±0.04ms                                      |    0.86 | quantum_info.CliffordDecomposeBench.time_decompose('5,10')               |
| -        | 4.53±0.4ms                         | 3.33±0.07ms                                      |    0.73 | quantum_info.SparsePauliOpBench.time_tensor(150, 100)                    |
| -        | 18.0±0.4ms                         | 13.5±0.3ms                                       |    0.75 | queko.QUEKOTranspilerBench.time_transpile_bigd(3, None)                  |
| -        | 81.9±1ms                           | 61.9±1ms                                         |    0.76 | queko.QUEKOTranspilerBench.time_transpile_bntf(0, 'sabre')               |
| -        | 138±6ms                            | 88.2±1ms                                         |    0.64 | queko.QUEKOTranspilerBench.time_transpile_bntf(0, None)                  |
| -        | 114±2ms                            | 99.8±1ms                                         |    0.87 | queko.QUEKOTranspilerBench.time_transpile_bntf(2, 'sabre')               |
| -        | 165±0.7ms                          | 123±2ms                                          |    0.74 | queko.QUEKOTranspilerBench.time_transpile_bntf(3, 'sabre')               |
| -        | 74                                 | 43                                               |    0.58 | queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(2, 'sabre') |
| -        | 74                                 | 45                                               |    0.61 | queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(2, None)    |
| -        | 74                                 | 43                                               |    0.58 | queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(3, 'sabre') |
| -        | 74                                 | 45                                               |    0.61 | queko.QUEKOTranspilerBench.track_depth_bigd_optimal_depth_45(3, None)    |
| -        | 255                                | 216                                              |    0.85 | queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(2, 'sabre') |
| -        | 45                                 | 30                                               |    0.67 | queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(2, None)    |
| -        | 45                                 | 30                                               |    0.67 | queko.QUEKOTranspilerBench.track_depth_bntf_optimal_depth_25(3, None)    |
| -        | 28.7±1ms                           | 22.5±0.7ms                                       |    0.79 | random_circuit_hex.BenchRandomCircuitHex.time_ibmq_backend_transpile(10) |
| -        | 39.3±2ms                           | 28.7±1ms                                         |    0.73 | random_circuit_hex.BenchRandomCircuitHex.time_ibmq_backend_transpile(12) |
| -        | 20.4±0.8ms                         | 17.3±0.6ms                                       |    0.85 | random_circuit_hex.BenchRandomCircuitHex.time_ibmq_backend_transpile(8)  |

Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

I am absolutely in favor of this change, I think it's much cleaner and flexible, and the changes look good! I just left a question for my own understanding of the passes.

Comment on lines +560 to +561
# run a little bit of fix up on them. `GateDirection` doesn't guarantee that 1q gates are
# ISA safe after it runs, so we need another run too.
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to make sure I understood this sentence, is it GateDirection or CheckGateDirection that doesn't guarantee that 1q gates are ISA?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's GateDirection - that's the one that actually inserts gates. CheckGateDirection just says whether or not we need to run GateDirection and the subsequent fixer.

Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

LGTM!

@jakelishman jakelishman added this pull request to the merge queue Feb 6, 2025
Merged via the queue into Qiskit:main with commit cd6e020 Feb 6, 2025
17 checks passed
@jakelishman jakelishman deleted the translation-stage-direction branch February 6, 2025 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: API Change Include in the "Changed" section of the changelog Changelog: Deprecation Include in "Deprecated" section of changelog mod: transpiler Issues and PRs related to Transpiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move GateDirection responsibility into translation preset stage
4 participants