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 reverse permutation for LNN connectivity #12181

Merged
merged 7 commits into from
Apr 29, 2024

Conversation

ShellyGarion
Copy link
Member

Summary

See #9036

Add reverse permutations in depth 2n+2 based on Section 5 of Kutin et al. (https://arxiv.org/abs/quant-ph/0701194)

Details and comments

@ShellyGarion ShellyGarion added Changelog: New Feature Include in the "Added" section of the changelog synthesis labels Apr 15, 2024
@ShellyGarion ShellyGarion added this to the 1.1.0 milestone Apr 15, 2024
@ShellyGarion ShellyGarion requested review from alexanderivrii and a team as code owners April 15, 2024 11:06
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

@ShellyGarion ShellyGarion linked an issue Apr 15, 2024 that may be closed by this pull request
8 tasks
@coveralls
Copy link

coveralls commented Apr 15, 2024

Pull Request Test Coverage Report for Build 8865321376

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

  • 28 of 28 (100.0%) changed or added relevant lines in 4 files are covered.
  • 906 unchanged lines in 76 files lost coverage.
  • Overall coverage increased (+0.08%) to 89.422%

Files with Coverage Reduction New Missed Lines %
qiskit/circuit/library/standard_gates/r.py 1 97.62%
qiskit/transpiler/target.py 1 93.74%
crates/qasm2/src/expr.rs 1 94.03%
qiskit/primitives/backend_sampler_v2.py 1 99.21%
qiskit/circuit/library/generalized_gates/permutation.py 1 93.1%
qiskit/primitives/containers/data_bin.py 1 97.92%
qiskit/circuit/library/standard_gates/rxx.py 1 97.44%
qiskit/circuit/library/standard_gates/u2.py 1 96.67%
qiskit/circuit/library/standard_gates/rzx.py 1 97.44%
qiskit/quantum_info/operators/operator.py 1 94.94%
Totals Coverage Status
Change from base Build 8686173229: 0.08%
Covered Lines: 60924
Relevant Lines: 68131

💛 - Coveralls

Copy link
Contributor

@henryzou50 henryzou50 left a comment

Choose a reason for hiding this comment

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

Overall LGTM, but for some improvement in efficiency for synth_qft_line, we could directly append the circuit rather than using compose, and for the tests we could add some tests for edge cases / invalid input to help ensure robustness of the new feature.

Comment on lines 68 to 69
qc_rev = synth_permutation_reverse_lnn_kms(num_qubits)
qc = qc.compose(qc_rev)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks good, but I think we can do this more efficiently. While the current implementation using compose ensures correctness, it might not be the most efficient in terms of performance and memory usage, especially for larger circuits.

Instead of composing two quantum circuits, we could consider enhancing efficiency by adding a function that directly appends the reverse permutation LNN to an existing circuit. This approach would modify the circuit in place, avoiding the overhead associated with creating and composing a new circuit instance. Here's a conceptual sketch of how this could be implemented:

def append_reverse_permutation_lnn_kms(qc: QuantumCircuit, num_qubits: int) -> None:
    for _ in range((num_qubits + 1) // 2):
        _append_cx_stage1(qc, num_qubits)
        _append_cx_stage2(qc, num_qubits)
    if (num_qubits % 2) == 0:
        _append_cx_stage1(qc, num_qubits)

Copy link
Member Author

Choose a reason for hiding this comment

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

that's a good suggestion, I added it as a helper function.

Comment on lines +19 to +34
def _append_cx_stage1(qc, n):
"""A single layer of CX gates."""
for i in range(n // 2):
qc.cx(2 * i, 2 * i + 1)
for i in range((n + 1) // 2 - 1):
qc.cx(2 * i + 2, 2 * i + 1)
return qc


def _append_cx_stage2(qc, n):
"""A single layer of CX gates."""
for i in range(n // 2):
qc.cx(2 * i + 1, 2 * i)
for i in range((n + 1) // 2 - 1):
qc.cx(2 * i + 1, 2 * i + 2)
return qc
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed _append_cx_stage1 and _append_cx_stage2 functions were moved from qiskit/synthesis/linear_phase/cz_depth_lnn.py to qiskit/synthesis/permutation/permutation_reverse_lnn.py. Could you share the reasoning behind this change?

While I understand these are private functions and the move does not impact their functionality, I am curious if the new location makes more sense and better aligns with their specific use.

Copy link
Member Author

Choose a reason for hiding this comment

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

These functions are helper functions to construct a reverse permutation, and this is the reason that they have been moved. CZ circuit synthesis for LNN is basically constructing a reverse permutation with phase gates in between.

Comment on lines 115 to 116
@data(4, 5, 10, 15, 20)
def test_synth_permutation_reverse_lnn_kms(self, num_qubits):
Copy link
Contributor

Choose a reason for hiding this comment

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

Great work on the implementation and testing. The current tests effectively assess the basic functionality and correct usage scenarios. However, I suggest adding tests that focus on:

  • Edge Cases: Like scenarios with 0 or 1 qubits.
  • Invalid Input: To ensure the system handles invalid inputs as expected.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added test cases for 1,2 and 3 qubits.

Copy link
Contributor

@henryzou50 henryzou50 left a comment

Choose a reason for hiding this comment

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

LGTM

@henryzou50 henryzou50 added this pull request to the merge queue Apr 29, 2024
Merged via the queue into Qiskit:main with commit 8194a68 Apr 29, 2024
13 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 synthesis
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Synthesis algorithms for LNN connectivity
4 participants