qilisdk 0.1.4__py3-none-any.whl → 0.1.6__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.
Files changed (86) hide show
  1. qilisdk/__init__.py +11 -2
  2. qilisdk/__init__.pyi +2 -3
  3. qilisdk/_logging.py +135 -0
  4. qilisdk/_optionals.py +5 -7
  5. qilisdk/analog/__init__.py +3 -18
  6. qilisdk/analog/exceptions.py +2 -4
  7. qilisdk/analog/hamiltonian.py +455 -110
  8. qilisdk/analog/linear_schedule.py +121 -0
  9. qilisdk/analog/schedule.py +275 -79
  10. qilisdk/{extras → backends}/__init__.py +9 -4
  11. qilisdk/{common/model.py → backends/__init__.pyi} +3 -1
  12. qilisdk/backends/backend.py +117 -0
  13. qilisdk/{extras/cuda → backends}/cuda_backend.py +152 -159
  14. qilisdk/backends/qutip_backend.py +473 -0
  15. qilisdk/core/__init__.py +63 -0
  16. qilisdk/{common → core}/algorithm.py +2 -1
  17. qilisdk/{extras/qaas/qaas_settings.py → core/exceptions.py} +12 -6
  18. qilisdk/core/model.py +1034 -0
  19. qilisdk/core/parameterizable.py +75 -0
  20. qilisdk/core/qtensor.py +666 -0
  21. qilisdk/{common → core}/result.py +2 -1
  22. qilisdk/core/variables.py +1969 -0
  23. qilisdk/cost_functions/__init__.py +18 -0
  24. qilisdk/cost_functions/cost_function.py +77 -0
  25. qilisdk/cost_functions/model_cost_function.py +145 -0
  26. qilisdk/cost_functions/observable_cost_function.py +109 -0
  27. qilisdk/digital/__init__.py +3 -22
  28. qilisdk/digital/ansatz.py +200 -160
  29. qilisdk/digital/circuit.py +81 -9
  30. qilisdk/digital/exceptions.py +12 -6
  31. qilisdk/digital/gates.py +229 -86
  32. qilisdk/{extras/qaas/qaas_analog_result.py → functionals/__init__.py} +14 -5
  33. qilisdk/functionals/functional.py +39 -0
  34. qilisdk/{common/backend.py → functionals/functional_result.py} +3 -1
  35. qilisdk/functionals/sampling.py +81 -0
  36. qilisdk/functionals/sampling_result.py +92 -0
  37. qilisdk/functionals/time_evolution.py +98 -0
  38. qilisdk/functionals/time_evolution_result.py +84 -0
  39. qilisdk/functionals/variational_program.py +80 -0
  40. qilisdk/functionals/variational_program_result.py +69 -0
  41. qilisdk/logging_config.yaml +16 -0
  42. qilisdk/{common → optimizers}/__init__.py +1 -1
  43. qilisdk/optimizers/optimizer.py +39 -0
  44. qilisdk/{common → optimizers}/optimizer_result.py +3 -12
  45. qilisdk/{common/optimizer.py → optimizers/scipy_optimizer.py} +10 -28
  46. qilisdk/settings.py +78 -0
  47. qilisdk/speqtrum/__init__.py +41 -0
  48. qilisdk/{extras → speqtrum}/__init__.pyi +3 -3
  49. qilisdk/speqtrum/experiments/__init__.py +25 -0
  50. qilisdk/speqtrum/experiments/experiment_functional.py +124 -0
  51. qilisdk/speqtrum/experiments/experiment_result.py +231 -0
  52. qilisdk/{extras/qaas → speqtrum}/keyring.py +8 -4
  53. qilisdk/speqtrum/speqtrum.py +587 -0
  54. qilisdk/speqtrum/speqtrum_models.py +467 -0
  55. qilisdk/utils/__init__.py +0 -14
  56. qilisdk/utils/openqasm2.py +1 -1
  57. qilisdk/utils/serialization.py +1 -1
  58. qilisdk/utils/visualization/PlusJakartaSans-SemiBold.ttf +0 -0
  59. qilisdk/utils/visualization/__init__.py +24 -0
  60. qilisdk/utils/visualization/circuit_renderers.py +781 -0
  61. qilisdk/utils/visualization/schedule_renderers.py +166 -0
  62. qilisdk/utils/visualization/style.py +154 -0
  63. qilisdk/utils/visualization/themes.py +76 -0
  64. qilisdk/yaml.py +126 -0
  65. {qilisdk-0.1.4.dist-info → qilisdk-0.1.6.dist-info}/METADATA +186 -140
  66. qilisdk-0.1.6.dist-info/RECORD +69 -0
  67. qilisdk/analog/algorithms.py +0 -111
  68. qilisdk/analog/analog_backend.py +0 -43
  69. qilisdk/analog/analog_result.py +0 -114
  70. qilisdk/analog/quantum_objects.py +0 -596
  71. qilisdk/digital/digital_algorithm.py +0 -20
  72. qilisdk/digital/digital_backend.py +0 -90
  73. qilisdk/digital/digital_result.py +0 -145
  74. qilisdk/digital/vqe.py +0 -166
  75. qilisdk/extras/cuda/__init__.py +0 -13
  76. qilisdk/extras/cuda/cuda_analog_result.py +0 -19
  77. qilisdk/extras/cuda/cuda_digital_result.py +0 -19
  78. qilisdk/extras/qaas/__init__.py +0 -13
  79. qilisdk/extras/qaas/models.py +0 -132
  80. qilisdk/extras/qaas/qaas_backend.py +0 -255
  81. qilisdk/extras/qaas/qaas_digital_result.py +0 -20
  82. qilisdk/extras/qaas/qaas_time_evolution_result.py +0 -20
  83. qilisdk/extras/qaas/qaas_vqe_result.py +0 -20
  84. qilisdk-0.1.4.dist-info/RECORD +0 -51
  85. {qilisdk-0.1.4.dist-info → qilisdk-0.1.6.dist-info}/WHEEL +0 -0
  86. {qilisdk-0.1.4.dist-info → qilisdk-0.1.6.dist-info}/licenses/LICENCE +0 -0
@@ -1,90 +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 abc import ABC, abstractmethod
15
- from enum import Enum
16
-
17
- from qilisdk.digital.circuit import Circuit
18
- from qilisdk.digital.digital_result import DigitalResult
19
-
20
-
21
- class DigitalSimulationMethod(str, Enum):
22
- """
23
- Enumeration of available simulation methods for the CUDA backend.
24
- """
25
-
26
- STATE_VECTOR = "state_vector"
27
- TENSOR_NETWORK = "tensor_network"
28
- MATRIX_PRODUCT_STATE = "matrix_product_state"
29
-
30
-
31
- class DigitalBackend(ABC):
32
- """
33
- Abstract base class for digital quantum circuit backends.
34
-
35
- This abstract class defines the interface for a digital backend capable of executing a
36
- quantum circuit. Subclasses must implement the execute method to run the circuit with a
37
- specified number of measurement shots and return a DigitalResult encapsulating the measurement
38
- outcomes.
39
- """
40
-
41
- def __init__(
42
- self, digital_simulation_method: DigitalSimulationMethod = DigitalSimulationMethod.STATE_VECTOR
43
- ) -> None:
44
- """
45
- Initialize the DigitalBackend.
46
-
47
- Args:
48
- simulation_method (DigitalSimulationMethod, optional): The simulation method to use.
49
- Options include STATE_VECTOR, TENSOR_NETWORK, or MATRIX_PRODUCT_STATE.
50
- Defaults to STATE_VECTOR.
51
- """
52
- self._digital_simulation_method = digital_simulation_method
53
-
54
- @property
55
- def digital_simulation_method(self) -> DigitalSimulationMethod:
56
- """
57
- Get the simulation method currently configured for the backend.
58
-
59
- Returns:
60
- SimulationMethod: The simulation method to be used for circuit execution.
61
- """
62
- return self._digital_simulation_method
63
-
64
- @digital_simulation_method.setter
65
- def digital_simulation_method(self, value: DigitalSimulationMethod) -> None:
66
- """
67
- Set the simulation method for the backend.
68
-
69
- Args:
70
- value (SimulationMethod): The simulation method to set. Options include
71
- STATE_VECTOR, TENSOR_NETWORK, or MATRIX_PRODUCT_STATE.
72
- """
73
- self._digital_simulation_method = value
74
-
75
- @abstractmethod
76
- def execute(self, circuit: Circuit, nshots: int = 1000) -> DigitalResult:
77
- """
78
- Execute the provided quantum circuit and return the measurement results.
79
-
80
- This method should run the given circuit for the specified number of measurement shots and
81
- produce a DigitalResult instance containing the raw measurement samples and any computed
82
- probabilities.
83
-
84
- Args:
85
- circuit (Circuit): The quantum circuit to be executed.
86
- nshots (int, optional): The number of measurement shots to perform. Defaults to 1000.
87
-
88
- Returns:
89
- DigitalResult: The result of executing the circuit, including measurement samples and probabilities.
90
- """
@@ -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)
@@ -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.
@@ -1,19 +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 qilisdk.analog.analog_result import AnalogResult
15
- from qilisdk.yaml import yaml
16
-
17
-
18
- @yaml.register_class
19
- class CudaAnalogResult(AnalogResult): ...
@@ -1,19 +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 qilisdk.digital.digital_result import DigitalResult
15
- from qilisdk.yaml import yaml
16
-
17
-
18
- @yaml.register_class
19
- class CudaDigitalResult(DigitalResult): ...
@@ -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.
@@ -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