-
Notifications
You must be signed in to change notification settings - Fork 23
Feature/pyqasm benchmarking and Profiling #258
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
Open
vinayswamik
wants to merge
10
commits into
main
Choose a base branch
from
feature/pyqasm-benchmarking
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
99449c1
Added qasm files for benchmarking
vinayswamik 9442e52
Added asv benchmarking support in pyqasm
vinayswamik 4dab1e7
code refactor
vinayswamik e35f365
Update CHANGELOG.md
vinayswamik 81ee3a1
removed qasm files
vinayswamik 83e03c4
Refactor benchmark setup.
vinayswamik 55ffef2
Update Benchmarking
vinayswamik ffa48d7
Add profiling data and visualizations for PyQASM functions
vinayswamik ecd52d5
Merge branch 'main' into feature/pyqasm-benchmarking
vinayswamik 7a729e8
Merge branch 'main' into feature/pyqasm-benchmarking
TheGupta2012 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,32 @@ | ||
| { | ||
| "version": 1, | ||
| "project": "pyqasm", | ||
| "project_url": "https://sdk.qbraid.com/pyqasm/", | ||
| "repo": ".", | ||
| "install_command": [ | ||
| "in-dir={env_dir} python -m pip install {wheel_file}[visualization,pulse]" | ||
| ], | ||
| "uninstall_command": [ | ||
| "return-code=any python -m pip uninstall -y pyqasm" | ||
| ], | ||
| "build_command": [ | ||
| "python -m pip install -U build", | ||
| "python -m build --outdir {build_cache_dir} --wheel {build_dir}" | ||
| ], | ||
| "branches": [ | ||
| "main" | ||
| ], | ||
| "dvcs": "git", | ||
| "environment_type": "virtualenv", | ||
| "show_commit_url": "https://github.com/qBraid/pyqasm/commit/", | ||
| "pythons": [ | ||
| "3.10", | ||
| "3.11", | ||
| "3.12", | ||
| "3.13" | ||
| ], | ||
| "benchmark_dir": "tests/benchmarks", | ||
| "env_dir": ".asv/env", | ||
| "results_dir": ".asv/results", | ||
| "html_dir": "tests/benchmarks/.html" | ||
| } | ||
This file contains hidden or 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,13 @@ | ||
| # Copyright 2025 qBraid | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. |
This file contains hidden or 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,28 @@ | ||
| # Copyright 2025 qBraid | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # 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 | ||
|
ryanhill1 marked this conversation as resolved.
Outdated
|
||
|
|
||
| """ | ||
| This module is used to test the import time of pyqasm. | ||
| """ | ||
|
|
||
| from subprocess import call | ||
| from sys import executable | ||
|
|
||
|
|
||
| class PyqasmImport: | ||
| def time_pyqasm_import(self): | ||
| call((executable, "-c", "import pyqasm")) | ||
This file contains hidden or 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,33 @@ | ||
| # Copyright 2025 qBraid | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # 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 | ||
|
ryanhill1 marked this conversation as resolved.
Outdated
|
||
|
|
||
| """ | ||
| This module is used to test the openpulse of pyqasm. | ||
| """ | ||
|
|
||
| from pyqasm import load | ||
|
|
||
| from .qasm.benchmark_downloader import get_benchmark_file | ||
|
|
||
|
|
||
| class Openpulse: | ||
| def setup(self): | ||
| # Get benchmark file, downloading if necessary | ||
| self.qasm_file = get_benchmark_file("neutral_atom_gate.qasm") | ||
|
|
||
| def time_openpulse(self): | ||
| _ = load(self.qasm_file).unroll() | ||
This file contains hidden or 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,61 @@ | ||
| # Copyright 2025 qBraid | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # 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 | ||
|
|
||
|
ryanhill1 marked this conversation as resolved.
Outdated
|
||
| """ | ||
| This module is used to test the basic functions of pyqasm. | ||
| """ | ||
|
|
||
| import os | ||
| from pathlib import Path | ||
|
|
||
| from pyqasm import dump, dumps, load, printer | ||
|
|
||
| from .qasm.benchmark_downloader import get_benchmark_file | ||
|
|
||
|
|
||
| class PyqasmFunctions: | ||
| def setup(self): | ||
| # Get benchmark files, downloading if necessary | ||
| self.qasm_file = get_benchmark_file("qft_N100.qasm") | ||
|
|
||
| # 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") | ||
|
|
||
| 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): | ||
| # 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): | ||
| _ = load(self.qasm_file) | ||
|
|
||
| def time_dumps(self): | ||
| _ = dumps(self.pyqasm_obj) | ||
|
|
||
| def time_dump(self): | ||
| dump(self.pyqasm_obj, self.output_file) | ||
|
|
||
| def time_draw(self): | ||
| _ = printer.mpl_draw(self.mid_pyqasm_obj, idle_wires=True, external_draw=False) | ||
This file contains hidden or 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,13 @@ | ||
| # Copyright 2025 qBraid | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. |
This file contains hidden or 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,102 @@ | ||
| # Copyright 2025 qBraid | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """ | ||
| Benchmark file downloader utility. | ||
|
|
||
| This module handles downloading benchmark QASM files from the Qiskit repository | ||
| and caching them locally to avoid storing large files in version control. | ||
| """ | ||
|
|
||
| # pylint: disable-all | ||
|
ryanhill1 marked this conversation as resolved.
Outdated
|
||
|
|
||
| import json | ||
| import ssl | ||
| import tempfile | ||
| import urllib.request | ||
| from pathlib import Path | ||
| from typing import Dict, Optional | ||
|
|
||
|
|
||
| class BenchmarkDownloader: | ||
| """Handles downloading and caching of benchmark files.""" | ||
|
|
||
| def __init__(self, cache_dir: Optional[str] = None): | ||
| """Initialize the downloader.""" | ||
| self.cache_dir = Path(cache_dir) if cache_dir else Path(__file__).parent | ||
| self.cache_dir.mkdir(exist_ok=True) | ||
|
|
||
| # Load metadata | ||
| with open(self.cache_dir / "benchmark_metadata.json", "r", encoding="utf-8") as f: | ||
| self.metadata = json.load(f) | ||
|
|
||
| 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): | ||
| 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." | ||
| ) | ||
| return file_path | ||
|
|
||
| # For remote files, fetch and return a temporary file | ||
| return self._fetch_remote_file(filename, file_info) | ||
|
|
||
| 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) | ||
| ssl_context = ssl.create_default_context() | ||
| ssl_context.check_hostname = False | ||
| ssl_context.verify_mode = ssl.CERT_NONE | ||
|
|
||
| # Create opener with SSL context and fetch content | ||
| opener = urllib.request.build_opener(urllib.request.HTTPSHandler(context=ssl_context)) | ||
| urllib.request.install_opener(opener) | ||
|
|
||
| with urllib.request.urlopen(url) as response: | ||
| content = response.read() | ||
|
|
||
| # Create temporary file and write content | ||
| temp_file = tempfile.NamedTemporaryFile( | ||
| mode="wb", suffix=".qasm", prefix=f"benchmark_{filename}_", delete=False | ||
| ) | ||
| temp_file.write(content) | ||
| temp_file.close() | ||
|
|
||
| return Path(temp_file.name) | ||
|
|
||
| except Exception as e: | ||
| 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)) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.