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

fix issue/12311 with fractional gate in basis #12511

Merged
merged 7 commits into from
Jul 24, 2024

Conversation

ewinston
Copy link
Contributor

@ewinston ewinston commented Jun 5, 2024

Summary

This fixes an issue where an exception would be raised if transpiling a unitary gate to a backend with an RZZGate in its basis however transpiling with only basis_gates specified would transpile fine.

fixes #12311

Details and comments

In this case, where RZZ is the only entangling gate in the basis, decomposition of a 2q unitary gate wouldn't get synthesized in the UnitarySynthesis pass but would instead be synthesized in the HighLevelSynthesis pass because this would call the instruction's _define method which calls two_qubit_cnot_decompose. A subsequent BasisTranslator pass ultimately maps the cx to the rzz basis. I'm not sure whether this indirect path to unitary synthesis is intentional.

This pr resolves the specific example posed in the issue.

@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

@coveralls
Copy link

coveralls commented Jun 5, 2024

Pull Request Test Coverage Report for Build 9381719291

Details

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • 8 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.01%) to 89.6%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 2 93.64%
crates/qasm2/src/parse.rs 6 97.61%
Totals Coverage Status
Change from base Build 9372719342: 0.01%
Covered Lines: 62374
Relevant Lines: 69614

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jun 5, 2024

Pull Request Test Coverage Report for Build 9385447583

Details

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • 8 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.009%) to 89.597%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 2 93.64%
crates/qasm2/src/parse.rs 6 97.61%
Totals Coverage Status
Change from base Build 9372719342: 0.009%
Covered Lines: 62372
Relevant Lines: 69614

💛 - Coveralls

@@ -782,15 +782,15 @@ def _replace_parameterized_gate(op):
def is_supercontrolled(gate):
try:
operator = Operator(gate)
except QiskitError:
except (QiskitError, TypeError): # TypeError: parametrized gate
Copy link
Member

Choose a reason for hiding this comment

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

What is the source of a TypeError here? Is it coming from __array__ ?

I ask because I'm wondering if this is the correct fix, if it's coming from __array__ because the gate is parameterized in the target, I'm wondering if we should instantiate it with a fixed angle instead. Basically update _replace_parameterized_gate to handle RZZ too, or instead maybe try to generalize it. A parameterized gate in the target represents that any angle value is valid input so we're free to evaluate the matrix at a fixed angle if we want.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this seems to be the cause. I assigned it as done in _replace_parameterized_gate for now. I don't love the idea of implicitly making that choice here but at least there's precedence. c45d02d

@1ucian0 1ucian0 added Changelog: Bugfix Include in the "Fixed" section of the changelog labels Jun 10, 2024
@coveralls
Copy link

coveralls commented Jul 18, 2024

Pull Request Test Coverage Report for Build 10082610521

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

  • 1 of 2 (50.0%) changed or added relevant lines in 1 file are covered.
  • 692 unchanged lines in 33 files lost coverage.
  • Overall coverage increased (+0.02%) to 89.939%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/transpiler/passes/synthesis/unitary_synthesis.py 1 2 50.0%
Files with Coverage Reduction New Missed Lines %
qiskit/circuit/library/standard_gates/swap.py 1 98.18%
qiskit/circuit/duration.py 1 70.27%
crates/accelerate/src/synthesis/permutation/utils.rs 1 99.02%
crates/qasm2/src/expr.rs 1 94.02%
qiskit/transpiler/passes/layout/sabre_pre_layout.py 1 98.88%
qiskit/circuit/random/utils.py 1 94.87%
qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_gate_router.py 1 99.12%
qiskit/transpiler/passes/scheduling/alap.py 2 96.72%
qiskit/transpiler/passes/scheduling/asap.py 2 96.92%
crates/accelerate/src/convert_2q_block_matrix.rs 2 94.0%
Totals Coverage Status
Change from base Build 9976077291: 0.02%
Covered Lines: 65988
Relevant Lines: 73370

💛 - Coveralls

@1ucian0 1ucian0 added the stable backport potential The bug might be minimal and/or import enough to be port to stable label Jul 19, 2024
@ElePT ElePT added this to the 1.2.0 milestone Jul 22, 2024
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

This LGTM, I just have a small nit in the tests for future proofing (since I just had to deal with related failures caused by it on a different PR). I'll just apply that and enqueue this for merge.

test/python/transpiler/test_basis_translator.py Outdated Show resolved Hide resolved
test/python/transpiler/test_basis_translator.py Outdated Show resolved Hide resolved
@mtreinish mtreinish enabled auto-merge July 24, 2024 19:11
@mtreinish mtreinish modified the milestones: 1.2.0, 1.1.2 Jul 24, 2024
@mtreinish mtreinish added this pull request to the merge queue Jul 24, 2024
Merged via the queue into Qiskit:main with commit aaaf107 Jul 24, 2024
15 checks passed
mergify bot pushed a commit that referenced this pull request Jul 24, 2024
* linting

* linting...relax check for 3-qubit circuit

* update test docstrings

* black update

* bind RZZ to pi/2 if Rzz(theta) in basis

* Apply suggestions from code review

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
(cherry picked from commit aaaf107)
github-merge-queue bot pushed a commit that referenced this pull request Jul 25, 2024
* linting

* linting...relax check for 3-qubit circuit

* update test docstrings

* black update

* bind RZZ to pi/2 if Rzz(theta) in basis

* Apply suggestions from code review

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
(cherry picked from commit aaaf107)

Co-authored-by: ewinston <ewinston@us.ibm.com>
mtreinish added a commit that referenced this pull request Jul 25, 2024
Procatv pushed a commit to Procatv/qiskit-terra-catherines that referenced this pull request Aug 1, 2024
* linting

* linting...relax check for 3-qubit circuit

* update test docstrings

* black update

* bind RZZ to pi/2 if Rzz(theta) in basis

* Apply suggestions from code review

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2Q gate synthesis with fractional gates
6 participants