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

Extends SetLayout to take a list #10344

Merged
merged 13 commits into from
Jul 14, 2023
Merged

Extends SetLayout to take a list #10344

merged 13 commits into from
Jul 14, 2023

Conversation

1ucian0
Copy link
Member

@1ucian0 1ucian0 commented Jun 26, 2023

Fixes #8060

Extends SetLayout to take a list and a dictionary (agreed with @ajavadia to leave dict out for now).

from qiskit.transpiler import CouplingMap
from qiskit.transpiler.passmanager import PassManager
from qiskit.transpiler.passes import SetLayout, ApplyLayout, FullAncillaAllocation
from qiskit import QuantumCircuit, QuantumRegister

qr = QuantumRegister(6, "q")
circuit = QuantumCircuit(qr)
circuit.h(qr)
circuit.measure_all()

pass_manager = PassManager()
pass_manager.append(SetLayout([0, 1, 3, 5, 2, 6]))
pass_manager.append(FullAncillaAllocation(CouplingMap.from_line(7)))
pass_manager.append(ApplyLayout())
print(pass_manager.run(circuit))
               ┌───┐ ░ ┌─┐
      q_0 -> 0 ┤ H ├─░─┤M├───────────────
               ├───┤ ░ └╥┘┌─┐
      q_1 -> 1 ┤ H ├─░──╫─┤M├────────────
               ├───┤ ░  ║ └╥┘      ┌─┐
      q_4 -> 2 ┤ H ├─░──╫──╫───────┤M├───
               ├───┤ ░  ║  ║ ┌─┐   └╥┘
      q_2 -> 3 ┤ H ├─░──╫──╫─┤M├────╫────
               └───┘ ░  ║  ║ └╥┘    ║
ancilla_0 -> 4 ─────────╫──╫──╫─────╫────
               ┌───┐ ░  ║  ║  ║ ┌─┐ ║
      q_3 -> 5 ┤ H ├─░──╫──╫──╫─┤M├─╫────
               ├───┤ ░  ║  ║  ║ └╥┘ ║ ┌─┐
      q_5 -> 6 ┤ H ├─░──╫──╫──╫──╫──╫─┤M├
               └───┘ ░  ║  ║  ║  ║  ║ └╥┘
       meas: 6/═════════╩══╩══╩══╩══╩══╩═
                        0  1  2  3  4  5

@coveralls
Copy link

coveralls commented Jun 26, 2023

Pull Request Test Coverage Report for Build 5547570660

  • 10 of 11 (90.91%) changed or added relevant lines in 1 file are covered.
  • 342 unchanged lines in 19 files lost coverage.
  • Overall coverage increased (+0.05%) to 86.018%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/transpiler/passes/layout/set_layout.py 10 11 90.91%
Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/vf2_layout.rs 1 94.74%
qiskit/qasm/init.py 1 80.0%
qiskit/circuit/quantumcircuitdata.py 2 86.36%
qiskit/qasm/pygments/init.py 3 0%
crates/qasm2/src/lex.rs 4 91.65%
crates/accelerate/src/sabre_swap/layer.rs 5 96.64%
qiskit/circuit/bit.py 5 90.0%
crates/qasm2/src/parse.rs 6 97.11%
qiskit/algorithms/gradients/utils.py 6 95.11%
qiskit/execute_function.py 6 87.5%
Totals Coverage Status
Change from base Build 5451491224: 0.05%
Covered Lines: 71914
Relevant Lines: 83603

💛 - Coveralls

@1ucian0 1ucian0 changed the title take a list Extends SetLayout to take a list/dictionary Jun 26, 2023
@1ucian0 1ucian0 changed the title Extends SetLayout to take a list/dictionary Extends SetLayout to take a list Jul 3, 2023
@1ucian0 1ucian0 marked this pull request as ready for review July 3, 2023 19:57
@1ucian0 1ucian0 requested a review from a team as a code owner July 3, 2023 19:57
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

@1ucian0 1ucian0 added this to the 0.25.0 milestone Jul 3, 2023
@mtreinish mtreinish self-assigned this Jul 10, 2023
mtreinish
mtreinish previously approved these changes Jul 13, 2023
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, it's a straightforward change and matches what I did in #10291 to support simplifying the transpile() function: https://github.com/Qiskit/qiskit-terra/pull/10291/files#diff-774ea18ebe906b988e28b1f136d500044afd89228253ef99bfa27af3fc401e6a (I'll rebase #10291 to just use this)

qiskit/transpiler/passes/layout/set_layout.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creating Layout from a list of [int] or a map of {int: int}
4 participants