qbraid-core 0.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qbraid_core-0.0.0/CLAUDE.md +64 -0
- qbraid_core-0.0.0/LICENSE +43 -0
- qbraid_core-0.0.0/MANIFEST.in +5 -0
- qbraid_core-0.0.0/PKG-INFO +5 -0
- qbraid_core-0.0.0/README.md +92 -0
- qbraid_core-0.0.0/docs/_static/favicon.ico +0 -0
- qbraid_core-0.0.0/docs/_static/logo.png +0 -0
- qbraid_core-0.0.0/docs/api/qbraid_core.rst +4 -0
- qbraid_core-0.0.0/docs/api/qbraid_core.services.rst +17 -0
- qbraid_core-0.0.0/docs/conf.py +57 -0
- qbraid_core-0.0.0/docs/index.rst +73 -0
- qbraid_core-0.0.0/pyproject.toml +0 -0
- qbraid_core-0.0.0/qbraid_core/__init__.py +143 -0
- qbraid_core-0.0.0/qbraid_core/_compat.py +45 -0
- qbraid_core-0.0.0/qbraid_core/_import.py +77 -0
- qbraid_core-0.0.0/qbraid_core/_version.py +17 -0
- qbraid_core-0.0.0/qbraid_core/annotations.py +62 -0
- qbraid_core-0.0.0/qbraid_core/client.py +160 -0
- qbraid_core-0.0.0/qbraid_core/config.py +79 -0
- qbraid_core-0.0.0/qbraid_core/context.py +38 -0
- qbraid_core-0.0.0/qbraid_core/decimal.py +79 -0
- qbraid_core-0.0.0/qbraid_core/exceptions.py +58 -0
- qbraid_core-0.0.0/qbraid_core/py.typed +0 -0
- qbraid_core-0.0.0/qbraid_core/registry.py +78 -0
- qbraid_core-0.0.0/qbraid_core/retry.py +83 -0
- qbraid_core-0.0.0/qbraid_core/services/__init__.py +50 -0
- qbraid_core-0.0.0/qbraid_core/services/chat/__init__.py +29 -0
- qbraid_core-0.0.0/qbraid_core/services/chat/client.py +158 -0
- qbraid_core-0.0.0/qbraid_core/services/chat/exceptions.py +17 -0
- qbraid_core-0.0.0/qbraid_core/services/environments/__init__.py +96 -0
- qbraid_core-0.0.0/qbraid_core/services/environments/client.py +2031 -0
- qbraid_core-0.0.0/qbraid_core/services/environments/create.py +208 -0
- qbraid_core-0.0.0/qbraid_core/services/environments/exceptions.py +47 -0
- qbraid_core-0.0.0/qbraid_core/services/environments/kernels.py +100 -0
- qbraid_core-0.0.0/qbraid_core/services/environments/magic.py +74 -0
- qbraid_core-0.0.0/qbraid_core/services/environments/packages.py +350 -0
- qbraid_core-0.0.0/qbraid_core/services/environments/paths.py +295 -0
- qbraid_core-0.0.0/qbraid_core/services/environments/registry.py +784 -0
- qbraid_core-0.0.0/qbraid_core/services/environments/schema.py +214 -0
- qbraid_core-0.0.0/qbraid_core/services/environments/state.py +91 -0
- qbraid_core-0.0.0/qbraid_core/services/environments/utils/__init__.py +6 -0
- qbraid_core-0.0.0/qbraid_core/services/environments/validate.py +105 -0
- qbraid_core-0.0.0/qbraid_core/services/mcp/__init__.py +12 -0
- qbraid_core-0.0.0/qbraid_core/services/mcp/client.py +291 -0
- qbraid_core-0.0.0/qbraid_core/services/mcp/discovery.py +173 -0
- qbraid_core-0.0.0/qbraid_core/services/mcp/router.py +241 -0
- qbraid_core-0.0.0/qbraid_core/services/quantum/__init__.py +44 -0
- qbraid_core-0.0.0/qbraid_core/services/quantum/adapter.py +146 -0
- qbraid_core-0.0.0/qbraid_core/services/quantum/client.py +270 -0
- qbraid_core-0.0.0/qbraid_core/services/quantum/exceptions.py +17 -0
- qbraid_core-0.0.0/qbraid_core/services/quantum/proxy.py +109 -0
- qbraid_core-0.0.0/qbraid_core/services/quantum/proxy_braket.py +116 -0
- qbraid_core-0.0.0/qbraid_core/services/quantum/runner.py +382 -0
- qbraid_core-0.0.0/qbraid_core/services/storage/__init__.py +54 -0
- qbraid_core-0.0.0/qbraid_core/services/storage/client.py +175 -0
- qbraid_core-0.0.0/qbraid_core/services/storage/disk_usage_client.py +95 -0
- qbraid_core-0.0.0/qbraid_core/services/storage/exceptions.py +17 -0
- qbraid_core-0.0.0/qbraid_core/services/storage/types.py +61 -0
- qbraid_core-0.0.0/qbraid_core/sessions.py +788 -0
- qbraid_core-0.0.0/qbraid_core/system/__init__.py +37 -0
- qbraid_core-0.0.0/qbraid_core/system/exceptions.py +33 -0
- qbraid_core-0.0.0/qbraid_core/system/executables.py +397 -0
- qbraid_core-0.0.0/qbraid_core/system/filemanager.py +154 -0
- qbraid_core-0.0.0/qbraid_core/system/generic.py +59 -0
- qbraid_core-0.0.0/qbraid_core/system/magic/__init__.py +29 -0
- qbraid_core-0.0.0/qbraid_core/system/magic/manager.py +64 -0
- qbraid_core-0.0.0/qbraid_core/system/magic/qbraid_magic.py +207 -0
- qbraid_core-0.0.0/qbraid_core/system/packages.py +235 -0
- qbraid_core-0.0.0/qbraid_core/system/versions.py +509 -0
- qbraid_core-0.0.0/qbraid_core.egg-info/PKG-INFO +5 -0
- qbraid_core-0.0.0/qbraid_core.egg-info/SOURCES.txt +72 -0
- qbraid_core-0.0.0/qbraid_core.egg-info/dependency_links.txt +1 -0
- qbraid_core-0.0.0/qbraid_core.egg-info/top_level.txt +1 -0
- qbraid_core-0.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# qBraid Core Development
|
|
2
|
+
|
|
3
|
+
> **MIGRATION IN PROGRESS:** Part of the Environment Manager Migration.
|
|
4
|
+
> Before changing `qbraid_core/services/environments/`, read:
|
|
5
|
+
> - `../migration/PROGRESS.md` - Current status and tasks
|
|
6
|
+
> - `../migration/INTERFACES.md` - API contracts
|
|
7
|
+
>
|
|
8
|
+
> **Branch:** `enhancing_envs`
|
|
9
|
+
|
|
10
|
+
## Structure
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
qbraid_core/
|
|
14
|
+
├── services/
|
|
15
|
+
│ ├── environments/ # EnvironmentManagerClient, EnvironmentRegistryManager
|
|
16
|
+
│ ├── quantum/ # Quantum job submission
|
|
17
|
+
│ ├── mcp/ # MCP WebSocket client
|
|
18
|
+
│ └── ...
|
|
19
|
+
├── system/ # Executables, packages, versions
|
|
20
|
+
└── sessions.py # QbraidSession
|
|
21
|
+
tests/ # Mirrors source structure
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Development Environment
|
|
25
|
+
|
|
26
|
+
Use the shared venv in the parent folder:
|
|
27
|
+
```bash
|
|
28
|
+
../.venv/bin/python script.py # Run scripts
|
|
29
|
+
../.venv/bin/pytest tests/environments/ # Run tests
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Commands
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Testing
|
|
36
|
+
tox -e unit-tests # Run tests with coverage (target: 80%)
|
|
37
|
+
pytest tests/environments/ # Run specific tests
|
|
38
|
+
|
|
39
|
+
# Linting
|
|
40
|
+
tox -e format-check # Check all linters
|
|
41
|
+
tox -e linters # Auto-fix formatting
|
|
42
|
+
|
|
43
|
+
# Install for dev (use parent venv)
|
|
44
|
+
../.venv/bin/pip install -e ".[test,environments,mcp]"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Key Files for Environments
|
|
48
|
+
|
|
49
|
+
- `services/environments/client.py` - EnvironmentManagerClient (API calls)
|
|
50
|
+
- `services/environments/registry.py` - EnvironmentRegistryManager (local registry)
|
|
51
|
+
- `services/environments/schema.py` - EnvironmentConfig, EnvironmentEntry models
|
|
52
|
+
- `services/environments/exceptions.py` - Custom exceptions
|
|
53
|
+
|
|
54
|
+
## Testing Notes
|
|
55
|
+
|
|
56
|
+
- Use `pytest.mark.asyncio` for async tests
|
|
57
|
+
- Mock external calls with `unittest.mock` or `monkeypatch`
|
|
58
|
+
- See existing tests in `tests/environments/` for patterns
|
|
59
|
+
|
|
60
|
+
## Environment Variable for Local API Testing
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
QBRAID_API_URL="http://localhost:3001/api/v1" python script.py
|
|
64
|
+
```
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
qBraid Commercial Software License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025, qBraid Development Team
|
|
4
|
+
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
This license agreement ("License") is between the qBraid Development Team ("Author") and you, the Licensee. This software and associated documentation files (the "Software") may only be used by authorized qBraid customers who have agreed to qBraid's Terms of Service and have a valid subscription or license agreement with qBraid. By using or distributing this Software, you agree to the following terms:
|
|
8
|
+
|
|
9
|
+
1. Grant of License.
|
|
10
|
+
|
|
11
|
+
Subject to the terms of this License, the Author grants you a non-exclusive, non-transferable license to use the Software for personal, academic, and educational purposes. Use of the Software for commercial purposes is strictly prohibited unless express permission is granted by the Author.
|
|
12
|
+
|
|
13
|
+
2. Distribution.
|
|
14
|
+
|
|
15
|
+
You may distribute the Software to others, provided that any such distribution is made under the same terms of this License. Modifications to the Software may not be distributed.
|
|
16
|
+
|
|
17
|
+
3. Modification.
|
|
18
|
+
|
|
19
|
+
You are permitted to modify the Software for personal use. You may contribute improvements or bug fixes back to the Author or the community, but you may not distribute the modifications.
|
|
20
|
+
|
|
21
|
+
4. Commercial Use.
|
|
22
|
+
|
|
23
|
+
The Software may not be used for commercial purposes without explicit, prior written permission from the Author. Permissions for commercial use will be considered on a case-by-case basis.
|
|
24
|
+
|
|
25
|
+
5. Attribution
|
|
26
|
+
|
|
27
|
+
If the Software is used in a non-private setting, including but not limited to academic work, commercial settings, or published literature, attribution must be given to "qbraid-core authored by the qBraid Development Team."
|
|
28
|
+
|
|
29
|
+
6. Disclaimer of Warranty.
|
|
30
|
+
|
|
31
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT.
|
|
32
|
+
|
|
33
|
+
7. Limitation of Liability.
|
|
34
|
+
|
|
35
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
36
|
+
|
|
37
|
+
8. Termination.
|
|
38
|
+
|
|
39
|
+
This License is effective until terminated. Your rights under this License will terminate automatically without notice from the Author if you fail to comply with any term(s) of this License.
|
|
40
|
+
|
|
41
|
+
By using the Software, you agree to be bound by the terms of this License. Redistribution of the Software or use of the Software other than as specifically authorized under this License is prohibited and may result in severe civil and criminal penalties.
|
|
42
|
+
|
|
43
|
+
For licensing inquiries, please contact: contact@qbraid.com
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# qbraid-core
|
|
2
|
+
|
|
3
|
+
[](https://qbraid.github.io/qbraid-core/)
|
|
4
|
+
[](https://codecov.io/gh/qBraid/qbraid-core)
|
|
5
|
+
[](https://pypi.org/project/qbraid-core/)
|
|
6
|
+
[](https://pypi.org/project/qbraid-core/)
|
|
7
|
+
[](https://github.com/qBraid/community/issues)
|
|
8
|
+
|
|
9
|
+
Python library providing core abstractions for software development within the qBraid ecosystem, and a low-level interface to a growing array of qBraid cloud services. The qbraid-core package forms the foundational base for the [qBraid CLI](https://pypi.org/project/qbraid-cli/), the [qBraid SDK](https://pypi.org/project/qbraid/), and the
|
|
10
|
+
[jupyter-environment-manager](https://pypi.org/project/jupyter-environment-manager/).
|
|
11
|
+
|
|
12
|
+
You can find the latest, most up to date, documentation [here](https://qbraid.github.io/qbraid-core/), including a list of services that are supported.
|
|
13
|
+
|
|
14
|
+
*See also*: [`qbraid-core-js`](https://qbraid.github.io/qbraid-core-js/)
|
|
15
|
+
|
|
16
|
+
## Getting Started
|
|
17
|
+
|
|
18
|
+
You can install qbraid-core from PyPI with:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
python -m pip install qbraid-core
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Local configuration
|
|
25
|
+
|
|
26
|
+
After installing qbraid-core, you must configure your account credentials:
|
|
27
|
+
|
|
28
|
+
1. Create a qBraid account or log in to your existing account by visiting
|
|
29
|
+
[account.qbraid.com](https://account.qbraid.com/)
|
|
30
|
+
2. Copy your [API Key](https://docs.qbraid.com/home/account#api-keys) from the left side of
|
|
31
|
+
your [account page](https://account.qbraid.com/):
|
|
32
|
+
3. Save your API key from step 2 in local [configuration file](https://docs.qbraid.com/cli/user-guide/config-files). On Linux and macOS, this file is located at `~/.qbraid/qbraidrc`, where `~` corresponds to your home (`$HOME`) directory. On Windows, the equivalent default location is `%USERPROFILE%\.qbraid\qbraidrc`.
|
|
33
|
+
|
|
34
|
+
```ini
|
|
35
|
+
[default]
|
|
36
|
+
api-key = YOUR_KEY
|
|
37
|
+
url = https://api.qbraid.com/api
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Or generate your `~/.qbraid/qbraidrc` file via the qbraid-core Python interface:
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
>>> from qbraid_core import QbraidSession
|
|
44
|
+
>>> session = QbraidSession(api_key='API_KEY')
|
|
45
|
+
>>> session.save_config()
|
|
46
|
+
>>> session.get_available_services()
|
|
47
|
+
['chat', 'environments', 'quantum', 'storage']
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Other credential configuration methods are available using the [qBraid-CLI](https://docs.qbraid.com/cli/api-reference/qbraid_configure).
|
|
51
|
+
|
|
52
|
+
### Verify setup
|
|
53
|
+
|
|
54
|
+
After configuring your qBraid credentials, verify your setup by running the following from a Python interpreter:
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
>>> import qbraid_core
|
|
58
|
+
>>> quantum_client = qbraid_core.client('quantum')
|
|
59
|
+
>>> device_data = quantum_client.search_devices()
|
|
60
|
+
>>> for item in device_data:
|
|
61
|
+
... print(item['qbraid_id'])
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Community
|
|
65
|
+
|
|
66
|
+
- For feature requests and bug reports: [Submit an issue](https://github.com/qBraid/community/issues)
|
|
67
|
+
- For discussions and/or specific questions about qBraid services, [join our discord community](https://discord.gg/KugF6Cnncm)
|
|
68
|
+
- For questions that are more suited for a forum, post to [Stack Overflow](https://stackoverflow.com/) with the [`qbraid`](https://stackoverflow.com/questions/tagged/qbraid) tag.
|
|
69
|
+
|
|
70
|
+
## Launch on qBraid
|
|
71
|
+
|
|
72
|
+
The "Launch on qBraid" button (below) can be added to any public GitHub
|
|
73
|
+
repository. Clicking on it automaically opens qBraid Lab, and performs a
|
|
74
|
+
`git clone` of the project repo into your account's home directory. Copy the
|
|
75
|
+
code below, and replace `YOUR-USERNAME` and `YOUR-REPOSITORY` with your GitHub
|
|
76
|
+
info.
|
|
77
|
+
|
|
78
|
+
[<img src="https://qbraid-static.s3.amazonaws.com/logos/Launch_on_qBraid_white.png" width="150">](https://account.qbraid.com?gitHubUrl=https://github.com/qBraid/qBraid.git)
|
|
79
|
+
|
|
80
|
+
Use the badge in your project's `README.md`:
|
|
81
|
+
|
|
82
|
+
```markdown
|
|
83
|
+
[<img src="https://qbraid-static.s3.amazonaws.com/logos/Launch_on_qBraid_white.png" width="150">](https://account.qbraid.com?gitHubUrl=https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Use the badge in your project's `README.rst`:
|
|
87
|
+
|
|
88
|
+
```rst
|
|
89
|
+
.. image:: https://qbraid-static.s3.amazonaws.com/logos/Launch_on_qBraid_white.png
|
|
90
|
+
:target: https://account.qbraid.com?gitHubUrl=https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git
|
|
91
|
+
:width: 150px
|
|
92
|
+
```
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
qbraid_core.services
|
|
2
|
+
====================
|
|
3
|
+
|
|
4
|
+
.. automodule:: qbraid_core.services
|
|
5
|
+
:undoc-members:
|
|
6
|
+
:show-inheritance:
|
|
7
|
+
|
|
8
|
+
Submodules
|
|
9
|
+
-----------
|
|
10
|
+
|
|
11
|
+
.. autosummary::
|
|
12
|
+
:toctree: ../stubs/
|
|
13
|
+
|
|
14
|
+
quantum
|
|
15
|
+
environments
|
|
16
|
+
chat
|
|
17
|
+
storage
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Configuration file for the Sphinx documentation builder.
|
|
2
|
+
#
|
|
3
|
+
# This file only contains a selection of the most common options. For a full
|
|
4
|
+
# list see the documentation:
|
|
5
|
+
# http://www.sphinx-doc.org/en/master/config
|
|
6
|
+
|
|
7
|
+
# -- Project information -----------------------------------------------------
|
|
8
|
+
|
|
9
|
+
import qbraid_core
|
|
10
|
+
|
|
11
|
+
project = "qBraid"
|
|
12
|
+
copyright = "2025, qBraid Development Team"
|
|
13
|
+
author = "qBraid Development Team"
|
|
14
|
+
|
|
15
|
+
# Set the version
|
|
16
|
+
version = qbraid_core.__version__
|
|
17
|
+
|
|
18
|
+
# -- General configuration ---------------------------------------------------
|
|
19
|
+
|
|
20
|
+
# Add any Sphinx extension module names here, as strings. They can be
|
|
21
|
+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
|
22
|
+
# ones.
|
|
23
|
+
extensions = [
|
|
24
|
+
"sphinx.ext.napoleon",
|
|
25
|
+
"sphinx.ext.autodoc",
|
|
26
|
+
"sphinx_autodoc_typehints",
|
|
27
|
+
"sphinx.ext.autosummary",
|
|
28
|
+
"sphinx_copybutton",
|
|
29
|
+
"sphinx-pydantic",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
# for rendering documentation without installing the package deps
|
|
33
|
+
autodoc_mock_imports = ["jupyter_client", "IPython", "yaml"]
|
|
34
|
+
|
|
35
|
+
# The master toctree document.
|
|
36
|
+
master_doc = "index"
|
|
37
|
+
|
|
38
|
+
# List of patterns, relative to source directory, that match files and
|
|
39
|
+
# directories to ignore when looking for source files.
|
|
40
|
+
# This pattern also affects html_static_path and html_extra_path.
|
|
41
|
+
exclude_patterns = ["_build", "*.pytest_cache", "*.ipynb_checkpoints", "*tests"]
|
|
42
|
+
|
|
43
|
+
# -- Options for HTML output -------------------------------------------------
|
|
44
|
+
|
|
45
|
+
# The theme to use for HTML and HTML Help pages. See the documentation for
|
|
46
|
+
# a list of builtin themes.
|
|
47
|
+
html_theme = "sphinx_rtd_theme"
|
|
48
|
+
|
|
49
|
+
# Add any paths that contain custom static files (such as style sheets) here,
|
|
50
|
+
# relative to this directory. They are copied after the builtin static files,
|
|
51
|
+
# so a file named "default.css" will overwrite the builtin "default.css".
|
|
52
|
+
html_static_path = ["_static"]
|
|
53
|
+
|
|
54
|
+
html_favicon = "_static/favicon.ico"
|
|
55
|
+
html_show_sphinx = False
|
|
56
|
+
|
|
57
|
+
html_css_files = ["css/s4defs-roles.css"]
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
.. raw:: html
|
|
2
|
+
|
|
3
|
+
<h1 style="text-align: center">
|
|
4
|
+
<img src="./_static/logo.png" alt="qbraid logo" style="width:60px;height:60px;">
|
|
5
|
+
<span> qBraid</span>
|
|
6
|
+
<span style="color:#808080"> | CORE</span>
|
|
7
|
+
</h1>
|
|
8
|
+
<p style="text-align:center;font-style:italic;color:#808080">
|
|
9
|
+
Python client for developing software with qBraid cloud services
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
Overview
|
|
13
|
+
---------
|
|
14
|
+
|
|
15
|
+
Python library providing core abstractions for software development within the qBraid ecosystem, and a low-level interface
|
|
16
|
+
to a growing array of qBraid cloud services. The qbraid-core package forms the foundational base for the `qBraid CLI <https://pypi.org/project/qbraid-cli/>`_,
|
|
17
|
+
the `qBraid SDK <https://pypi.org/project/qbraid/>`_, and the `jupyter-environment-manager <https://pypi.org/project/jupyter-environment-manager/>`_.
|
|
18
|
+
|
|
19
|
+
.. seealso::
|
|
20
|
+
|
|
21
|
+
- `qbraid-core-js <https://qbraid.github.io/qbraid-core-js/>`_
|
|
22
|
+
|
|
23
|
+
Installation
|
|
24
|
+
--------------
|
|
25
|
+
|
|
26
|
+
You can install qbraid-core from PyPI with:
|
|
27
|
+
|
|
28
|
+
.. code-block:: bash
|
|
29
|
+
|
|
30
|
+
pip install qbraid-core
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
Resources
|
|
34
|
+
-----------
|
|
35
|
+
|
|
36
|
+
- `User Guide <https://docs.qbraid.com/core/user-guide>`_
|
|
37
|
+
- `API Reference <https://qbraid.github.io/qbraid-core/api/qbraid_core.html>`_
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
.. toctree::
|
|
41
|
+
:maxdepth: 1
|
|
42
|
+
:caption: SDK API Reference
|
|
43
|
+
:hidden:
|
|
44
|
+
|
|
45
|
+
qbraid <https://qbraid.github.io/qBraid/api/qbraid.html>
|
|
46
|
+
qbraid.programs <https://qbraid.github.io/qBraid/api/qbraid.programs.html>
|
|
47
|
+
qbraid.interface <https://qbraid.github.io/qBraid/api/qbraid.interface.html>
|
|
48
|
+
qbraid.transpiler <https://qbraid.github.io/qBraid/api/qbraid.transpiler.html>
|
|
49
|
+
qbraid.passes <https://qbraid.github.io/qBraid/api/qbraid.passes.html>
|
|
50
|
+
qbraid.runtime <https://qbraid.github.io/qBraid/api/qbraid.runtime.html>
|
|
51
|
+
qbraid.visualization <https://qbraid.github.io/qBraid/api/qbraid.visualization.html>
|
|
52
|
+
|
|
53
|
+
.. toctree::
|
|
54
|
+
:caption: QIR API Reference
|
|
55
|
+
:hidden:
|
|
56
|
+
|
|
57
|
+
qbraid_qir <https://qbraid.github.io/qbraid-qir/api/qbraid_qir.html>
|
|
58
|
+
qbraid_qir.cirq <https://qbraid.github.io/qbraid-qir/api/qbraid_qir.cirq.html>
|
|
59
|
+
qbraid_qir.qasm3 <https://qbraid.github.io/qbraid-qir/api/qbraid_qir.qasm3.html>
|
|
60
|
+
|
|
61
|
+
.. toctree::
|
|
62
|
+
:maxdepth: 1
|
|
63
|
+
:caption: CORE API Reference
|
|
64
|
+
:hidden:
|
|
65
|
+
|
|
66
|
+
api/qbraid_core
|
|
67
|
+
api/qbraid_core.services
|
|
68
|
+
|
|
69
|
+
.. toctree::
|
|
70
|
+
:caption: PYQASM API Reference
|
|
71
|
+
:hidden:
|
|
72
|
+
|
|
73
|
+
pyqasm <https://qbraid.github.io/pyqasm/api/pyqasm.html>
|
|
File without changes
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Copyright (c) 2025, qBraid Development Team
|
|
2
|
+
# All rights reserved.
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
This top level module contains the main qBraid public functionality.
|
|
6
|
+
|
|
7
|
+
.. currentmodule:: qbraid_core
|
|
8
|
+
|
|
9
|
+
Classes
|
|
10
|
+
----------
|
|
11
|
+
|
|
12
|
+
.. autosummary::
|
|
13
|
+
:toctree: ../stubs/
|
|
14
|
+
|
|
15
|
+
Session
|
|
16
|
+
QbraidClient
|
|
17
|
+
QbraidSession
|
|
18
|
+
|
|
19
|
+
Functions
|
|
20
|
+
----------
|
|
21
|
+
|
|
22
|
+
.. autosummary::
|
|
23
|
+
:toctree: ../stubs/
|
|
24
|
+
|
|
25
|
+
client
|
|
26
|
+
setup_default_session
|
|
27
|
+
|
|
28
|
+
Exceptions
|
|
29
|
+
------------
|
|
30
|
+
|
|
31
|
+
.. autosummary::
|
|
32
|
+
:toctree: ../stubs/
|
|
33
|
+
|
|
34
|
+
QbraidException
|
|
35
|
+
QbraidChainedException
|
|
36
|
+
AuthError
|
|
37
|
+
ConfigError
|
|
38
|
+
RequestsApiError
|
|
39
|
+
ResourceNotFoundError
|
|
40
|
+
UserNotFoundError
|
|
41
|
+
|
|
42
|
+
"""
|
|
43
|
+
from ._compat import __version__
|
|
44
|
+
from ._import import LazyLoader
|
|
45
|
+
from .annotations import deprecated
|
|
46
|
+
from .client import QbraidClient, QbraidClientV1
|
|
47
|
+
from .exceptions import (
|
|
48
|
+
AuthError,
|
|
49
|
+
ConfigError,
|
|
50
|
+
QbraidChainedException,
|
|
51
|
+
QbraidException,
|
|
52
|
+
RequestsApiError,
|
|
53
|
+
ResourceNotFoundError,
|
|
54
|
+
UserNotFoundError,
|
|
55
|
+
)
|
|
56
|
+
from .retry import PostForcelistRetry
|
|
57
|
+
from .sessions import QbraidSession, QbraidSessionV1, Session
|
|
58
|
+
|
|
59
|
+
# Hold the default session in a global variable, but don't initialize it yet.
|
|
60
|
+
_DEFAULT_SESSION = None # pylint: disable=invalid-name
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def setup_default_session(**kwargs):
|
|
64
|
+
"""
|
|
65
|
+
Set up a default session, passing through any parameters to the session
|
|
66
|
+
constructor. There is no need to call this unless you wish to pass custom
|
|
67
|
+
parameters, because a default session will be created for you.
|
|
68
|
+
"""
|
|
69
|
+
global _DEFAULT_SESSION # pylint: disable=global-statement
|
|
70
|
+
_DEFAULT_SESSION = QbraidSession(**kwargs)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _get_default_session():
|
|
74
|
+
"""
|
|
75
|
+
Get or create a default session. If the session does not exist, it is created
|
|
76
|
+
with the provided keyword arguments. If it already exists, the existing session
|
|
77
|
+
is returned, ignoring any provided arguments.
|
|
78
|
+
|
|
79
|
+
This function ensures that a session is created only once and reused, offering
|
|
80
|
+
a balance between laziness and reusability.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
**kwargs: Keyword arguments to pass to the Session constructor if creating
|
|
84
|
+
a new session.
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
The default session instance.
|
|
88
|
+
"""
|
|
89
|
+
if _DEFAULT_SESSION is None:
|
|
90
|
+
setup_default_session()
|
|
91
|
+
|
|
92
|
+
return _DEFAULT_SESSION
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def client(*args, **kwargs):
|
|
96
|
+
"""
|
|
97
|
+
Create a client for a specified service using the default session. If specific
|
|
98
|
+
session parameters are needed, a new default session can be initialized before
|
|
99
|
+
calling this function.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
service_name (str): The name of the service for which to create the client.
|
|
103
|
+
**kwargs: Keyword arguments for session customization, used only if creating
|
|
104
|
+
a new default session.
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
A service client instance.
|
|
108
|
+
"""
|
|
109
|
+
return _get_default_session().client(*args, **kwargs)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
__all__ = [
|
|
113
|
+
"Session",
|
|
114
|
+
"QbraidClient",
|
|
115
|
+
"QbraidClientV1",
|
|
116
|
+
"QbraidSession",
|
|
117
|
+
"QbraidSessionV1",
|
|
118
|
+
"PostForcelistRetry",
|
|
119
|
+
"client",
|
|
120
|
+
"setup_default_session",
|
|
121
|
+
"QbraidException",
|
|
122
|
+
"QbraidChainedException",
|
|
123
|
+
"AuthError",
|
|
124
|
+
"ConfigError",
|
|
125
|
+
"RequestsApiError",
|
|
126
|
+
"ResourceNotFoundError",
|
|
127
|
+
"UserNotFoundError",
|
|
128
|
+
"LazyLoader",
|
|
129
|
+
"deprecated",
|
|
130
|
+
"__version__",
|
|
131
|
+
]
|
|
132
|
+
|
|
133
|
+
_lazy_mods = ["services", "system"]
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def __getattr__(name):
|
|
137
|
+
if name in _lazy_mods:
|
|
138
|
+
return LazyLoader(name, globals(), f"qbraid_core.{name}")
|
|
139
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def __dir__():
|
|
143
|
+
return sorted(__all__ + _lazy_mods)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Copyright (c) 2025, qBraid Development Team
|
|
2
|
+
# All rights reserved.
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Module for emitting and disabling warnings at top level.
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
import warnings
|
|
9
|
+
|
|
10
|
+
from ._import import LazyLoader
|
|
11
|
+
from ._version import __version__
|
|
12
|
+
from .exceptions import QbraidException
|
|
13
|
+
|
|
14
|
+
versions = LazyLoader("versions", globals(), "qbraid_core.system.versions")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _warn_new_version(local: str, latest: str) -> bool:
|
|
18
|
+
"""Returns True if you should warn user about updated package version,
|
|
19
|
+
False otherwise."""
|
|
20
|
+
if not local or local == "dev" or not latest:
|
|
21
|
+
return False
|
|
22
|
+
|
|
23
|
+
installed_major, installed_minor = map(int, local.split(".")[:2])
|
|
24
|
+
latest_major, latest_minor = map(int, latest.split(".")[:2])
|
|
25
|
+
|
|
26
|
+
return (installed_major, installed_minor) < (latest_major, latest_minor)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def check_version(package: str) -> None:
|
|
30
|
+
"""Emits UserWarning if updated package version exists."""
|
|
31
|
+
try:
|
|
32
|
+
local_version = (
|
|
33
|
+
__version__ if package == "qbraid_core" else versions.get_local_package_version(package)
|
|
34
|
+
)
|
|
35
|
+
latest_version = versions.get_latest_package_version(package)
|
|
36
|
+
|
|
37
|
+
if _warn_new_version(local_version, latest_version):
|
|
38
|
+
warnings.warn(
|
|
39
|
+
f"You are using {package} version {local_version}, however, version "
|
|
40
|
+
f"{latest_version} is available. To avoid compatibility issues, consider "
|
|
41
|
+
"upgrading.",
|
|
42
|
+
UserWarning,
|
|
43
|
+
)
|
|
44
|
+
except QbraidException:
|
|
45
|
+
pass
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Copyright (c) 2025, qBraid Development Team
|
|
2
|
+
# All rights reserved.
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Module used for lazy loading and dynamic imports of submodules.
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
import importlib
|
|
9
|
+
import logging
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
import types
|
|
13
|
+
import warnings
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def suppress_warning(warning_name: str, module_name: str) -> None:
|
|
19
|
+
"""
|
|
20
|
+
Suppresses a specific warning from a module, if that module is available.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
warning_name (str): The name of the warning class to suppress.
|
|
24
|
+
module_name (str): The module where the warning class is defined.
|
|
25
|
+
|
|
26
|
+
"""
|
|
27
|
+
try:
|
|
28
|
+
module = __import__(module_name, fromlist=[warning_name])
|
|
29
|
+
warning_class = getattr(module, warning_name)
|
|
30
|
+
warnings.simplefilter("ignore", warning_class)
|
|
31
|
+
except (ImportError, AttributeError):
|
|
32
|
+
logger.warning("Failed to suppress warning %s from module %s", warning_name, module_name)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class LazyLoader(types.ModuleType):
|
|
36
|
+
"""Lazily import a module, mainly to avoid pulling in large dependencies.
|
|
37
|
+
|
|
38
|
+
This class acts as a proxy for a module, loading it only when an attribute
|
|
39
|
+
of the module is accessed for the first time.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
local_name: The local name that the module will be refered to as.
|
|
43
|
+
parent_module_globals: The globals of the module where this should be imported.
|
|
44
|
+
Typically this will be globals().
|
|
45
|
+
name: The full qualified name of the module.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
def __init__(self, local_name, parent_module_globals, name):
|
|
49
|
+
self._local_name = local_name
|
|
50
|
+
self._parent_module_globals = parent_module_globals
|
|
51
|
+
self._module = None
|
|
52
|
+
self._docs_build = self._is_sphinx_build()
|
|
53
|
+
super().__init__(name)
|
|
54
|
+
|
|
55
|
+
def _is_sphinx_build(self):
|
|
56
|
+
"""Check if the current environment is a Sphinx build."""
|
|
57
|
+
return os.environ.get("SPHINX_BUILD") == "1" or "sphinx" in sys.modules
|
|
58
|
+
|
|
59
|
+
def _load(self):
|
|
60
|
+
"""Load the module and insert it into the parent's globals."""
|
|
61
|
+
if self._module is None:
|
|
62
|
+
self._module = importlib.import_module(self.__name__)
|
|
63
|
+
self._parent_module_globals[self._local_name] = self._module
|
|
64
|
+
self.__dict__.update(self._module.__dict__)
|
|
65
|
+
return self._module
|
|
66
|
+
|
|
67
|
+
def __getattr__(self, item):
|
|
68
|
+
if self._docs_build:
|
|
69
|
+
self._load() # Ensure module is loaded when Sphinx is running
|
|
70
|
+
module = self._load()
|
|
71
|
+
return getattr(module, item)
|
|
72
|
+
|
|
73
|
+
def __dir__(self):
|
|
74
|
+
if self._docs_build:
|
|
75
|
+
self._load() # Ensure module is loaded when Sphinx is running
|
|
76
|
+
module = self._load()
|
|
77
|
+
return dir(module)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Copyright (c) 2025, qBraid Development Team
|
|
2
|
+
# All rights reserved.
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Module defining package version.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import importlib.metadata
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
__version__ = importlib.metadata.version("qbraid-core")
|
|
12
|
+
except Exception: # pylint: disable=broad-exception-caught # pragma: no cover
|
|
13
|
+
__version__ = "dev"
|
|
14
|
+
|
|
15
|
+
__version_tuple__ = tuple(int(part) if part.isdigit() else part for part in __version__.split("."))
|
|
16
|
+
|
|
17
|
+
__all__ = ["__version__", "__version_tuple__"]
|