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

drawer enhancement: show layout info if circuit.layout exists #2739

Closed
ajavadia opened this issue Jul 4, 2019 · 1 comment · Fixed by #2781
Closed

drawer enhancement: show layout info if circuit.layout exists #2739

ajavadia opened this issue Jul 4, 2019 · 1 comment · Fixed by #2781
Assignees
Labels
status: pending PR It has one or more PRs pending to solve this issue
Milestone

Comments

@ajavadia
Copy link
Member

ajavadia commented Jul 4, 2019

With some recent changes, a circuit that gets transpiled onto a coupling_map now will contain information about which qubits of the original (virtual) circuit correspond to which qubits of the final (physical) circuit. For example:

from qiskit.circuit import QuantumRegister, QuantumCircuit
from qiskit.compiler import transpile
from qiskit.test.mock import FakeTokyo
tokyo = FakeTokyo()

v = QuantumRegister(3)
circuit = QuantumCircuit(v)
circuit.h(v[0])
circuit.cx(v[0], v[1])
circuit.cx(v[0], v[2])

# do a GHZ state preparation on qubits 3, 7, 11, using ancillas for swap
new_circuit = transpile(circuit, tokyo, initial_layout=[3, 7, 11])

image

image

This request is to show the layout information next to each qubit. This can be found via:

new_circuit.layout
Layout({
3: Qubit(QuantumRegister(3, 'v'), 0),
7: Qubit(QuantumRegister(3, 'v'), 1),
11: Qubit(QuantumRegister(3, 'v'), 2),
0: Qubit(QuantumRegister(17, 'ancilla'), 0),
1: Qubit(QuantumRegister(17, 'ancilla'), 1),
2: Qubit(QuantumRegister(17, 'ancilla'), 2),
4: Qubit(QuantumRegister(17, 'ancilla'), 3),
5: Qubit(QuantumRegister(17, 'ancilla'), 4),
6: Qubit(QuantumRegister(17, 'ancilla'), 5),
8: Qubit(QuantumRegister(17, 'ancilla'), 6),
9: Qubit(QuantumRegister(17, 'ancilla'), 7),
10: Qubit(QuantumRegister(17, 'ancilla'), 8),
12: Qubit(QuantumRegister(17, 'ancilla'), 9),
13: Qubit(QuantumRegister(17, 'ancilla'), 10),
14: Qubit(QuantumRegister(17, 'ancilla'), 11),
15: Qubit(QuantumRegister(17, 'ancilla'), 12),
16: Qubit(QuantumRegister(17, 'ancilla'), 13),
17: Qubit(QuantumRegister(17, 'ancilla'), 14),
18: Qubit(QuantumRegister(17, 'ancilla'), 15),
19: Qubit(QuantumRegister(17, 'ancilla'), 16)
})

So I envision something like:

q0 (ancilla0) ------------
q1 (ancilla1) ------------
q2 (ancilla2) ------------
q3 (v0)       ------------
q4 (ancilla3) ------------
q5 (ancilla4) ------------
q6 (ancilla5) ------------
q7 (v1)       ------------
.
.

Note: the fact that we have q0, q1, .. q19 is an artifact of not being able to create register-less circuits currently. Eventually this should just be shown as physical qubits 0, 1, ..., 19.

@ajavadia ajavadia added this to To do in Visualization and Juypter Tools via automation Jul 4, 2019
@ajavadia ajavadia added this to the 0.9 milestone Jul 4, 2019
@nonhermitian
Copy link
Contributor

The example Layout is the reverse mapping, but other than that this is good.

@1ucian0 1ucian0 self-assigned this Jul 11, 2019
@1ucian0 1ucian0 added the status: pending PR It has one or more PRs pending to solve this issue label Jul 12, 2019
Visualization and Juypter Tools automation moved this from To do to Done Aug 13, 2019
mtreinish pushed a commit that referenced this issue Aug 13, 2019
Fixes #2739

This PR adds layout support for all the drawers, with the option with_layout=bool.

* from unittest.mock import patch

* .

* util

* options

* docstring

* text

* done with text

* more tests

* remove utils function

* mpl

* remove namedtuple

* mpl

* latex

* lint

* flip order

* space in latex

* utils

* lint

* layout -> _layout

* Revert "layout -> _layout"

This reverts commit 576c243.

* layout -> _layout

* merge

* CHANGELOG

* flip layout

* default is True, so no need to have arg

* new test

* changelog

* fixing text

* adjust tests

* fixing latex

* fix mpl

* add test

* name classical register

* __str__

* single_line

* optimization_level

* print result

* avoid paging
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this issue Aug 5, 2020
Fixes Qiskit#2739

This PR adds layout support for all the drawers, with the option with_layout=bool.

* from unittest.mock import patch

* .

* util

* options

* docstring

* text

* done with text

* more tests

* remove utils function

* mpl

* remove namedtuple

* mpl

* latex

* lint

* flip order

* space in latex

* utils

* lint

* layout -> _layout

* Revert "layout -> _layout"

This reverts commit 576c243.

* layout -> _layout

* merge

* CHANGELOG

* flip layout

* default is True, so no need to have arg

* new test

* changelog

* fixing text

* adjust tests

* fixing latex

* fix mpl

* add test

* name classical register

* __str__

* single_line

* optimization_level

* print result

* avoid paging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pending PR It has one or more PRs pending to solve this issue
Development

Successfully merging a pull request may close this issue.

3 participants