tno.quantum.devices 1.0.1__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.
- tno_quantum_devices-1.0.1/CHANGELOG.md +3 -0
- tno_quantum_devices-1.0.1/CITATION.cff +22 -0
- tno_quantum_devices-1.0.1/LICENSE +201 -0
- tno_quantum_devices-1.0.1/PKG-INFO +95 -0
- tno_quantum_devices-1.0.1/README.md +52 -0
- tno_quantum_devices-1.0.1/pyproject.toml +62 -0
- tno_quantum_devices-1.0.1/setup.cfg +4 -0
- tno_quantum_devices-1.0.1/src/tno/quantum/devices/__init__.py +34 -0
- tno_quantum_devices-1.0.1/src/tno/quantum/devices/_config.py +63 -0
- tno_quantum_devices-1.0.1/src/tno/quantum/devices/azure.py +216 -0
- tno_quantum_devices-1.0.1/src/tno/quantum/devices/ibm.py +171 -0
- tno_quantum_devices-1.0.1/src/tno/quantum/devices/py.typed +0 -0
- tno_quantum_devices-1.0.1/src/tno/quantum/devices/test/__init__.py +1 -0
- tno_quantum_devices-1.0.1/src/tno/quantum/devices/test/test_azure.py +49 -0
- tno_quantum_devices-1.0.1/src/tno/quantum/devices/test/test_config.py +19 -0
- tno_quantum_devices-1.0.1/src/tno/quantum/devices/test/test_ibm.py +47 -0
- tno_quantum_devices-1.0.1/src/tno.quantum.devices.egg-info/PKG-INFO +95 -0
- tno_quantum_devices-1.0.1/src/tno.quantum.devices.egg-info/SOURCES.txt +20 -0
- tno_quantum_devices-1.0.1/src/tno.quantum.devices.egg-info/dependency_links.txt +1 -0
- tno_quantum_devices-1.0.1/src/tno.quantum.devices.egg-info/entry_points.txt +3 -0
- tno_quantum_devices-1.0.1/src/tno.quantum.devices.egg-info/requires.txt +19 -0
- tno_quantum_devices-1.0.1/src/tno.quantum.devices.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
license: Apache-2.0
|
|
3
|
+
message: If you use this software, please cite it using these metadata.
|
|
4
|
+
authors:
|
|
5
|
+
- name: TNO Quantum
|
|
6
|
+
city: The Hague
|
|
7
|
+
country: NL
|
|
8
|
+
email: quantumcodelab@tno.nl
|
|
9
|
+
website: https://tno.nl
|
|
10
|
+
type: software
|
|
11
|
+
url: https://tno.nl
|
|
12
|
+
contact:
|
|
13
|
+
- name: TNO Quantum
|
|
14
|
+
city: The Hague
|
|
15
|
+
country: NL
|
|
16
|
+
email: quantumcodelab@tno.nl
|
|
17
|
+
website: https://tno.nl
|
|
18
|
+
repository-code: https://github.com/TNO-Quantum/devices
|
|
19
|
+
repository-artifact: https://pypi.org/project/tno.quantum.devices
|
|
20
|
+
title: TNO Quantum - Devices
|
|
21
|
+
version: 1.0.2
|
|
22
|
+
date-released: 2026-10-08
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 The Netherlands Organisation for Applied Scientific Research (TNO)
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tno.quantum.devices
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: Devices
|
|
5
|
+
Author-email: TNO Quantum Code Lab <tnoquantum@tno.nl>
|
|
6
|
+
Maintainer-email: TNO Quantum Code Lab <tnoquantum@tno.nl>
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
Project-URL: Homepage, https://github.com/TNO-Quantum/
|
|
9
|
+
Project-URL: Documentation, https://github.com/TNO-Quantum/
|
|
10
|
+
Project-URL: Source, https://github.com/TNO-Quantum/devices
|
|
11
|
+
Keywords: TNO,Quantum,Devices
|
|
12
|
+
Platform: any
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Information Technology
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: pennylane
|
|
27
|
+
Requires-Dist: pennylane-qiskit
|
|
28
|
+
Requires-Dist: tno.quantum.utils
|
|
29
|
+
Provides-Extra: tests
|
|
30
|
+
Requires-Dist: pytest>=8.1.1; extra == "tests"
|
|
31
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == "tests"
|
|
32
|
+
Provides-Extra: ibm
|
|
33
|
+
Requires-Dist: qiskit>=2; extra == "ibm"
|
|
34
|
+
Requires-Dist: qiskit-ibm-runtime; extra == "ibm"
|
|
35
|
+
Requires-Dist: qiskit-ibm-provider; extra == "ibm"
|
|
36
|
+
Provides-Extra: azure
|
|
37
|
+
Requires-Dist: qiskit>=2; extra == "azure"
|
|
38
|
+
Requires-Dist: azure-core; extra == "azure"
|
|
39
|
+
Requires-Dist: azure-identity; extra == "azure"
|
|
40
|
+
Requires-Dist: azure-quantum[qiskit]>=3.5.0; extra == "azure"
|
|
41
|
+
Requires-Dist: azure-storage-blob; extra == "azure"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# TNO Quantum: Devices
|
|
45
|
+
|
|
46
|
+
TNO Quantum provides generic software components aimed at facilitating the development
|
|
47
|
+
of quantum applications.
|
|
48
|
+
|
|
49
|
+
The devices package provides a consistent way to configure and instantiate PennyLane devices,
|
|
50
|
+
including local devices and remote backends from IBM Quantum Platform and Azure Quantum.
|
|
51
|
+
|
|
52
|
+
## Documentation
|
|
53
|
+
|
|
54
|
+
Documentation of the `tno.quantum.devices` package can be found [here](https://tno-quantum.github.io/documentation/).
|
|
55
|
+
|
|
56
|
+
## Install
|
|
57
|
+
|
|
58
|
+
Easily install the `tno.quantum.devices` package using pip:
|
|
59
|
+
|
|
60
|
+
```console
|
|
61
|
+
$ python -m pip install tno.quantum.devices
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Usage
|
|
65
|
+
|
|
66
|
+
The `tno.quantum.devices` package can be used as shown in the following example.
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from tno.quantum.devices import DeviceConfig
|
|
70
|
+
|
|
71
|
+
# Get a list of supported items
|
|
72
|
+
sorted(DeviceConfig.supported_items())
|
|
73
|
+
# ['default.clifford', 'default.gaussian', 'default.mixed', ...]
|
|
74
|
+
|
|
75
|
+
# Create a device
|
|
76
|
+
config = DeviceConfig("default.qubit", options={"wires": 5})
|
|
77
|
+
config.get_instance()
|
|
78
|
+
# <default.qubit device (wires=5) at 0x7b9fd6fc7770>
|
|
79
|
+
|
|
80
|
+
# Create an IBM device using "ibm.remote"
|
|
81
|
+
config = DeviceConfig("ibm.remote", options={"backend_name": "ibm_aachen", "wires": 5})
|
|
82
|
+
config.get_instance()
|
|
83
|
+
# <IBMDevice device (wires=5) at 0x7b9ffcfa5f30>
|
|
84
|
+
|
|
85
|
+
# Create an Azure device using "azure.remote"
|
|
86
|
+
config = DeviceConfig(
|
|
87
|
+
"azure.remote", options={"backend_name": "rigetti_cepheus", "wires": 5}
|
|
88
|
+
)
|
|
89
|
+
config.get_instance()
|
|
90
|
+
# <AzureDevice device (wires=5) at 0x7b9fdcbba9e0>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## (End)use limitations
|
|
94
|
+
|
|
95
|
+
The content of this software may solely be used for applications that comply with international export control laws.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# TNO Quantum: Devices
|
|
2
|
+
|
|
3
|
+
TNO Quantum provides generic software components aimed at facilitating the development
|
|
4
|
+
of quantum applications.
|
|
5
|
+
|
|
6
|
+
The devices package provides a consistent way to configure and instantiate PennyLane devices,
|
|
7
|
+
including local devices and remote backends from IBM Quantum Platform and Azure Quantum.
|
|
8
|
+
|
|
9
|
+
## Documentation
|
|
10
|
+
|
|
11
|
+
Documentation of the `tno.quantum.devices` package can be found [here](https://tno-quantum.github.io/documentation/).
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
Easily install the `tno.quantum.devices` package using pip:
|
|
16
|
+
|
|
17
|
+
```console
|
|
18
|
+
$ python -m pip install tno.quantum.devices
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
The `tno.quantum.devices` package can be used as shown in the following example.
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from tno.quantum.devices import DeviceConfig
|
|
27
|
+
|
|
28
|
+
# Get a list of supported items
|
|
29
|
+
sorted(DeviceConfig.supported_items())
|
|
30
|
+
# ['default.clifford', 'default.gaussian', 'default.mixed', ...]
|
|
31
|
+
|
|
32
|
+
# Create a device
|
|
33
|
+
config = DeviceConfig("default.qubit", options={"wires": 5})
|
|
34
|
+
config.get_instance()
|
|
35
|
+
# <default.qubit device (wires=5) at 0x7b9fd6fc7770>
|
|
36
|
+
|
|
37
|
+
# Create an IBM device using "ibm.remote"
|
|
38
|
+
config = DeviceConfig("ibm.remote", options={"backend_name": "ibm_aachen", "wires": 5})
|
|
39
|
+
config.get_instance()
|
|
40
|
+
# <IBMDevice device (wires=5) at 0x7b9ffcfa5f30>
|
|
41
|
+
|
|
42
|
+
# Create an Azure device using "azure.remote"
|
|
43
|
+
config = DeviceConfig(
|
|
44
|
+
"azure.remote", options={"backend_name": "rigetti_cepheus", "wires": 5}
|
|
45
|
+
)
|
|
46
|
+
config.get_instance()
|
|
47
|
+
# <AzureDevice device (wires=5) at 0x7b9fdcbba9e0>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## (End)use limitations
|
|
51
|
+
|
|
52
|
+
The content of this software may solely be used for applications that comply with international export control laws.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools", "setuptools-scm", "pennylane"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tno.quantum.devices"
|
|
7
|
+
description = "Devices"
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
authors = [{ name = "TNO Quantum Code Lab", email = "tnoquantum@tno.nl" }]
|
|
10
|
+
maintainers = [{ name = "TNO Quantum Code Lab", email = "tnoquantum@tno.nl" }]
|
|
11
|
+
keywords = ["TNO", "Quantum", "Devices"]
|
|
12
|
+
license = "Apache-2.0"
|
|
13
|
+
license-files = ["LICENSE"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
'Intended Audience :: Developers',
|
|
16
|
+
'Intended Audience :: Information Technology',
|
|
17
|
+
'Intended Audience :: Science/Research',
|
|
18
|
+
'Operating System :: OS Independent',
|
|
19
|
+
'Programming Language :: Python :: 3',
|
|
20
|
+
'Programming Language :: Python :: 3.11',
|
|
21
|
+
'Programming Language :: Python :: 3.12',
|
|
22
|
+
'Programming Language :: Python :: 3.13',
|
|
23
|
+
'Programming Language :: Python :: 3.14',
|
|
24
|
+
'Typing :: Typed',
|
|
25
|
+
]
|
|
26
|
+
dynamic = ["version"]
|
|
27
|
+
requires-python = ">=3.11"
|
|
28
|
+
dependencies = ["pennylane", "pennylane-qiskit", "tno.quantum.utils"]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://github.com/TNO-Quantum/"
|
|
32
|
+
Documentation = "https://github.com/TNO-Quantum/"
|
|
33
|
+
Source = "https://github.com/TNO-Quantum/devices"
|
|
34
|
+
|
|
35
|
+
[project.optional-dependencies]
|
|
36
|
+
tests = ["pytest>=8.1.1", "pytest-cov>=4.1.0"]
|
|
37
|
+
ibm = [
|
|
38
|
+
"qiskit>=2",
|
|
39
|
+
"qiskit-ibm-runtime", # IBM
|
|
40
|
+
"qiskit-ibm-provider", # IBM
|
|
41
|
+
]
|
|
42
|
+
azure = [
|
|
43
|
+
"qiskit>=2",
|
|
44
|
+
"azure-core", # Azure
|
|
45
|
+
"azure-identity", # Azure
|
|
46
|
+
"azure-quantum[qiskit]>=3.5.0", # Azure
|
|
47
|
+
"azure-storage-blob", # Azure
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
[project.entry-points."pennylane.plugins"]
|
|
51
|
+
"ibm.remote" = "tno.quantum.devices.ibm:IBMDevice"
|
|
52
|
+
"azure.remote" = "tno.quantum.devices.azure:AzureDevice"
|
|
53
|
+
|
|
54
|
+
[tool.setuptools]
|
|
55
|
+
platforms = ["any"]
|
|
56
|
+
|
|
57
|
+
[tool.setuptools.dynamic]
|
|
58
|
+
version = { attr = "tno.quantum.devices.__version__" }
|
|
59
|
+
|
|
60
|
+
[tool.setuptools.package-data]
|
|
61
|
+
"*" = ["py.typed"]
|
|
62
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""This package can be used to connect to backends from various quantum providers.
|
|
2
|
+
|
|
3
|
+
Currently, the supported quantum providers are:
|
|
4
|
+
|
|
5
|
+
- `IBM Quantum Platform <https://quantum.cloud.ibm.com/>`_
|
|
6
|
+
- `Azure Quantum <https://azure.microsoft.com/en-us/solutions/quantum-computing>`_
|
|
7
|
+
|
|
8
|
+
Besides external quantum providers, this package also provides the functionality to
|
|
9
|
+
instantiate the default PennyLane devices.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
Installation
|
|
13
|
+
------------
|
|
14
|
+
|
|
15
|
+
Install the base package using ``pip``:
|
|
16
|
+
|
|
17
|
+
.. code-block:: bash
|
|
18
|
+
|
|
19
|
+
pip install tno.quantum.devices
|
|
20
|
+
|
|
21
|
+
Provider-specific dependencies can be installed via extras:
|
|
22
|
+
|
|
23
|
+
.. code-block:: bash
|
|
24
|
+
|
|
25
|
+
pip install tno.quantum.devices[ibm] # for IBM Quantum backends
|
|
26
|
+
pip install tno.quantum.devices[azure] # for Azure Quantum backends
|
|
27
|
+
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
from tno.quantum.devices._config import DeviceConfig
|
|
31
|
+
|
|
32
|
+
__all__ = ["DeviceConfig"]
|
|
33
|
+
|
|
34
|
+
__version__ = "1.0.1"
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""This module contains the ``DeviceConfig`` class."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Callable, Mapping
|
|
6
|
+
from functools import partial
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
import pennylane as qml
|
|
10
|
+
from pennylane.devices import Device
|
|
11
|
+
from tno.quantum.utils import BaseConfig
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class DeviceConfig(BaseConfig[Device]):
|
|
15
|
+
"""Configuration class for creating PennyLane :py:class:`~pennylane.devices.Device`
|
|
16
|
+
instances.
|
|
17
|
+
|
|
18
|
+
Supported devices can be obtained by calling
|
|
19
|
+
:py:meth:`~DeviceConfig.supported_items`.
|
|
20
|
+
|
|
21
|
+
Example:
|
|
22
|
+
>>> from tno.quantum.devices import DeviceConfig
|
|
23
|
+
>>>
|
|
24
|
+
>>> # List available PennyLane devices
|
|
25
|
+
>>> sorted(DeviceConfig.supported_items()) # doctest: +ELLIPSIS
|
|
26
|
+
[..., 'default.gaussian', 'default.mixed', 'default.qubit', ...]
|
|
27
|
+
>>>
|
|
28
|
+
>>> # Instantiate PennyLane device
|
|
29
|
+
>>> config = DeviceConfig("default.qubit", options={"wires": 5})
|
|
30
|
+
>>> type(config.get_instance())
|
|
31
|
+
<class 'pennylane.devices.default_qubit.DefaultQubit'>
|
|
32
|
+
""" # noqa: D205
|
|
33
|
+
|
|
34
|
+
def __init__(
|
|
35
|
+
self,
|
|
36
|
+
name: str,
|
|
37
|
+
options: Mapping[str, Any] | None = None,
|
|
38
|
+
) -> None:
|
|
39
|
+
"""Initialize :py:class:`DeviceConfig`.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
name: Name of the PennyLane :py:class:`~pennylane.devices.Device`.
|
|
43
|
+
options: Keyword arguments to pass to the device.
|
|
44
|
+
"""
|
|
45
|
+
super().__init__(name=name, options=options)
|
|
46
|
+
|
|
47
|
+
@staticmethod
|
|
48
|
+
def supported_items() -> dict[str, Callable[..., Device]]:
|
|
49
|
+
"""Obtain all supported PennyLane backend devices.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
Dictionary with callable that instantiate Pennylane Device instances.
|
|
53
|
+
"""
|
|
54
|
+
return {name: partial(qml.device, name=name) for name in qml.plugin_devices}
|
|
55
|
+
|
|
56
|
+
def get_instance(self, *args: Any, **kwargs: Any) -> Device:
|
|
57
|
+
"""Instantiate PennyLane :py:class:`~pennylane.devices.Device`.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
args: Additional positional arguments to pass to the device.
|
|
61
|
+
kwargs: Additional keyword arguments to pass to the device.
|
|
62
|
+
"""
|
|
63
|
+
return super().get_instance(*args, **kwargs)
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"""This module contains functionality related to the Azure quantum provider.
|
|
2
|
+
|
|
3
|
+
The :py:class:`AzureDevice` class defines a PennyLane device (called ``azure.remote``)
|
|
4
|
+
which can be used execute circuits on the Azure backends.
|
|
5
|
+
The following example shows how this can be done.
|
|
6
|
+
|
|
7
|
+
Example:
|
|
8
|
+
-------
|
|
9
|
+
|
|
10
|
+
.. code-block:: python
|
|
11
|
+
|
|
12
|
+
# To use any of the Azure backends, make sure your connection string is set.
|
|
13
|
+
# This method sets the connection string in the environment variables, so it needs
|
|
14
|
+
# to be set at the start of every session.
|
|
15
|
+
from tno.quantum.devices import azure
|
|
16
|
+
|
|
17
|
+
azure.set_connection_string(
|
|
18
|
+
connection_string="...",
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
# An Azure device can be constructed in two ways.
|
|
22
|
+
# (1) Either directly using `qml.device`
|
|
23
|
+
import pennylane as qml
|
|
24
|
+
|
|
25
|
+
dev = qml.device("azure.remote", backend_name="quantinuum.sim.h2-1e", wires=2)
|
|
26
|
+
|
|
27
|
+
# (2) Using the `DeviceConfig` class.
|
|
28
|
+
from tno.quantum.devices import DeviceConfig
|
|
29
|
+
|
|
30
|
+
config = DeviceConfig(
|
|
31
|
+
"azure.remote",
|
|
32
|
+
options={"backend_name": "quantinuum.sim.h2-1e", "wires": 2},
|
|
33
|
+
)
|
|
34
|
+
dev = config.get_instance()
|
|
35
|
+
|
|
36
|
+
# Now, we can create and execute a quantum circuit on the defined device.
|
|
37
|
+
@qml.qnode(dev, shots=100)
|
|
38
|
+
def circuit():
|
|
39
|
+
qml.Hadamard(0)
|
|
40
|
+
qml.CNOT([0, 1])
|
|
41
|
+
return qml.sample()
|
|
42
|
+
|
|
43
|
+
samples = circuit()
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
from __future__ import annotations
|
|
47
|
+
|
|
48
|
+
import importlib.util
|
|
49
|
+
import os
|
|
50
|
+
from collections.abc import Iterable
|
|
51
|
+
from typing import TYPE_CHECKING, Any, cast
|
|
52
|
+
|
|
53
|
+
from pennylane_qiskit.remote import RemoteDevice
|
|
54
|
+
|
|
55
|
+
if TYPE_CHECKING:
|
|
56
|
+
from pennylane.devices import ExecutionConfig
|
|
57
|
+
from pennylane.tape import QuantumScriptOrBatch
|
|
58
|
+
from pennylane.typing import Result, ResultBatch
|
|
59
|
+
from pennylane.wires import WiresLike
|
|
60
|
+
from qiskit import QuantumCircuit
|
|
61
|
+
from qiskit.circuit import Instruction
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _is_azure_installed() -> bool:
|
|
65
|
+
return importlib.util.find_spec("azure") is not None
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if _is_azure_installed():
|
|
69
|
+
from azure.quantum import Workspace
|
|
70
|
+
from azure.quantum.qiskit import AzureQuantumProvider
|
|
71
|
+
from azure.quantum.qiskit.backends.backend import AzureBackendConfig
|
|
72
|
+
|
|
73
|
+
if TYPE_CHECKING:
|
|
74
|
+
from azure.quantum.qiskit.backends import AzureBackendBase
|
|
75
|
+
|
|
76
|
+
# Ad-hoc fix for `azure-quantum` bug
|
|
77
|
+
|
|
78
|
+
def azure_backend_config_getattr_fixed( # noqa: D103
|
|
79
|
+
self: AzureBackendConfig, name: str
|
|
80
|
+
) -> Any:
|
|
81
|
+
if name == "max_experiments":
|
|
82
|
+
return 1
|
|
83
|
+
try:
|
|
84
|
+
return self.__dict__[name]
|
|
85
|
+
except KeyError as exc:
|
|
86
|
+
if name == "metadata":
|
|
87
|
+
msg = "AzureBackendConfig has no property `metadata`"
|
|
88
|
+
raise AttributeError(msg) from None
|
|
89
|
+
if name in self.metadata:
|
|
90
|
+
return self.metadata[name]
|
|
91
|
+
msg = f"'{type(self).__name__}' object has no attribute '{name}'"
|
|
92
|
+
raise AttributeError(msg) from exc
|
|
93
|
+
|
|
94
|
+
AzureBackendConfig.__getattr__ = azure_backend_config_getattr_fixed
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
_AZURE_SERVICE: AzureQuantumProvider | None = None
|
|
98
|
+
_AZURE_QUANTUM_CONNECTION_STRING = "AZURE_QUANTUM_CONNECTION_STRING"
|
|
99
|
+
_AZURE_NOT_INSTALLED_MSG = (
|
|
100
|
+
"because Azure quantum packages are not installed. "
|
|
101
|
+
"These can be installed via `tno.quantum.devices[azure]`."
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def backends() -> list[str]:
|
|
106
|
+
"""Returns a list of names of all available Azure backends."""
|
|
107
|
+
global _AZURE_SERVICE # noqa: PLW0602
|
|
108
|
+
connect()
|
|
109
|
+
return [backend.name for backend in _AZURE_SERVICE.backends()] # type: ignore[union-attr]
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def backend(name: str) -> AzureBackendBase:
|
|
113
|
+
"""Get Azure backend by name.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
name: Name of the Azure backend.
|
|
117
|
+
"""
|
|
118
|
+
global _AZURE_SERVICE # noqa: PLW0602
|
|
119
|
+
connect()
|
|
120
|
+
return cast("AzureBackendBase", _AZURE_SERVICE.get_backend(name)) # type: ignore[union-attr]
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def connect() -> None:
|
|
124
|
+
"""Connect to the Azure service.
|
|
125
|
+
|
|
126
|
+
Before calling this method, a connection string must be set as an environment
|
|
127
|
+
variable, e.g. using :py:meth:`set_connection_string`. Otherwise, an exception
|
|
128
|
+
will be raised.
|
|
129
|
+
|
|
130
|
+
Raises:
|
|
131
|
+
RuntimeError - If no connection string is set.
|
|
132
|
+
"""
|
|
133
|
+
global _AZURE_SERVICE # noqa: PLW0603
|
|
134
|
+
|
|
135
|
+
if not _is_azure_installed():
|
|
136
|
+
msg = "Could not connect to Azure service, " + _AZURE_NOT_INSTALLED_MSG
|
|
137
|
+
raise RuntimeError(msg)
|
|
138
|
+
|
|
139
|
+
if _AZURE_SERVICE is None:
|
|
140
|
+
connection_string = os.environ.get(_AZURE_QUANTUM_CONNECTION_STRING, None)
|
|
141
|
+
if connection_string is None:
|
|
142
|
+
msg = (
|
|
143
|
+
"No connection string found. "
|
|
144
|
+
"Use `tno.quantum.devices.azure.set_connection_string` "
|
|
145
|
+
"to set the connection string."
|
|
146
|
+
)
|
|
147
|
+
raise RuntimeError(msg)
|
|
148
|
+
workspace = Workspace.from_connection_string(connection_string)
|
|
149
|
+
_AZURE_SERVICE = AzureQuantumProvider(workspace)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def set_connection_string(
|
|
153
|
+
connection_string: str,
|
|
154
|
+
) -> None:
|
|
155
|
+
"""Set the ``AZURE_QUANTUM_CONNECTION_STRING`` environment variable.
|
|
156
|
+
|
|
157
|
+
Args:
|
|
158
|
+
connection_string: Azure connection string.
|
|
159
|
+
"""
|
|
160
|
+
os.environ[_AZURE_QUANTUM_CONNECTION_STRING] = connection_string
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
class AzureDevice(RemoteDevice): # type: ignore[misc]
|
|
164
|
+
"""PennyLane device for Azure backends.
|
|
165
|
+
|
|
166
|
+
This device can be constructed using :py:obj:`qml.device("azure.remote", ...)`.
|
|
167
|
+
"""
|
|
168
|
+
|
|
169
|
+
def __init__(self, *, backend_name: str, wires: WiresLike, **kwargs: Any) -> None:
|
|
170
|
+
"""Initialize Azure device.
|
|
171
|
+
|
|
172
|
+
Args:
|
|
173
|
+
backend_name: Name of the Azure backend.
|
|
174
|
+
wires: Wires.
|
|
175
|
+
kwargs: Additional keyword arguments to be passed to the underlying
|
|
176
|
+
:py:class:`~pennylane_qiskit.remote.RemoteDevice`.
|
|
177
|
+
"""
|
|
178
|
+
if not _is_azure_installed():
|
|
179
|
+
msg = (
|
|
180
|
+
"Failed to instantiate device 'azure.remote', "
|
|
181
|
+
+ _AZURE_NOT_INSTALLED_MSG
|
|
182
|
+
)
|
|
183
|
+
raise RuntimeError(msg)
|
|
184
|
+
|
|
185
|
+
self._backend_name = backend_name
|
|
186
|
+
self._backend = backend(backend_name)
|
|
187
|
+
super().__init__(backend=self._backend, wires=wires, **kwargs)
|
|
188
|
+
|
|
189
|
+
def execute(
|
|
190
|
+
self,
|
|
191
|
+
circuits: QuantumScriptOrBatch,
|
|
192
|
+
execution_config: ExecutionConfig | None = None,
|
|
193
|
+
) -> Result | ResultBatch:
|
|
194
|
+
"""Execute circuits with execution config."""
|
|
195
|
+
return super().execute(circuits, execution_config)
|
|
196
|
+
|
|
197
|
+
def compile_circuits(self, circuits: list[QuantumCircuit]) -> list[QuantumCircuit]:
|
|
198
|
+
"""Compiles multiple circuits one after the other.
|
|
199
|
+
|
|
200
|
+
Args:
|
|
201
|
+
circuits: List of circuits to compile.
|
|
202
|
+
|
|
203
|
+
Returns:
|
|
204
|
+
List of compiled circuits
|
|
205
|
+
"""
|
|
206
|
+
circuits = cast("list[QuantumCircuit]", super().compile_circuits(circuits))
|
|
207
|
+
for circuit in circuits:
|
|
208
|
+
self._remove_barriers(circuit)
|
|
209
|
+
return circuits
|
|
210
|
+
|
|
211
|
+
def _remove_barriers(self, circuit: QuantumCircuit) -> None:
|
|
212
|
+
circuit.data = [
|
|
213
|
+
instruction
|
|
214
|
+
for instruction in cast("Iterable[Any]", circuit.data)
|
|
215
|
+
if cast("Instruction", instruction.operation).name != "barrier"
|
|
216
|
+
]
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"""This module contains functionality related to the IBM quantum provider.
|
|
2
|
+
|
|
3
|
+
The :py:class:`IBMDevice` class defines a PennyLane device (called ``ibm.remote``)
|
|
4
|
+
which can be used execute circuits on the IBM backends.
|
|
5
|
+
The following example shows how this can be done.
|
|
6
|
+
|
|
7
|
+
Example:
|
|
8
|
+
-------
|
|
9
|
+
|
|
10
|
+
.. code-block:: python
|
|
11
|
+
|
|
12
|
+
# To use any of the IBM backends, make sure your account is saved.
|
|
13
|
+
# This method stores the account to disk, so it only needs to run once.
|
|
14
|
+
from tno.quantum.devices import ibm
|
|
15
|
+
|
|
16
|
+
ibm.save_account(
|
|
17
|
+
token="...",
|
|
18
|
+
instance="...",
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
# An IBM device can be constructed in two ways.
|
|
22
|
+
# (1) Either directly using `qml.device`
|
|
23
|
+
import pennylane as qml
|
|
24
|
+
|
|
25
|
+
dev = qml.device("ibm.remote", backend_name="ibm_strasbourg", wires=2)
|
|
26
|
+
|
|
27
|
+
# (2) Using the `DeviceConfig` class.
|
|
28
|
+
from tno.quantum.devices import DeviceConfig
|
|
29
|
+
|
|
30
|
+
config = DeviceConfig(
|
|
31
|
+
"ibm.remote",
|
|
32
|
+
options={"backend_name": "ibm_strasbourg", "wires": 2},
|
|
33
|
+
)
|
|
34
|
+
dev = config.get_instance()
|
|
35
|
+
|
|
36
|
+
# Now, we can create and execute a quantum circuit on the defined device.
|
|
37
|
+
@qml.qnode(dev, shots=100)
|
|
38
|
+
def circuit():
|
|
39
|
+
qml.Hadamard(0)
|
|
40
|
+
qml.CNOT([0, 1])
|
|
41
|
+
return qml.sample()
|
|
42
|
+
|
|
43
|
+
samples = circuit()
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
import importlib.util
|
|
47
|
+
from typing import Any, Literal, cast
|
|
48
|
+
|
|
49
|
+
from pennylane.devices import ExecutionConfig
|
|
50
|
+
from pennylane.tape import QuantumScriptOrBatch
|
|
51
|
+
from pennylane.typing import Result, ResultBatch
|
|
52
|
+
from pennylane.wires import WiresLike
|
|
53
|
+
from pennylane_qiskit.remote import RemoteDevice
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _is_ibm_installed() -> bool:
|
|
57
|
+
return importlib.util.find_spec("qiskit_ibm_runtime") is not None
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
if _is_ibm_installed():
|
|
61
|
+
from qiskit_ibm_runtime import QiskitRuntimeService
|
|
62
|
+
from qiskit_ibm_runtime.ibm_backend import IBMBackend
|
|
63
|
+
|
|
64
|
+
_IBM_SERVICE: QiskitRuntimeService | None = None
|
|
65
|
+
_IBM_NOT_INSTALLED_MSG = (
|
|
66
|
+
"because IBM quantum packages are not installed. "
|
|
67
|
+
"These can be installed via `tno.quantum.devices[ibm]`."
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def backends() -> list[str]:
|
|
72
|
+
"""Return a list of names of all available IBM devices."""
|
|
73
|
+
global _IBM_SERVICE # noqa: PLW0602
|
|
74
|
+
connect()
|
|
75
|
+
return [backend.name for backend in _IBM_SERVICE.backends()] # type: ignore[union-attr]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def backend(name: str) -> IBMBackend:
|
|
79
|
+
"""Get IBM backend by name.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
name: Name of the IBM backend.
|
|
83
|
+
"""
|
|
84
|
+
global _IBM_SERVICE # noqa: PLW0602
|
|
85
|
+
connect()
|
|
86
|
+
return cast("IBMBackend", _IBM_SERVICE.backend(name)) # type: ignore[union-attr]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def connect() -> None:
|
|
90
|
+
"""Connect to the IBM service.
|
|
91
|
+
|
|
92
|
+
Before calling this method, an IBM account must be saved, e.g. using
|
|
93
|
+
:py:meth:`save_account`. Otherwise, an exception will be raised.
|
|
94
|
+
|
|
95
|
+
Raises:
|
|
96
|
+
RuntimeError - If no IBM account is saved.s
|
|
97
|
+
"""
|
|
98
|
+
global _IBM_SERVICE # noqa: PLW0603
|
|
99
|
+
|
|
100
|
+
if not _is_ibm_installed():
|
|
101
|
+
msg = "Could not connect to IBM service, " + _IBM_NOT_INSTALLED_MSG
|
|
102
|
+
raise RuntimeError(msg)
|
|
103
|
+
|
|
104
|
+
if _IBM_SERVICE is None:
|
|
105
|
+
_IBM_SERVICE = QiskitRuntimeService()
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def save_account( # noqa: PLR0913
|
|
109
|
+
*,
|
|
110
|
+
token: str,
|
|
111
|
+
instance: str,
|
|
112
|
+
channel: Literal["ibm_quantum_platform", "ibm_cloud"] = "ibm_quantum_platform",
|
|
113
|
+
name: str | None = None,
|
|
114
|
+
set_as_default: bool = True,
|
|
115
|
+
overwrite: bool = False,
|
|
116
|
+
) -> None:
|
|
117
|
+
"""Save IBM account.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
token: IBM Cloud API key.
|
|
121
|
+
instance: This is a parameter to specify the CRN or service name.
|
|
122
|
+
channel: Channel type, either ``ibm_cloud`` or ``ibm_quantum_platform``.
|
|
123
|
+
name: Name of the account to save.
|
|
124
|
+
set_as_default: If :py:const:`True`, the account is saved as the default
|
|
125
|
+
account.
|
|
126
|
+
overwrite: If :py:const:`True`, the existing account is to be overwritten.
|
|
127
|
+
"""
|
|
128
|
+
if not _is_ibm_installed():
|
|
129
|
+
msg = "Failed to save IBM account, " + _IBM_NOT_INSTALLED_MSG
|
|
130
|
+
raise RuntimeError(msg)
|
|
131
|
+
|
|
132
|
+
QiskitRuntimeService.save_account(
|
|
133
|
+
token=token,
|
|
134
|
+
instance=instance,
|
|
135
|
+
channel=channel,
|
|
136
|
+
name=name,
|
|
137
|
+
set_as_default=set_as_default,
|
|
138
|
+
overwrite=overwrite,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class IBMDevice(RemoteDevice): # type: ignore[misc]
|
|
143
|
+
"""PennyLane device for IBM backends.
|
|
144
|
+
|
|
145
|
+
This device can be constructed using :py:obj:`qml.device("ibm.remote", ...)`.
|
|
146
|
+
"""
|
|
147
|
+
|
|
148
|
+
def __init__(self, *, backend_name: str, wires: WiresLike, **kwargs: Any) -> None:
|
|
149
|
+
"""Initialize IBM device.
|
|
150
|
+
|
|
151
|
+
Args:
|
|
152
|
+
backend_name: Name of the IBM backend.
|
|
153
|
+
wires: Wires.
|
|
154
|
+
kwargs: Additional keyword arguments to be passed to the underlying
|
|
155
|
+
:py:class:`~pennylane_qiskit.remote.RemoteDevice`.
|
|
156
|
+
"""
|
|
157
|
+
if not _is_ibm_installed():
|
|
158
|
+
msg = "Failed to instantiate device 'ibm.remote', " + _IBM_NOT_INSTALLED_MSG
|
|
159
|
+
raise RuntimeError(msg)
|
|
160
|
+
|
|
161
|
+
self._backend_name = backend_name
|
|
162
|
+
self._backend = backend(backend_name)
|
|
163
|
+
super().__init__(backend=self._backend, wires=wires, **kwargs)
|
|
164
|
+
|
|
165
|
+
def execute(
|
|
166
|
+
self,
|
|
167
|
+
circuits: QuantumScriptOrBatch,
|
|
168
|
+
execution_config: ExecutionConfig | None = None,
|
|
169
|
+
) -> Result | ResultBatch:
|
|
170
|
+
"""Execute circuits with execution config."""
|
|
171
|
+
return super().execute(circuits, execution_config)
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Testing subpackage of the tno.quantum.devices package"""
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
import pennylane as qml
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from tno.quantum.devices import DeviceConfig, azure
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def can_connect_to_azure() -> bool:
|
|
11
|
+
try:
|
|
12
|
+
azure.connect()
|
|
13
|
+
except Exception: # noqa: BLE001
|
|
14
|
+
return False
|
|
15
|
+
return True
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
_CAN_CONNECT_TO_AZURE = can_connect_to_azure()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@pytest.mark.skipif(
|
|
22
|
+
not _CAN_CONNECT_TO_AZURE, reason="Could not connect to Azure service"
|
|
23
|
+
)
|
|
24
|
+
def test_azure_bell_circuit() -> None:
|
|
25
|
+
"""Test if a Bell circuit can be run on one of Azure's backends."""
|
|
26
|
+
# Find a simulator backend
|
|
27
|
+
backend_name = next((name for name in azure.backends() if "sim" in name), None)
|
|
28
|
+
|
|
29
|
+
if backend_name is None:
|
|
30
|
+
msg = (
|
|
31
|
+
"Could not perform test `test_azure_bell_circuit`, "
|
|
32
|
+
"because no Azure simulator backend was found."
|
|
33
|
+
)
|
|
34
|
+
logging.warning(msg) # noqa: LOG015
|
|
35
|
+
return
|
|
36
|
+
|
|
37
|
+
# Construct device via DeviceConfig
|
|
38
|
+
dev = DeviceConfig(
|
|
39
|
+
"azure.remote", options={"backend_name": backend_name, "wires": 2}
|
|
40
|
+
).get_instance()
|
|
41
|
+
|
|
42
|
+
# Create and execute a quantum circuit on the defined device
|
|
43
|
+
@qml.qnode(dev, shots=100) # type: ignore[untyped-decorator]
|
|
44
|
+
def circuit() -> Any:
|
|
45
|
+
qml.Hadamard(0)
|
|
46
|
+
qml.CNOT([0, 1])
|
|
47
|
+
return qml.sample()
|
|
48
|
+
|
|
49
|
+
circuit()
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Test module for the DeviceConfig class."""
|
|
2
|
+
|
|
3
|
+
from pennylane.devices.default_qubit import DefaultQubit
|
|
4
|
+
|
|
5
|
+
from tno.quantum.devices import DeviceConfig
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_device_config_contains_custom_devices() -> None:
|
|
9
|
+
"""Test that the DeviceConfig contains the custom IBM and Azure devices."""
|
|
10
|
+
items = DeviceConfig.supported_items()
|
|
11
|
+
assert "ibm.remote" in items
|
|
12
|
+
assert "azure.remote" in items
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_device_config_instantiate_default_qubit() -> None:
|
|
16
|
+
"""Test that the DeviceConfig can properly instantiate PennyLane devices."""
|
|
17
|
+
config = DeviceConfig("default.qubit", options={"wires": 1})
|
|
18
|
+
dev = config.get_instance()
|
|
19
|
+
assert isinstance(dev, DefaultQubit)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
import pennylane as qml
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from tno.quantum.devices import DeviceConfig, ibm
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def can_connect_to_ibm() -> bool:
|
|
11
|
+
try:
|
|
12
|
+
ibm.connect()
|
|
13
|
+
except Exception: # noqa: BLE001
|
|
14
|
+
return False
|
|
15
|
+
return True
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
_CAN_CONNECT_TO_IBM = can_connect_to_ibm()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@pytest.mark.skipif(not _CAN_CONNECT_TO_IBM, reason="Could not connect to IBM service")
|
|
22
|
+
def test_ibm_bell_circuit() -> None:
|
|
23
|
+
"""Test if a Bell circuit can be run on one of IBM's backends."""
|
|
24
|
+
# Find a simulator backend
|
|
25
|
+
backend_name = next((name for name in ibm.backends() if "sim" in name), None)
|
|
26
|
+
|
|
27
|
+
if backend_name is None:
|
|
28
|
+
msg = (
|
|
29
|
+
"Could not perform test `test_ibm_bell_circuit`, "
|
|
30
|
+
"because no IBM simulator backend was found."
|
|
31
|
+
)
|
|
32
|
+
logging.warning(msg) # noqa: LOG015
|
|
33
|
+
return
|
|
34
|
+
|
|
35
|
+
# Construct device via DeviceConfig
|
|
36
|
+
dev = DeviceConfig(
|
|
37
|
+
"ibm.remote", options={"backend_name": backend_name, "wires": 2}
|
|
38
|
+
).get_instance()
|
|
39
|
+
|
|
40
|
+
# Create and execute a quantum circuit on the defined device
|
|
41
|
+
@qml.qnode(dev, shots=100) # type: ignore[untyped-decorator]
|
|
42
|
+
def circuit() -> Any:
|
|
43
|
+
qml.Hadamard(0)
|
|
44
|
+
qml.CNOT([0, 1])
|
|
45
|
+
return qml.sample()
|
|
46
|
+
|
|
47
|
+
circuit()
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tno.quantum.devices
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: Devices
|
|
5
|
+
Author-email: TNO Quantum Code Lab <tnoquantum@tno.nl>
|
|
6
|
+
Maintainer-email: TNO Quantum Code Lab <tnoquantum@tno.nl>
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
Project-URL: Homepage, https://github.com/TNO-Quantum/
|
|
9
|
+
Project-URL: Documentation, https://github.com/TNO-Quantum/
|
|
10
|
+
Project-URL: Source, https://github.com/TNO-Quantum/devices
|
|
11
|
+
Keywords: TNO,Quantum,Devices
|
|
12
|
+
Platform: any
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Information Technology
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: pennylane
|
|
27
|
+
Requires-Dist: pennylane-qiskit
|
|
28
|
+
Requires-Dist: tno.quantum.utils
|
|
29
|
+
Provides-Extra: tests
|
|
30
|
+
Requires-Dist: pytest>=8.1.1; extra == "tests"
|
|
31
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == "tests"
|
|
32
|
+
Provides-Extra: ibm
|
|
33
|
+
Requires-Dist: qiskit>=2; extra == "ibm"
|
|
34
|
+
Requires-Dist: qiskit-ibm-runtime; extra == "ibm"
|
|
35
|
+
Requires-Dist: qiskit-ibm-provider; extra == "ibm"
|
|
36
|
+
Provides-Extra: azure
|
|
37
|
+
Requires-Dist: qiskit>=2; extra == "azure"
|
|
38
|
+
Requires-Dist: azure-core; extra == "azure"
|
|
39
|
+
Requires-Dist: azure-identity; extra == "azure"
|
|
40
|
+
Requires-Dist: azure-quantum[qiskit]>=3.5.0; extra == "azure"
|
|
41
|
+
Requires-Dist: azure-storage-blob; extra == "azure"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# TNO Quantum: Devices
|
|
45
|
+
|
|
46
|
+
TNO Quantum provides generic software components aimed at facilitating the development
|
|
47
|
+
of quantum applications.
|
|
48
|
+
|
|
49
|
+
The devices package provides a consistent way to configure and instantiate PennyLane devices,
|
|
50
|
+
including local devices and remote backends from IBM Quantum Platform and Azure Quantum.
|
|
51
|
+
|
|
52
|
+
## Documentation
|
|
53
|
+
|
|
54
|
+
Documentation of the `tno.quantum.devices` package can be found [here](https://tno-quantum.github.io/documentation/).
|
|
55
|
+
|
|
56
|
+
## Install
|
|
57
|
+
|
|
58
|
+
Easily install the `tno.quantum.devices` package using pip:
|
|
59
|
+
|
|
60
|
+
```console
|
|
61
|
+
$ python -m pip install tno.quantum.devices
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Usage
|
|
65
|
+
|
|
66
|
+
The `tno.quantum.devices` package can be used as shown in the following example.
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from tno.quantum.devices import DeviceConfig
|
|
70
|
+
|
|
71
|
+
# Get a list of supported items
|
|
72
|
+
sorted(DeviceConfig.supported_items())
|
|
73
|
+
# ['default.clifford', 'default.gaussian', 'default.mixed', ...]
|
|
74
|
+
|
|
75
|
+
# Create a device
|
|
76
|
+
config = DeviceConfig("default.qubit", options={"wires": 5})
|
|
77
|
+
config.get_instance()
|
|
78
|
+
# <default.qubit device (wires=5) at 0x7b9fd6fc7770>
|
|
79
|
+
|
|
80
|
+
# Create an IBM device using "ibm.remote"
|
|
81
|
+
config = DeviceConfig("ibm.remote", options={"backend_name": "ibm_aachen", "wires": 5})
|
|
82
|
+
config.get_instance()
|
|
83
|
+
# <IBMDevice device (wires=5) at 0x7b9ffcfa5f30>
|
|
84
|
+
|
|
85
|
+
# Create an Azure device using "azure.remote"
|
|
86
|
+
config = DeviceConfig(
|
|
87
|
+
"azure.remote", options={"backend_name": "rigetti_cepheus", "wires": 5}
|
|
88
|
+
)
|
|
89
|
+
config.get_instance()
|
|
90
|
+
# <AzureDevice device (wires=5) at 0x7b9fdcbba9e0>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## (End)use limitations
|
|
94
|
+
|
|
95
|
+
The content of this software may solely be used for applications that comply with international export control laws.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
CHANGELOG.md
|
|
2
|
+
CITATION.cff
|
|
3
|
+
LICENSE
|
|
4
|
+
README.md
|
|
5
|
+
pyproject.toml
|
|
6
|
+
src/tno.quantum.devices.egg-info/PKG-INFO
|
|
7
|
+
src/tno.quantum.devices.egg-info/SOURCES.txt
|
|
8
|
+
src/tno.quantum.devices.egg-info/dependency_links.txt
|
|
9
|
+
src/tno.quantum.devices.egg-info/entry_points.txt
|
|
10
|
+
src/tno.quantum.devices.egg-info/requires.txt
|
|
11
|
+
src/tno.quantum.devices.egg-info/top_level.txt
|
|
12
|
+
src/tno/quantum/devices/__init__.py
|
|
13
|
+
src/tno/quantum/devices/_config.py
|
|
14
|
+
src/tno/quantum/devices/azure.py
|
|
15
|
+
src/tno/quantum/devices/ibm.py
|
|
16
|
+
src/tno/quantum/devices/py.typed
|
|
17
|
+
src/tno/quantum/devices/test/__init__.py
|
|
18
|
+
src/tno/quantum/devices/test/test_azure.py
|
|
19
|
+
src/tno/quantum/devices/test/test_config.py
|
|
20
|
+
src/tno/quantum/devices/test/test_ibm.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
pennylane
|
|
2
|
+
pennylane-qiskit
|
|
3
|
+
tno.quantum.utils
|
|
4
|
+
|
|
5
|
+
[azure]
|
|
6
|
+
qiskit>=2
|
|
7
|
+
azure-core
|
|
8
|
+
azure-identity
|
|
9
|
+
azure-quantum[qiskit]>=3.5.0
|
|
10
|
+
azure-storage-blob
|
|
11
|
+
|
|
12
|
+
[ibm]
|
|
13
|
+
qiskit>=2
|
|
14
|
+
qiskit-ibm-runtime
|
|
15
|
+
qiskit-ibm-provider
|
|
16
|
+
|
|
17
|
+
[tests]
|
|
18
|
+
pytest>=8.1.1
|
|
19
|
+
pytest-cov>=4.1.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tno
|