forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added sabre v0_20 and started checking pm
- Loading branch information
1 parent
c0241a4
commit a413fb4
Showing
4 changed files
with
620 additions
and
2 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
workspace_experiments/experiment_setup/coupling_maps/coupling_maps_files.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
from qiskit.transpiler import CouplingMap | ||
import os | ||
import ast | ||
|
||
def file_to_coupling_map(file_path): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from qiskit.transpiler import PassManager | ||
from qiskit.transpiler.passes import ApplyLayout, FullAncillaAllocation, \ | ||
EnlargeWithAncilla, TrivialLayout, SetLayout | ||
from qiskit.transpiler.passes.layout.sabre_layout import SabreLayout | ||
import time | ||
import numpy as np | ||
import pandas as pd | ||
|
||
# routing passes | ||
from qiskit.transpiler.passes.routing.sabre_swap import SabreSwap as Sabre | ||
from sabre_mods.sabre_swap_v0_20_ import SabreSwap as SabreSwap_v0_20 | ||
|
||
def build_rp(rp_str, cm, seed=42, look=0, beam=0, num_iter=1, crit=1): | ||
""" Build a routing pass based on the routing pass string rp_str. | ||
Args: | ||
rp_str (str): routing pass string | ||
cm (list): coupling map | ||
seed (int): seed for the routing pass | ||
look (int): look ahead (only for Sabre Look) | ||
beam (int): beam width (only for Sabre Look and Sabre Dive) | ||
num_iter (int): number of iterations (only for Sabre Dive) | ||
crit (int): criteral path weight (only for Sabre Crit) | ||
""" | ||
|
||
rp = None | ||
print(f"Using seed {seed} for routing pass.") | ||
|
||
if rp_str == "sabre": | ||
print(f" Building Sabre routing pass") | ||
rp = Sabre(cm, seed=seed) | ||
elif rp_str == "sabre_v0_20_": | ||
print(f" Building Sabre v0.20 routing pass") | ||
rp = SabreSwap_v0_20(cm, seed=seed) | ||
elif rp_str == "sabre_v0_20_extended": | ||
print(f" Building Sabre v0.20 extended routing pass") | ||
rp = SabreSwap_v0_20(cm, seed=seed, heuristic="lookahead") | ||
else: | ||
raise ValueError(f"Unknown routing pass {rp_str}") | ||
|
||
return rp | ||
|
||
def build_lp(lp_str, cm, rp, seed=42): | ||
""" Build a layout pass based on the layout pass string lp_str. | ||
Args: | ||
lp_str (str): layout pass string | ||
cm (list): coupling map | ||
rp (obj): routing pass | ||
seed (int): seed for the layout pass | ||
""" | ||
|
||
lp = None | ||
print(f"Using seed {seed} for layout pass.") | ||
|
||
|
||
if lp_str == "sabre_layout": | ||
print(f" Building Sabre layout pass") | ||
lp = SabreLayout(cm, rp, seed=seed) | ||
elif lp_str == "fast_layout": | ||
print(f" Building Fast layout pass") | ||
lp = SabreLayout(cm, Sabre(cm, seed=seed), seed=seed) | ||
elif lp_str == "trivial_layout": | ||
print(f" Building Trivial layout pass") | ||
lp = TrivialLayout() | ||
else: | ||
raise ValueError(f"Unknown layout pass {lp_str}") | ||
|
||
|
||
return lp | ||
|
||
def build_pm(rp, lp, cm): | ||
""" Build a pass manager based on the routing and layout passes. | ||
Args: | ||
rp (obj): routing pass | ||
lp (obj): layout pass | ||
cm (list): coupling map | ||
""" | ||
|
||
return PassManager([ | ||
lp, | ||
FullAncillaAllocation(cm), | ||
EnlargeWithAncilla(), | ||
ApplyLayout(), | ||
rp | ||
]) |
Oops, something went wrong.