Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ venv/
ENV/
env.bak/
venv.bak/
.asv/

# Spyder project settings
.spyderproject
Expand Down
5 changes: 2 additions & 3 deletions tests/benchmarks/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# pylint: disable=no-member,invalid-name,missing-docstring,no-name-in-module
# pylint: disable=attribute-defined-outside-init,unsubscriptable-object

"""
This module is used to test the import time of pyqasm.
"""
Expand All @@ -24,5 +21,7 @@


class PyqasmImport:
"""Test the import time of pyqasm."""

def time_pyqasm_import(self):
call((executable, "-c", "import pyqasm"))
6 changes: 3 additions & 3 deletions tests/benchmarks/openpulse.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# pylint: disable=no-member,invalid-name,missing-docstring,no-name-in-module
# pylint: disable=attribute-defined-outside-init,unsubscriptable-object

"""
This module is used to test the openpulse of pyqasm.
"""
Expand All @@ -25,8 +22,11 @@


class Openpulse:
"""Test the pyqasm openpulse functionality."""

def setup(self):
# Get benchmark file, downloading if necessary
# pylint: disable-next=attribute-defined-outside-init
self.qasm_file = get_benchmark_file("neutral_atom_gate.qasm")

def time_openpulse(self):
Expand Down
58 changes: 41 additions & 17 deletions tests/benchmarks/pyqasm_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# pylint: disable=no-member,invalid-name,missing-docstring,no-name-in-module
# pylint: disable=attribute-defined-outside-init,unsubscriptable-object
# pylint: disable=attribute-defined-outside-init

"""
This module is used to test the basic functions of pyqasm.
This module is used to test the pyqasm functions.
"""

import os
Expand All @@ -28,34 +27,59 @@


class PyqasmFunctions:
def setup(self):
# Get benchmark files, downloading if necessary
self.qasm_file = get_benchmark_file("qft_N100.qasm")
"""Test the pyqasm functions."""

# Create output file path in the same directory as input file
input_path = Path(self.qasm_file)
self.output_file = str(input_path.parent / "qft_N100_unrolled.qasm")
# Define parameters for asv
params = [["small (224 lines)", "mid (2335 lines)", "large (17460 lines)"]]
param_names = ["qasm_file"]
timeout = 600

def setup(self, file_size):
# Extract the original file size name from the parameter value
if "(224 lines)" in file_size:
file_size_key = "small"
elif "(2335 lines)" in file_size:
file_size_key = "mid"
elif "(17460 lines)" in file_size:
file_size_key = "large"
else:
file_size_key = file_size

# Define files for each size category
self.files = {
"small": "vqe_uccsd_n4.qasm", # 224 lines
"mid": "dnn_n16.qasm", # 2335 lines
"large": "qv_N029_12345.qasm", # 17460 lines
}

# Get benchmark file for the specified size
self.qasm_file = get_benchmark_file(self.files[file_size_key])
self.pyqasm_obj = load(self.qasm_file)
self.mid_qasm_file = get_benchmark_file("pea_3_pi_8.qasm")
self.mid_pyqasm_obj = load(self.mid_qasm_file)

def teardown(self):
# Create output file path for dump operations
input_path = Path(self.qasm_file)
self.output_file = str(input_path.parent / f"{file_size_key}_unrolled.qasm")

def teardown(self, _):
# Clean up the output file if it was created
if hasattr(self, "output_file") and os.path.exists(self.output_file):
try:
os.remove(self.output_file)
except OSError:
pass

def time_load(self):
def time_load(self, _):
"""Load QASM file of specified size."""
_ = load(self.qasm_file)

def time_dumps(self):
def time_dumps(self, _):
"""Serialize QASM object of specified size to string."""
_ = dumps(self.pyqasm_obj)

def time_dump(self):
def time_dump(self, _):
"""Dump QASM object of specified size to file."""
dump(self.pyqasm_obj, self.output_file)

def time_draw(self):
_ = printer.mpl_draw(self.mid_pyqasm_obj, idle_wires=True, external_draw=False)
def time_draw(self, _):
"""Draw QASM object of specified size."""
_ = printer.mpl_draw(self.pyqasm_obj, idle_wires=True, external_draw=False)
47 changes: 19 additions & 28 deletions tests/benchmarks/qasm/benchmark_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
and caching them locally to avoid storing large files in version control.
"""

# pylint: disable-all

import json
import ssl
import tempfile
Expand All @@ -43,29 +41,27 @@ def __init__(self, cache_dir: Optional[str] = None):

def get_file_path(self, filename: str) -> Path:
"""Get the path for a benchmark file, fetching from remote repository if needed."""
if filename not in self.metadata["benchmark_files"]:
raise KeyError(f"Unknown benchmark file: {filename}")

file_info = self.metadata["benchmark_files"][filename]

# Check if this is a local-only file
if file_info.get("local_only", False):
# Check local_files first
if filename in self.metadata["local_files"]:
file_path = self.cache_dir / filename
if not file_path.exists():
raise RuntimeError(
f"Local file {filename} not found. Please ensure it exists in the repository."
)
raise RuntimeError(f"Local file {filename} not found in {self.cache_dir}")
Comment thread
vinayswamik marked this conversation as resolved.
Outdated
return file_path

# For remote files, fetch and return a temporary file
return self._fetch_remote_file(filename, file_info)
# Check benchmark_files
if filename in self.metadata["benchmark_files"]:
file_info = self.metadata["benchmark_files"][filename]
# Fetch remote files
return self._fetch_remote_file(filename, file_info)

raise KeyError(f"Unknown benchmark file: {filename}")
Comment thread
vinayswamik marked this conversation as resolved.
Outdated

def _fetch_remote_file(self, filename: str, file_info: Dict) -> Path:
"""Fetch a remote benchmark file and return a temporary file path."""
url = file_info["url"]

try:
# Create SSL context that doesn't verify certificates (for development)
# Create SSL context that doesn't verify certificates (for development/CI)
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
Expand All @@ -78,25 +74,20 @@ def _fetch_remote_file(self, filename: str, file_info: Dict) -> Path:
content = response.read()

# Create temporary file and write content
temp_file = tempfile.NamedTemporaryFile(
with tempfile.NamedTemporaryFile(
mode="wb", suffix=".qasm", prefix=f"benchmark_{filename}_", delete=False
)
temp_file.write(content)
temp_file.close()
) as temp_file:
temp_file.write(content)
temp_file_path = Path(temp_file.name)

return Path(temp_file.name)
return temp_file_path

except Exception as e:
# pylint: disable-next=raise-missing-from
raise RuntimeError(f"Failed to fetch {filename} from {url}: {e}")


# Global instance for convenience
_downloader = None


def get_benchmark_file(filename: str) -> str:
"""Get the path to a benchmark file, downloading if necessary."""
global _downloader
if _downloader is None:
_downloader = BenchmarkDownloader()
return str(_downloader.get_file_path(filename))
downloader = BenchmarkDownloader()
return str(downloader.get_file_path(filename))
123 changes: 27 additions & 96 deletions tests/benchmarks/qasm/benchmark_metadata.json
Original file line number Diff line number Diff line change
@@ -1,106 +1,37 @@
{
"benchmark_files": {
Comment thread
vinayswamik marked this conversation as resolved.
"20QBT_45CYC_.0D1_.1D2_3.qasm": {
"source": "Qiskit-benchmark",
"url": "https://raw.githubusercontent.com/Qiskit/qiskit/main/test/benchmarks/qasm/20QBT_45CYC_.0D1_.1D2_3.qasm",
"description": "20 qubit benchmark with 45 cycles",
"size_bytes": 946
},
"53QBT_100CYC_QSE_3.qasm": {
"source": "Qiskit-benchmark",
"url": "https://raw.githubusercontent.com/Qiskit/qiskit/main/test/benchmarks/qasm/53QBT_100CYC_QSE_3.qasm",
"description": "53 qubit benchmark with 100 cycles",
"size_bytes": 41671
},
"54QBT_25CYC_QSE_3.qasm": {
"source": "Qiskit-benchmark",
"url": "https://raw.githubusercontent.com/Qiskit/qiskit/main/test/benchmarks/qasm/54QBT_25CYC_QSE_3.qasm",
"description": "54 qubit benchmark with 25 cycles",
"size_bytes": 10814
},
"depth_4gt10-v1_81.qasm": {
"source": "Qiskit-benchmark",
"url": "https://raw.githubusercontent.com/Qiskit/qiskit/main/test/benchmarks/qasm/depth_4gt10-v1_81.qasm",
"description": "Depth benchmark 4gt10-v1 with 81 qubits",
"size_bytes": 1694
},
"depth_4mod5-v0_19.qasm": {
"source": "Qiskit-benchmark",
"url": "https://raw.githubusercontent.com/Qiskit/qiskit/main/test/benchmarks/qasm/depth_4mod5-v0_19.qasm",
"description": "Depth benchmark 4mod5-v0 with 19 qubits",
"size_bytes": 448
},
"depth_mod8-10_178.qasm": {
"source": "Qiskit-benchmark",
"url": "https://raw.githubusercontent.com/Qiskit/qiskit/main/test/benchmarks/qasm/depth_mod8-10_178.qasm",
"description": "Depth benchmark mod8-10 with 178 qubits",
"size_bytes": 3834
},
"dtc_100_cx_12345.qasm": {
"source": "Qiskit-benchmark",
"url": "https://raw.githubusercontent.com/Qiskit/qiskit/main/test/benchmarks/qasm/dtc_100_cx_12345.qasm",
"description": "DTC benchmark with 100 CX gates",
"size_bytes": 1204349
},
"vqe_uccsd_n4.qasm": {
"source": "Qiskit-benchpress",
"url": "https://raw.githubusercontent.com/Qiskit/benchpress/573c9ce7a1ffebd4ca6d1b0971eba7aca2c9c9a4/benchpress/qasm/qasmbench-small/vqe_uccsd_n4/vqe_uccsd_n4.qasm",
"description": "VQE UCCSD benchmark with 4 qubits (small)",
"size_bytes": 15000
},
"dnn_n16.qasm": {
"source": "Qiskit-benchpress",
"url": "https://raw.githubusercontent.com/Qiskit/benchpress/573c9ce7a1ffebd4ca6d1b0971eba7aca2c9c9a4/benchpress/qasm/qasmbench-medium/dnn_n16/dnn_n16.qasm",
"description": "Deep Neural Network benchmark with 16 qubits (medium)",
"size_bytes": 120000
},
"qv_N029_12345.qasm": {
"source": "Qiskit-benchpress",
"url": "https://raw.githubusercontent.com/Qiskit/benchpress/573c9ce7a1ffebd4ca6d1b0971eba7aca2c9c9a4/benchpress/qasm/qv/qv_N029_12345.qasm",
"description": "Quantum Volume benchmark with 29 qubits (large, 17,460 lines)",
"size_bytes": 470000
}
},
"repository_info": {
"name": "Qiskit-benchpress",
"url": "https://github.com/Qiskit/benchpress",
"description": "QASM benchmark files from Qiskit benchpress repository",
"license": "Apache-2.0",
"commit_hash": "573c9ce7a1ffebd4ca6d1b0971eba7aca2c9c9a4"
},
"local_files": {
"neutral_atom_gate.qasm": {
"source": "local",
"description": "Neutral atom gate benchmark (local file)",
"size_bytes": 3584,
"local_only": true
},
"pea_3_pi_8.qasm": {
"source": "Qiskit-benchmark",
"url": "https://raw.githubusercontent.com/Qiskit/qiskit/main/test/benchmarks/qasm/pea_3_pi_8.qasm",
"description": "PEA benchmark with 3 pi/8 rotations",
"size_bytes": 695
},
"qaoa_barabasi_albert_N100_3reps.qasm": {
"source": "Qiskit-benchmark",
"url": "https://raw.githubusercontent.com/Qiskit/qiskit/main/test/benchmarks/qasm/qaoa_barabasi_albert_N100_3reps.qasm",
"description": "QAOA benchmark on Barabasi-Albert graph with N=100 and 3 repetitions",
"size_bytes": 47302
},
"qft_N100.qasm": {
"source": "Qiskit-benchmark",
"url": "https://raw.githubusercontent.com/Qiskit/qiskit/main/test/benchmarks/qasm/qft_N100.qasm",
"description": "Quantum Fourier Transform benchmark with N=100",
"size_bytes": 437131
},
"square_heisenberg_N100.qasm": {
"source": "Qiskit-benchmark",
"url": "https://raw.githubusercontent.com/Qiskit/qiskit/main/test/benchmarks/qasm/square_heisenberg_N100.qasm",
"description": "Square Heisenberg model benchmark with N=100",
"size_bytes": 120081
},
"test_eoh_qasm.qasm": {
"source": "Qiskit-benchmark",
"url": "https://raw.githubusercontent.com/Qiskit/qiskit/main/test/benchmarks/qasm/test_eoh_qasm.qasm",
"description": "EOH (Evolution of Hamiltonian) test benchmark",
"size_bytes": 72169
},
"time_cnt3-5_179.qasm": {
"source": "Qiskit-benchmark",
"url": "https://raw.githubusercontent.com/Qiskit/qiskit/main/test/benchmarks/qasm/time_cnt3-5_179.qasm",
"description": "Time benchmark cnt3-5 with 179 qubits",
"size_bytes": 2124
},
"time_cnt3-5_180.qasm": {
"source": "Qiskit-benchmark",
"url": "https://raw.githubusercontent.com/Qiskit/qiskit/main/test/benchmarks/qasm/time_cnt3-5_180.qasm",
"description": "Time benchmark cnt3-5 with 180 qubits",
"size_bytes": 5770
},
"time_qft_16.qasm": {
"source": "Qiskit-benchmark",
"url": "https://raw.githubusercontent.com/Qiskit/qiskit/main/test/benchmarks/qasm/time_qft_16.qasm",
"description": "Time benchmark QFT with 16 qubits",
"size_bytes": 8240
}
},
"repository_info": {
"name": "Qiskit-benchmark",
"url": "https://github.com/Qiskit/qiskit",
"description": "QASM benchmark files from Qiskit repository",
"license": "Apache-2.0"
}
}
Loading