qilisdk 0.1.3__py3-none-any.whl → 0.1.5__py3-none-any.whl
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.
- qilisdk/__init__.py +11 -2
- qilisdk/__init__.pyi +2 -3
- qilisdk/_logging.py +135 -0
- qilisdk/_optionals.py +5 -7
- qilisdk/analog/__init__.py +3 -18
- qilisdk/analog/exceptions.py +2 -4
- qilisdk/analog/hamiltonian.py +455 -110
- qilisdk/analog/linear_schedule.py +118 -0
- qilisdk/analog/schedule.py +272 -79
- qilisdk/backends/__init__.py +45 -0
- qilisdk/{digital/digital_algorithm.py → backends/__init__.pyi} +3 -5
- qilisdk/backends/backend.py +117 -0
- qilisdk/{extras/cuda → backends}/cuda_backend.py +153 -161
- qilisdk/backends/qutip_backend.py +492 -0
- qilisdk/common/__init__.py +48 -2
- qilisdk/common/algorithm.py +2 -1
- qilisdk/{extras/qaas/qaas_settings.py → common/exceptions.py} +12 -6
- qilisdk/common/model.py +1019 -1
- qilisdk/common/parameterizable.py +75 -0
- qilisdk/common/qtensor.py +666 -0
- qilisdk/common/result.py +2 -1
- qilisdk/common/variables.py +1931 -0
- qilisdk/{extras/cuda/cuda_analog_result.py → cost_functions/__init__.py} +3 -4
- qilisdk/cost_functions/cost_function.py +77 -0
- qilisdk/cost_functions/model_cost_function.py +145 -0
- qilisdk/cost_functions/observable_cost_function.py +109 -0
- qilisdk/digital/__init__.py +3 -22
- qilisdk/digital/ansatz.py +203 -160
- qilisdk/digital/circuit.py +81 -9
- qilisdk/digital/exceptions.py +12 -6
- qilisdk/digital/gates.py +228 -85
- qilisdk/{extras/qaas/qaas_analog_result.py → functionals/__init__.py} +14 -5
- qilisdk/functionals/functional.py +39 -0
- qilisdk/{extras/cuda/cuda_digital_result.py → functionals/functional_result.py} +3 -4
- qilisdk/functionals/sampling.py +81 -0
- qilisdk/functionals/sampling_result.py +92 -0
- qilisdk/functionals/time_evolution.py +98 -0
- qilisdk/functionals/time_evolution_result.py +84 -0
- qilisdk/functionals/variational_program.py +80 -0
- qilisdk/functionals/variational_program_result.py +69 -0
- qilisdk/logging_config.yaml +16 -0
- qilisdk/{common/backend.py → optimizers/__init__.py} +2 -1
- qilisdk/optimizers/optimizer.py +39 -0
- qilisdk/{common → optimizers}/optimizer_result.py +3 -12
- qilisdk/{common/optimizer.py → optimizers/scipy_optimizer.py} +10 -28
- qilisdk/settings.py +78 -0
- qilisdk/{extras → speqtrum}/__init__.py +7 -8
- qilisdk/{extras → speqtrum}/__init__.pyi +3 -3
- qilisdk/speqtrum/experiments/__init__.py +25 -0
- qilisdk/speqtrum/experiments/experiment_functional.py +124 -0
- qilisdk/speqtrum/experiments/experiment_result.py +231 -0
- qilisdk/{extras/qaas → speqtrum}/keyring.py +8 -4
- qilisdk/speqtrum/speqtrum.py +432 -0
- qilisdk/speqtrum/speqtrum_models.py +300 -0
- qilisdk/utils/__init__.py +0 -14
- qilisdk/utils/openqasm2.py +1 -1
- qilisdk/utils/serialization.py +1 -1
- qilisdk/utils/visualization/PlusJakartaSans-SemiBold.ttf +0 -0
- qilisdk/utils/visualization/__init__.py +24 -0
- qilisdk/utils/visualization/circuit_renderers.py +781 -0
- qilisdk/utils/visualization/schedule_renderers.py +161 -0
- qilisdk/utils/visualization/style.py +154 -0
- qilisdk/utils/visualization/themes.py +76 -0
- qilisdk/yaml.py +126 -0
- {qilisdk-0.1.3.dist-info → qilisdk-0.1.5.dist-info}/METADATA +180 -135
- qilisdk-0.1.5.dist-info/RECORD +69 -0
- qilisdk/analog/algorithms.py +0 -111
- qilisdk/analog/analog_backend.py +0 -43
- qilisdk/analog/analog_result.py +0 -114
- qilisdk/analog/quantum_objects.py +0 -533
- qilisdk/digital/digital_backend.py +0 -90
- qilisdk/digital/digital_result.py +0 -145
- qilisdk/digital/vqe.py +0 -166
- qilisdk/extras/cuda/__init__.py +0 -13
- qilisdk/extras/qaas/__init__.py +0 -13
- qilisdk/extras/qaas/models.py +0 -132
- qilisdk/extras/qaas/qaas_backend.py +0 -255
- qilisdk/extras/qaas/qaas_digital_result.py +0 -20
- qilisdk/extras/qaas/qaas_time_evolution_result.py +0 -20
- qilisdk/extras/qaas/qaas_vqe_result.py +0 -20
- qilisdk-0.1.3.dist-info/RECORD +0 -51
- {qilisdk-0.1.3.dist-info → qilisdk-0.1.5.dist-info}/WHEEL +0 -0
- {qilisdk-0.1.3.dist-info → qilisdk-0.1.5.dist-info}/licenses/LICENCE +0 -0
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
# Copyright 2025 Qilimanjaro Quantum Tech
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
import heapq
|
|
15
|
-
import operator
|
|
16
|
-
from pprint import pformat
|
|
17
|
-
|
|
18
|
-
from qilisdk.common.result import Result
|
|
19
|
-
from qilisdk.yaml import yaml
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
@yaml.register_class
|
|
23
|
-
class DigitalResult(Result):
|
|
24
|
-
"""
|
|
25
|
-
Class representing the result of a quantum circuit measurement.
|
|
26
|
-
|
|
27
|
-
DigitalResult encapsulates the outcome of a digital measurement performed on a quantum circuit.
|
|
28
|
-
It includes the total number of measurement shots, the measurement samples and measurement probabilities.
|
|
29
|
-
|
|
30
|
-
Attributes:
|
|
31
|
-
nshots (int): The number of measurement shots performed in the experiment.
|
|
32
|
-
nqubits (int): The number of qubits measured.
|
|
33
|
-
samples (dict[str, int]): A dictionary where keys are bitstrings representing measurement outcomes and values are the number of times each outcome was observed.
|
|
34
|
-
"""
|
|
35
|
-
|
|
36
|
-
def __init__(self, nshots: int, samples: dict[str, int]) -> None:
|
|
37
|
-
"""
|
|
38
|
-
Initializes a DigitalResult instance.
|
|
39
|
-
|
|
40
|
-
Args:
|
|
41
|
-
nshots (int): The total number of measurement shots performed.
|
|
42
|
-
samples (dict[str, int]): A dictionary mapping bitstring outcomes to their occurrence counts.
|
|
43
|
-
All keys (bitstrings) must have the same length, which determines the number of qubits.
|
|
44
|
-
|
|
45
|
-
Raises:
|
|
46
|
-
ValueError: If the samples dictionary is empty or if not all bitstring keys have the same length.
|
|
47
|
-
"""
|
|
48
|
-
self._nshots = nshots
|
|
49
|
-
self._samples = samples
|
|
50
|
-
|
|
51
|
-
# Ensure samples is not empty and is correct.
|
|
52
|
-
if not samples:
|
|
53
|
-
raise ValueError("The samples dictionary is empty.")
|
|
54
|
-
bitstrings = list(samples.keys())
|
|
55
|
-
nqubits = len(bitstrings[0])
|
|
56
|
-
if not all(len(bitstring) == nqubits for bitstring in bitstrings):
|
|
57
|
-
raise ValueError("Not all bitstring keys have the same length.")
|
|
58
|
-
|
|
59
|
-
# Assign nqubits to attribute
|
|
60
|
-
self._nqubits = nqubits
|
|
61
|
-
|
|
62
|
-
# Calculate probabilities
|
|
63
|
-
self._probabilities = {
|
|
64
|
-
bitstring: counts / self._nshots if self._nshots > 0 else 0.0 for bitstring, counts in self._samples.items()
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
@property
|
|
68
|
-
def nshots(self) -> int:
|
|
69
|
-
"""
|
|
70
|
-
Gets the number of measurement shots.
|
|
71
|
-
|
|
72
|
-
Returns:
|
|
73
|
-
int: The total number of measurement shots performed.
|
|
74
|
-
"""
|
|
75
|
-
return self._nshots
|
|
76
|
-
|
|
77
|
-
@property
|
|
78
|
-
def nqubits(self) -> int:
|
|
79
|
-
"""
|
|
80
|
-
Gets the number of qubits involved in the measurement.
|
|
81
|
-
|
|
82
|
-
Returns:
|
|
83
|
-
int: The number of qubits measured.
|
|
84
|
-
"""
|
|
85
|
-
return self._nqubits
|
|
86
|
-
|
|
87
|
-
@property
|
|
88
|
-
def samples(self) -> dict[str, int]:
|
|
89
|
-
"""
|
|
90
|
-
Gets the raw measurement samples.
|
|
91
|
-
|
|
92
|
-
Returns:
|
|
93
|
-
dict[str, int]: A dictionary where keys are bitstrings representing measurement outcomes
|
|
94
|
-
and values are the number of times each outcome was observed.
|
|
95
|
-
"""
|
|
96
|
-
return dict(self._samples)
|
|
97
|
-
|
|
98
|
-
@property
|
|
99
|
-
def probabilities(self) -> dict[str, float]:
|
|
100
|
-
"""
|
|
101
|
-
Gets the probabilities for each measurement outcome.
|
|
102
|
-
|
|
103
|
-
Returns:
|
|
104
|
-
dict[str, float]: A dictionary mapping each bitstring outcome to its corresponding probability.
|
|
105
|
-
"""
|
|
106
|
-
return dict(self._probabilities)
|
|
107
|
-
|
|
108
|
-
def get_probability(self, bitstring: str) -> float:
|
|
109
|
-
"""
|
|
110
|
-
Computes the probability of a specific measurement outcome.
|
|
111
|
-
|
|
112
|
-
Args:
|
|
113
|
-
bitstring (str): The bitstring representing the measurement outcome of interest.
|
|
114
|
-
|
|
115
|
-
Returns:
|
|
116
|
-
float: The probability of the specified bitstring occurring.
|
|
117
|
-
"""
|
|
118
|
-
return self._probabilities.get(bitstring, 0.0)
|
|
119
|
-
|
|
120
|
-
def get_probabilities(self, n: int | None = None) -> list[tuple[str, float]]:
|
|
121
|
-
"""
|
|
122
|
-
Returns the n most probable bitstrings along with their probabilities.
|
|
123
|
-
|
|
124
|
-
Parameters:
|
|
125
|
-
n (int): The number of most probable bitstrings to return.
|
|
126
|
-
|
|
127
|
-
Returns:
|
|
128
|
-
list[tuple[str, float]]: A list of tuples (bitstring, probability) sorted in descending order by probability.
|
|
129
|
-
"""
|
|
130
|
-
if n is None:
|
|
131
|
-
n = len(self._probabilities)
|
|
132
|
-
return heapq.nlargest(n, self._probabilities.items(), key=operator.itemgetter(1))
|
|
133
|
-
|
|
134
|
-
def __repr__(self) -> str:
|
|
135
|
-
"""
|
|
136
|
-
Returns a string representation of the DigitalResult instance for debugging purposes.
|
|
137
|
-
|
|
138
|
-
The representation includes the class name, the number of measurement shots, and a formatted
|
|
139
|
-
display of the measurement samples.
|
|
140
|
-
|
|
141
|
-
Returns:
|
|
142
|
-
str: A string representation of the DigitalResult instance for debugging.
|
|
143
|
-
"""
|
|
144
|
-
class_name = self.__class__.__name__
|
|
145
|
-
return f"{class_name}(\n nshots={self.nshots},\n samples={pformat(self.samples)}\n)"
|
qilisdk/digital/vqe.py
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
# Copyright 2025 Qilimanjaro Quantum Tech
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
from pprint import pformat
|
|
15
|
-
from typing import Callable
|
|
16
|
-
|
|
17
|
-
from qilisdk.common.optimizer import Optimizer
|
|
18
|
-
from qilisdk.common.optimizer_result import OptimizerIntermediateResult, OptimizerResult
|
|
19
|
-
from qilisdk.common.result import Result
|
|
20
|
-
from qilisdk.digital.ansatz import Ansatz
|
|
21
|
-
from qilisdk.digital.digital_algorithm import DigitalAlgorithm
|
|
22
|
-
from qilisdk.digital.digital_backend import DigitalBackend
|
|
23
|
-
from qilisdk.digital.digital_result import DigitalResult
|
|
24
|
-
from qilisdk.yaml import yaml
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
@yaml.register_class
|
|
28
|
-
class VQEResult(Result):
|
|
29
|
-
"""
|
|
30
|
-
Represents the result of a VQE calculation.
|
|
31
|
-
|
|
32
|
-
Attributes:
|
|
33
|
-
optimal_cost (float): The estimated ground state energy (optimal cost).
|
|
34
|
-
optimal_parameters (list[float]): The optimal parameters found during the optimization.
|
|
35
|
-
"""
|
|
36
|
-
|
|
37
|
-
def __init__(self, optimizer_result: OptimizerResult) -> None:
|
|
38
|
-
super().__init__()
|
|
39
|
-
self._optimizer_result: OptimizerResult = optimizer_result
|
|
40
|
-
|
|
41
|
-
@property
|
|
42
|
-
def optimal_cost(self) -> float:
|
|
43
|
-
"""
|
|
44
|
-
Get the optimal cost (estimated ground state energy).
|
|
45
|
-
|
|
46
|
-
Returns:
|
|
47
|
-
float: The optimal cost.
|
|
48
|
-
"""
|
|
49
|
-
return self._optimizer_result.optimal_cost
|
|
50
|
-
|
|
51
|
-
@property
|
|
52
|
-
def optimal_parameters(self) -> list[float]:
|
|
53
|
-
"""
|
|
54
|
-
Get the optimal ansatz parameters.
|
|
55
|
-
|
|
56
|
-
Returns:
|
|
57
|
-
list[float]: The optimal parameters.
|
|
58
|
-
"""
|
|
59
|
-
return self._optimizer_result.optimal_parameters
|
|
60
|
-
|
|
61
|
-
@property
|
|
62
|
-
def intermediate_results(self) -> list[OptimizerIntermediateResult]:
|
|
63
|
-
"""
|
|
64
|
-
Get the intermediate results.
|
|
65
|
-
|
|
66
|
-
Returns:
|
|
67
|
-
list[OptimizerResult]: The intermediate results.
|
|
68
|
-
"""
|
|
69
|
-
return self._optimizer_result.intermediate_results
|
|
70
|
-
|
|
71
|
-
def __repr__(self) -> str:
|
|
72
|
-
"""
|
|
73
|
-
Return a string representation of the VQEResult for debugging.
|
|
74
|
-
|
|
75
|
-
Returns:
|
|
76
|
-
str: A formatted string detailing the optimal cost and parameters.
|
|
77
|
-
"""
|
|
78
|
-
class_name = self.__class__.__name__
|
|
79
|
-
return (
|
|
80
|
-
f"{class_name}(\n Optimal Cost = {self.optimal_cost},"
|
|
81
|
-
+ f"\n Optimal Parameters={pformat(self.optimal_parameters)},"
|
|
82
|
-
+ f"\n Intermediate Results={pformat(self.intermediate_results)})"
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
@yaml.register_class
|
|
87
|
-
class VQE(DigitalAlgorithm):
|
|
88
|
-
"""
|
|
89
|
-
Implements the Variational Quantum Eigensolver (VQE) algorithm.
|
|
90
|
-
|
|
91
|
-
The VQE algorithm is a hybrid quantum-classical method used to approximate the ground
|
|
92
|
-
state energy of a quantum system. It relies on a parameterized quantum circuit (ansatz)
|
|
93
|
-
whose parameters are tuned by a classical optimizer to minimize the cost function—typically
|
|
94
|
-
the expectation value of the system's Hamiltonian.
|
|
95
|
-
|
|
96
|
-
The algorithm outputs a VQEResult that includes the optimal cost (estimated ground state energy)
|
|
97
|
-
and the optimal parameters that yield this cost.
|
|
98
|
-
"""
|
|
99
|
-
|
|
100
|
-
def __init__(
|
|
101
|
-
self, ansatz: Ansatz, initial_params: list[float], cost_function: Callable[[DigitalResult], float]
|
|
102
|
-
) -> None:
|
|
103
|
-
"""
|
|
104
|
-
Initialize the VQE algorithm.
|
|
105
|
-
|
|
106
|
-
Args:
|
|
107
|
-
ansatz (Ansatz): The parameterized quantum circuit representing the trial state.
|
|
108
|
-
initial_params (list[float]): The initial set of parameters for the ansatz.
|
|
109
|
-
cost_function (Callable[[DigitalResult], float]): A function that computes the cost from
|
|
110
|
-
a DigitalResult obtained after executing the circuit. The cost generally represents the
|
|
111
|
-
expectation value of the Hamiltonian.
|
|
112
|
-
"""
|
|
113
|
-
self._ansatz = ansatz
|
|
114
|
-
self._initial_params = initial_params
|
|
115
|
-
self._cost_function = cost_function
|
|
116
|
-
self._execution_results: list[DigitalResult]
|
|
117
|
-
|
|
118
|
-
def obtain_cost(self, params: list[float], backend: DigitalBackend, nshots: int = 1000) -> float:
|
|
119
|
-
"""
|
|
120
|
-
Evaluate the cost at a given parameter set by executing the corresponding quantum circuit.
|
|
121
|
-
|
|
122
|
-
The process involves:
|
|
123
|
-
1. Generating the quantum circuit using the ansatz with the specified parameters.
|
|
124
|
-
2. Executing the circuit on the provided digital backend with the given number of shots.
|
|
125
|
-
3. Passing the resulting DigitalResult to the cost_function to obtain the cost value.
|
|
126
|
-
|
|
127
|
-
Args:
|
|
128
|
-
params (list[float]): The ansatz parameters to evaluate.
|
|
129
|
-
backend (DigitalBackend): The digital backend that executes the quantum circuit.
|
|
130
|
-
nshots (int, optional): The number of shots (circuit executions). Defaults to 1000.
|
|
131
|
-
|
|
132
|
-
Returns:
|
|
133
|
-
float: The cost computed from the DigitalResult.
|
|
134
|
-
"""
|
|
135
|
-
circuit = self._ansatz.get_circuit(params)
|
|
136
|
-
results = backend.execute(circuit=circuit, nshots=nshots)
|
|
137
|
-
return self._cost_function(results)
|
|
138
|
-
|
|
139
|
-
def execute(
|
|
140
|
-
self,
|
|
141
|
-
backend: DigitalBackend,
|
|
142
|
-
optimizer: Optimizer,
|
|
143
|
-
nshots: int = 1000,
|
|
144
|
-
store_intermediate_results: bool = False,
|
|
145
|
-
) -> VQEResult:
|
|
146
|
-
"""
|
|
147
|
-
Run the VQE algorithm to obtain the optimal parameters and the corresponding cost.
|
|
148
|
-
|
|
149
|
-
This method leverages a classical optimizer to minimize the cost function by varying the
|
|
150
|
-
ansatz parameters. The optimizer returns a tuple containing the optimal cost and the optimal
|
|
151
|
-
parameters. A VQEResult object is then created using these values.
|
|
152
|
-
|
|
153
|
-
Args:
|
|
154
|
-
backend (DigitalBackend): The backend for executing quantum circuits.
|
|
155
|
-
optimizer (Optimizer): The classical optimizer for tuning the ansatz parameters.
|
|
156
|
-
nshots (int, optional): The number of shots for each circuit execution. Defaults to 1000.
|
|
157
|
-
|
|
158
|
-
Returns:
|
|
159
|
-
VQEResult: An object containing the optimal cost and the optimal ansatz parameters.
|
|
160
|
-
"""
|
|
161
|
-
optimizer_result = optimizer.optimize(
|
|
162
|
-
lambda x: self.obtain_cost(x, backend=backend, nshots=nshots),
|
|
163
|
-
self._initial_params,
|
|
164
|
-
store_intermediate_results=store_intermediate_results,
|
|
165
|
-
)
|
|
166
|
-
return VQEResult(optimizer_result=optimizer_result)
|
qilisdk/extras/cuda/__init__.py
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# Copyright 2025 Qilimanjaro Quantum Tech
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
qilisdk/extras/qaas/__init__.py
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# Copyright 2025 Qilimanjaro Quantum Tech
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
qilisdk/extras/qaas/models.py
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
# Copyright 2025 Qilimanjaro Quantum Tech
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
from enum import Enum
|
|
16
|
-
|
|
17
|
-
from pydantic import BaseModel, ConfigDict, Field
|
|
18
|
-
|
|
19
|
-
from qilisdk.analog import Hamiltonian, QuantumObject, Schedule, TimeEvolution
|
|
20
|
-
from qilisdk.analog.hamiltonian import PauliOperator
|
|
21
|
-
from qilisdk.common.optimizer import Optimizer
|
|
22
|
-
from qilisdk.digital import VQE, Circuit
|
|
23
|
-
from qilisdk.yaml import yaml
|
|
24
|
-
|
|
25
|
-
from .qaas_analog_result import QaaSAnalogResult
|
|
26
|
-
from .qaas_digital_result import QaaSDigitalResult
|
|
27
|
-
from .qaas_time_evolution_result import QaaSTimeEvolutionResult
|
|
28
|
-
from .qaas_vqe_result import QaaSVQEResult
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
class QaaSModel(BaseModel):
|
|
32
|
-
model_config = ConfigDict(validate_by_name=True, validate_by_alias=True, arbitrary_types_allowed=True)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class LoginPayload(BaseModel): ...
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
class Token(QaaSModel):
|
|
39
|
-
"""
|
|
40
|
-
Represents the structure of the login response:
|
|
41
|
-
{
|
|
42
|
-
"accessToken": "...",
|
|
43
|
-
"expiresIn": 123456789,
|
|
44
|
-
"issuedAt": "123456789",
|
|
45
|
-
"refreshToken": "...",
|
|
46
|
-
"tokenType": "bearer"
|
|
47
|
-
}
|
|
48
|
-
"""
|
|
49
|
-
|
|
50
|
-
access_token: str = Field(alias="accessToken")
|
|
51
|
-
expires_in: int = Field(alias="expiresIn")
|
|
52
|
-
issued_at: str = Field(alias="issuedAt")
|
|
53
|
-
refresh_token: str = Field(alias="refreshToken")
|
|
54
|
-
token_type: str = Field(alias="tokenType")
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
class DeviceStatus(str, Enum):
|
|
58
|
-
"""Device status typing for posting"""
|
|
59
|
-
|
|
60
|
-
ONLINE = "online"
|
|
61
|
-
MAINTENANCE = "maintenance"
|
|
62
|
-
OFFLINE = "offline"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
class DeviceType(str, Enum):
|
|
66
|
-
"""Device type"""
|
|
67
|
-
|
|
68
|
-
QUANTUM_DIGITAL = "quantum_device"
|
|
69
|
-
QUANTUM_ANALOG = "quantum_analog_device"
|
|
70
|
-
SIMULATOR = "simulator_device"
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
@yaml.register_class
|
|
74
|
-
class Device(QaaSModel):
|
|
75
|
-
id: int = Field(...)
|
|
76
|
-
name: str = Field(...)
|
|
77
|
-
status: DeviceStatus = Field(...)
|
|
78
|
-
type: DeviceType = Field(...)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
class ExecutePayloadType(str, Enum):
|
|
82
|
-
DIGITAL = "digital"
|
|
83
|
-
ANALOG = "analog"
|
|
84
|
-
VQE = "vqe"
|
|
85
|
-
TIME_EVOLUTION = "time_evolution"
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
@yaml.register_class
|
|
89
|
-
class DigitalPayload(QaaSModel):
|
|
90
|
-
circuit: Circuit = Field(...)
|
|
91
|
-
nshots: int = Field(...)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
@yaml.register_class
|
|
95
|
-
class AnalogPayload(QaaSModel):
|
|
96
|
-
schedule: Schedule = Field(...)
|
|
97
|
-
initial_state: QuantumObject = Field(...)
|
|
98
|
-
observables: list[PauliOperator | Hamiltonian] = Field(...)
|
|
99
|
-
store_intermediate_results: bool = Field(...)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
@yaml.register_class
|
|
103
|
-
class VQEPayload(QaaSModel):
|
|
104
|
-
vqe: VQE = Field(...)
|
|
105
|
-
optimizer: Optimizer = Field(...)
|
|
106
|
-
nshots: int = Field(...)
|
|
107
|
-
store_intermediate_results: bool = Field(...)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
@yaml.register_class
|
|
111
|
-
class TimeEvolutionPayload(QaaSModel):
|
|
112
|
-
time_evolution: TimeEvolution = Field()
|
|
113
|
-
store_intermediate_results: bool = Field()
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
@yaml.register_class
|
|
117
|
-
class ExecutePayload(QaaSModel):
|
|
118
|
-
type: ExecutePayloadType = Field(...)
|
|
119
|
-
device_id: int = Field(...)
|
|
120
|
-
digital_payload: DigitalPayload | None = None
|
|
121
|
-
analog_payload: AnalogPayload | None = None
|
|
122
|
-
vqe_payload: VQEPayload | None = None
|
|
123
|
-
time_evolution_payload: TimeEvolutionPayload | None = None
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
@yaml.register_class
|
|
127
|
-
class ExecuteResponse(QaaSModel):
|
|
128
|
-
type: ExecutePayloadType = Field(...)
|
|
129
|
-
digital_result: QaaSDigitalResult | None = None
|
|
130
|
-
analog_result: QaaSAnalogResult | None = None
|
|
131
|
-
vqe_result: QaaSVQEResult | None = None
|
|
132
|
-
time_evolution_result: QaaSTimeEvolutionResult | None = None
|