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

Update GateDirection and checker for control flow #8822

Merged
merged 3 commits into from
Oct 1, 2022

Conversation

jakelishman
Copy link
Member

Summary

These are largely straightforwards, but since each pass has essentially two separate versions, it became simpler to refactor them out when doing the recursion, rather than using internal closures. As part of the refactor, we also swap to using Target.instruction_supported to check for validity - this method was added after the passes were originally made target-aware.

Details and comments

These are largely straightforwards, but since each pass has essentially
two separate versions, it became simpler to refactor them out when doing
the recursion, rather than using internal closures.  As part of the
refactor, we also swap to using `Target.instruction_supported` to check
for validity - this method was added after the passes were originally
made target-aware.
@jakelishman jakelishman added Changelog: New Feature Include in the "Added" section of the changelog Changelog: Bugfix Include in the "Fixed" section of the changelog labels Sep 30, 2022
@jakelishman jakelishman requested a review from a team as a code owner September 30, 2022 20:23
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core

@coveralls
Copy link

coveralls commented Sep 30, 2022

Pull Request Test Coverage Report for Build 3161855539

  • 74 of 77 (96.1%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.04%) to 84.685%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/transpiler/passes/utils/gate_direction.py 48 51 94.12%
Totals Coverage Status
Change from base Build 3161387625: 0.04%
Covered Lines: 61507
Relevant Lines: 72630

💛 - Coveralls

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.

Overall this LGTM, I really like the new code structure it's much easier to follow, especially in gate_direction. The only thing that sticks out are the inline comments I left on check_gate_direction. But the same comment applies to gate_direction. Basically we're making these passes operate in O(2n) when we can do it in O(n). I think after we combine the loops this should be good to go.

qiskit/transpiler/passes/utils/check_gate_direction.py Outdated Show resolved Hide resolved
qiskit/transpiler/passes/utils/check_gate_direction.py Outdated Show resolved Hide resolved
Comment on lines +153 to +165
elif node.name == "rzx":
if self.target.instruction_supported(
qargs=qargs, operation_class=RZXGate, parameters=node.op.params
):
continue
if self.target.instruction_supported(
qargs=swapped, operation_class=RZXGate, parameters=node.op.params
):
dag.substitute_node_with_dag(node, self._rzx_dag(*node.op.params))
else:
raise TranspilerError(
f"The circuit requires a connection between physical qubits {qargs}"
f" for {node.name}"
Copy link
Member

Choose a reason for hiding this comment

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

Ooh, this is nice, thanks for fixing the TODO there! @ajavadia will be glad to see this because it pushes us closer to being able to enable https://arxiv.org/abs/2111.02535 by default in transpile() if the backend supports tuned variants of rzx.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yeah - since Target.instruction_supported got added, the todo became very easy to action. I think we're probably leaving some efficiency on the table here when it's called in a loop with operation_class set, but that's for another day most likely.

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.

LGTM, thanks for the quick update

@mergify mergify bot merged commit 2a8cf79 into Qiskit:main Oct 1, 2022
@jakelishman jakelishman deleted the control-flow-direction branch October 3, 2022 20:02
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 Changelog: New Feature Include in the "Added" section of the changelog priority: high
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants