1 from qiskit
import QuantumCircuit
2 from squander.partitioning.tools
import qiskit_to_squander_name
8 from pathlib
import Path
11 SUPPORTED_GATES = {x
for n
in dir(gate)
for x
in (getattr(gate, n),)
if not n.startswith(
"_")
and issubclass(x, gate.Gate)
and n !=
"Gate"}
12 SUPPORTED_GATES_NAMES = {n
for n
in dir(gate)
if not n.startswith(
"_")
and issubclass(getattr(gate, n), gate.Gate)
and n !=
"Gate"}
16 Downloads GitHub repositories as zip archives, extracts them into a temporary 17 directory, and returns the list of all .qasm file paths found, along with 18 the temp folder path (for later cleanup). 21 repo_urls (list[str]): List of GitHub repository URLs. 24 (list[str], str): List of QASM file paths and the temp directory path. 26 temp_dir = tempfile.mkdtemp(prefix=
"repos_")
31 parts = url.rstrip(
"/").replace(
".git",
"").
split(
"/")
34 owner, repo = parts[-2], parts[-1]
37 zip_url = f
"https://github.com/{owner}/{repo}/archive/refs/heads/master.zip" 39 zip_path = os.path.join(temp_dir, f
"{repo}.zip")
42 r = requests.get(zip_url, stream=
True)
43 if r.status_code != 200:
44 raise RuntimeError(f
"Failed to download {zip_url}: HTTP {r.status_code}")
45 with open(zip_path,
"wb")
as f:
46 for chunk
in r.iter_content(chunk_size=8192):
50 extract_path = os.path.join(temp_dir, repo)
51 with zipfile.ZipFile(zip_path,
"r") as zf: 52 zf.extractall(extract_path) 55 for path
in Path(extract_path).rglob(
"*.qasm"):
56 qasm_files.append(str(path.resolve()))
58 return qasm_files, temp_dir
63 Deletes the temporary repository folder created by download_and_collect_qasm. 65 shutil.rmtree(temp_dir, ignore_errors=
True)
70 for repo
in [
"https://github.com/iic-jku/ibm_qx_mapping",
"https://github.com/Veri-Q/Benchmark",
"https://github.com/pnnl/QASMBench",
"https://github.com/QML-Group/qbench"]:
73 bad_files, missing_gates = [], {}
76 qc = QuantumCircuit.from_qasm_file(filename)
77 except Exception
as e:
78 bad_files.append(filename)
82 if not qc_gates_names.issubset(SUPPORTED_GATES_NAMES):
83 for x
in qc_gates_names-SUPPORTED_GATES_NAMES:
84 if not x
in missing_gates: missing_gates[x] = 0
87 print(repo,
"Missing gates:", missing_gates)
90 if __name__ ==
"__main__":
def cleanup_repo(temp_dir)
def download_and_collect_qasm(repo_urls)
def squander_gate_support_check()