Skip to content

Commit

Permalink
Refactor test to not use deprecated CXDirection (Qiskit#9877)
Browse files Browse the repository at this point in the history
* Minimal repo for decorators breaking Pass Manager drawing

* Refactor test to not use CXDirection

* Get rid of maxDiff because of Pylint
  • Loading branch information
Eric-Arellano authored and ElePT committed Apr 5, 2023
1 parent 4369a11 commit 7dc9e44
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
10 changes: 6 additions & 4 deletions test/python/visualization/references/pass_manager_standard.dot
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,20 @@ subgraph cluster_20 {
fontname=helvetica;
label="[7] ";
labeljust=l;
21 [color=blue, fontname=helvetica, label=CXDirection, shape=rectangle];
21 [color=blue, fontname=helvetica, label=GateDirection, shape=rectangle];
22 [color=black, fontname=helvetica, fontsize=10, label=coupling_map, shape=ellipse, style=solid];
22 -> 21;
23 [color=black, fontname=helvetica, fontsize=10, label=target, shape=ellipse, style=dashed];
23 -> 21;
19 -> 21;
}

subgraph cluster_23 {
subgraph cluster_24 {
fontname=helvetica;
label="[8] ";
labeljust=l;
24 [color=blue, fontname=helvetica, label=RemoveResetInZeroState, shape=rectangle];
21 -> 24;
25 [color=blue, fontname=helvetica, label=RemoveResetInZeroState, shape=rectangle];
21 -> 25;
}

}
10 changes: 6 additions & 4 deletions test/python/visualization/references/pass_manager_style.dot
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,20 @@ subgraph cluster_20 {
fontname=helvetica;
label="[7] ";
labeljust=l;
21 [color=blue, fontname=helvetica, label=CXDirection, shape=rectangle];
21 [color=blue, fontname=helvetica, label=GateDirection, shape=rectangle];
22 [color=black, fontname=helvetica, fontsize=10, label=coupling_map, shape=ellipse, style=solid];
22 -> 21;
23 [color=black, fontname=helvetica, fontsize=10, label=target, shape=ellipse, style=dashed];
23 -> 21;
19 -> 21;
}

subgraph cluster_23 {
subgraph cluster_24 {
fontname=helvetica;
label="[8] ";
labeljust=l;
24 [color=grey, fontname=helvetica, label=RemoveResetInZeroState, shape=rectangle];
21 -> 24;
25 [color=grey, fontname=helvetica, label=RemoveResetInZeroState, shape=rectangle];
21 -> 25;
}

}
19 changes: 12 additions & 7 deletions test/python/visualization/test_pass_manager_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
from qiskit.transpiler import CouplingMap, Layout
from qiskit.transpiler.passmanager import PassManager
from qiskit import QuantumRegister
from qiskit.transpiler.passes import Unroller
from qiskit.transpiler.passes import GateDirection, Unroller
from qiskit.transpiler.passes import CheckMap
from qiskit.transpiler.passes import CXDirection
from qiskit.transpiler.passes import SetLayout
from qiskit.transpiler.passes import TrivialLayout
from qiskit.transpiler.passes import BarrierBeforeFinalMeasurements
Expand Down Expand Up @@ -52,7 +51,7 @@ def setUp(self):
self.pass_manager.append(Unroller(basis_gates))
self.pass_manager.append(CheckMap(coupling_map))
self.pass_manager.append(BarrierBeforeFinalMeasurements(), do_while=lambda x: False)
self.pass_manager.append(CXDirection(coupling_map))
self.pass_manager.append(GateDirection(coupling_map))
self.pass_manager.append(RemoveResetInZeroState())

@unittest.skipIf(not optionals.HAS_GRAPHVIZ, "Graphviz not installed.")
Expand All @@ -61,8 +60,12 @@ def test_pass_manager_drawer_basic(self):
filename = "current_standard.dot"
self.pass_manager.draw(filename=filename, raw=True)

self.assertFilesAreEqual(filename, path_to_diagram_reference("pass_manager_standard.dot"))
os.remove(filename)
try:
self.assertFilesAreEqual(
filename, path_to_diagram_reference("pass_manager_standard.dot")
)
finally:
os.remove(filename)

@unittest.skipIf(not optionals.HAS_GRAPHVIZ, "Graphviz not installed.")
def test_pass_manager_drawer_style(self):
Expand All @@ -78,8 +81,10 @@ def test_pass_manager_drawer_style(self):
filename = "current_style.dot"
self.pass_manager.draw(filename=filename, style=style, raw=True)

self.assertFilesAreEqual(filename, path_to_diagram_reference("pass_manager_style.dot"))
os.remove(filename)
try:
self.assertFilesAreEqual(filename, path_to_diagram_reference("pass_manager_style.dot"))
finally:
os.remove(filename)


if __name__ == "__main__":
Expand Down

0 comments on commit 7dc9e44

Please sign in to comment.