classiq 0.33.0__py3-none-any.whl → 0.34.0__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.
- classiq/_internals/api_wrapper.py +9 -20
- classiq/_internals/jobs.py +9 -2
- classiq/executor.py +3 -10
- classiq/interface/_version.py +1 -1
- classiq/interface/backend/backend_preferences.py +17 -0
- classiq/interface/backend/pydantic_backend.py +8 -0
- classiq/interface/backend/quantum_backend_providers.py +13 -1
- classiq/interface/chemistry/ground_state_problem.py +1 -1
- classiq/interface/chemistry/operator.py +198 -0
- classiq/interface/executor/execution_request.py +2 -12
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/atomic_quantum_functions.py +2 -2
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/std_lib_functions.py +20 -110
- classiq/interface/generator/generated_circuit.py +8 -44
- classiq/interface/generator/generated_circuit_data.py +2 -11
- classiq/interface/generator/model/preferences/preferences.py +2 -2
- classiq/interface/generator/quantum_function_call.py +1 -1
- classiq/interface/hardware.py +1 -0
- classiq/interface/ide/show.py +1 -14
- classiq/interface/model/quantum_function_call.py +9 -339
- classiq/interface/model/quantum_statement.py +3 -2
- classiq/interface/server/routes.py +5 -6
- classiq/model/function_handler.pyi +88 -88
- classiq/qmod/declaration_inferrer.py +34 -17
- classiq/qmod/model_state_container.py +6 -3
- classiq/qmod/qmod_builtins.py +892 -4
- classiq/qmod/qmod_parameter.py +24 -8
- classiq/qmod/quantum_expandable.py +6 -2
- classiq/qmod/quantum_function.py +9 -9
- {classiq-0.33.0.dist-info → classiq-0.34.0.dist-info}/METADATA +1 -1
- {classiq-0.33.0.dist-info → classiq-0.34.0.dist-info}/RECORD +31 -35
- classiq/interface/model/clients/__init__.py +0 -0
- classiq/interface/model/clients/qmod/__init__.py +0 -0
- classiq/interface/model/clients/qmod/qmod_builtins.py +0 -905
- classiq/interface/model/semantics.py +0 -15
- {classiq-0.33.0.dist-info → classiq-0.34.0.dist-info}/WHEEL +0 -0
classiq/interface/generator/functions/core_lib_declarations/quantum_functions/std_lib_functions.py
CHANGED
@@ -7,17 +7,10 @@ from classiq.interface.model.quantum_function_declaration import (
|
|
7
7
|
QFT_STEP = QuantumFunctionDeclaration.parse_raw(
|
8
8
|
"""{
|
9
9
|
"name": "qft_step",
|
10
|
-
"param_decls": {
|
11
|
-
"num_qbits": {
|
12
|
-
"kind": "int"
|
13
|
-
}
|
14
|
-
},
|
10
|
+
"param_decls": {},
|
15
11
|
"port_declarations": {
|
16
|
-
"
|
17
|
-
"name": "
|
18
|
-
"size": {
|
19
|
-
"expr": "num_qbits"
|
20
|
-
},
|
12
|
+
"target": {
|
13
|
+
"name": "target",
|
21
14
|
"direction": "inout"
|
22
15
|
}
|
23
16
|
},
|
@@ -29,17 +22,10 @@ QFT_STEP = QuantumFunctionDeclaration.parse_raw(
|
|
29
22
|
QFT = QuantumFunctionDeclaration.parse_raw(
|
30
23
|
"""{
|
31
24
|
"name": "qft",
|
32
|
-
"param_decls": {
|
33
|
-
"num_qbits": {
|
34
|
-
"kind": "int"
|
35
|
-
}
|
36
|
-
},
|
25
|
+
"param_decls": {},
|
37
26
|
"port_declarations": {
|
38
|
-
"
|
39
|
-
"name": "
|
40
|
-
"size": {
|
41
|
-
"expr": "num_qbits"
|
42
|
-
},
|
27
|
+
"target": {
|
28
|
+
"name": "target",
|
43
29
|
"direction": "inout"
|
44
30
|
}
|
45
31
|
},
|
@@ -52,41 +38,22 @@ QPE = QuantumFunctionDeclaration.parse_raw(
|
|
52
38
|
"""{
|
53
39
|
"name": "qpe",
|
54
40
|
"param_decls": {
|
55
|
-
"
|
56
|
-
"kind": "int"
|
57
|
-
},
|
58
|
-
"qpe_reg_size": {
|
41
|
+
"precision": {
|
59
42
|
"kind": "int"
|
60
43
|
}
|
61
44
|
},
|
62
45
|
"port_declarations": {
|
63
|
-
"
|
64
|
-
"name": "
|
65
|
-
"size": {
|
66
|
-
"expr": "reg_size"
|
67
|
-
},
|
68
|
-
"direction": "inout"
|
69
|
-
},
|
70
|
-
"q": {
|
71
|
-
"name": "q",
|
46
|
+
"phase": {
|
47
|
+
"name": "phase",
|
72
48
|
"size": {
|
73
|
-
"expr": "
|
49
|
+
"expr": "precision"
|
74
50
|
},
|
75
|
-
"direction": "
|
51
|
+
"direction": "output"
|
76
52
|
}
|
77
53
|
},
|
78
54
|
"operand_declarations": {
|
79
|
-
"
|
80
|
-
"name": "
|
81
|
-
"port_declarations": {
|
82
|
-
"target": {
|
83
|
-
"name": "target",
|
84
|
-
"size": {
|
85
|
-
"expr": "reg_size"
|
86
|
-
},
|
87
|
-
"direction": "inout"
|
88
|
-
}
|
89
|
-
}
|
55
|
+
"unitary": {
|
56
|
+
"name": "unitary"
|
90
57
|
}
|
91
58
|
},
|
92
59
|
"positional_arg_declarations": []
|
@@ -97,9 +64,6 @@ SINGLE_PAULI = QuantumFunctionDeclaration.parse_raw(
|
|
97
64
|
"""{
|
98
65
|
"name": "single_pauli",
|
99
66
|
"param_decls": {
|
100
|
-
"reg_size": {
|
101
|
-
"kind": "int"
|
102
|
-
},
|
103
67
|
"slope": {
|
104
68
|
"kind": "real"
|
105
69
|
},
|
@@ -110,9 +74,6 @@ SINGLE_PAULI = QuantumFunctionDeclaration.parse_raw(
|
|
110
74
|
"port_declarations": {
|
111
75
|
"x": {
|
112
76
|
"name": "x",
|
113
|
-
"size": {
|
114
|
-
"expr": "reg_size"
|
115
|
-
},
|
116
77
|
"direction": "inout"
|
117
78
|
},
|
118
79
|
"q": {
|
@@ -150,12 +111,6 @@ LINEAR_PAULI_ROTATIONS = QuantumFunctionDeclaration.parse_raw(
|
|
150
111
|
"""{
|
151
112
|
"name": "linear_pauli_rotations",
|
152
113
|
"param_decls": {
|
153
|
-
"reg_size": {
|
154
|
-
"kind": "int"
|
155
|
-
},
|
156
|
-
"num_state_qubits": {
|
157
|
-
"kind": "int"
|
158
|
-
},
|
159
114
|
"bases": {
|
160
115
|
"kind": "list",
|
161
116
|
"element_type": {
|
@@ -178,16 +133,10 @@ LINEAR_PAULI_ROTATIONS = QuantumFunctionDeclaration.parse_raw(
|
|
178
133
|
"port_declarations": {
|
179
134
|
"x": {
|
180
135
|
"name": "x",
|
181
|
-
"size": {
|
182
|
-
"expr": "reg_size"
|
183
|
-
},
|
184
136
|
"direction": "inout"
|
185
137
|
},
|
186
138
|
"q": {
|
187
139
|
"name": "q",
|
188
|
-
"size": {
|
189
|
-
"expr": "num_state_qubits"
|
190
|
-
},
|
191
140
|
"direction": "inout"
|
192
141
|
}
|
193
142
|
},
|
@@ -380,17 +329,10 @@ GROVER_OPERATOR = QuantumFunctionDeclaration.parse_raw(
|
|
380
329
|
HADAMARD_TRANSFORM = QuantumFunctionDeclaration.parse_raw(
|
381
330
|
"""{
|
382
331
|
"name": "hadamard_transform",
|
383
|
-
"param_decls": {
|
384
|
-
"num_qubits": {
|
385
|
-
"kind": "int"
|
386
|
-
}
|
387
|
-
},
|
332
|
+
"param_decls": {},
|
388
333
|
"port_declarations": {
|
389
|
-
"
|
390
|
-
"name": "
|
391
|
-
"size": {
|
392
|
-
"expr": "num_qubits"
|
393
|
-
},
|
334
|
+
"target": {
|
335
|
+
"name": "target",
|
394
336
|
"direction": "inout"
|
395
337
|
}
|
396
338
|
},
|
@@ -402,17 +344,10 @@ HADAMARD_TRANSFORM = QuantumFunctionDeclaration.parse_raw(
|
|
402
344
|
APPLY_TO_ALL = QuantumFunctionDeclaration.parse_raw(
|
403
345
|
"""{
|
404
346
|
"name": "apply_to_all",
|
405
|
-
"param_decls": {
|
406
|
-
"num_qubits": {
|
407
|
-
"kind": "int"
|
408
|
-
}
|
409
|
-
},
|
347
|
+
"param_decls": {},
|
410
348
|
"port_declarations": {
|
411
|
-
"
|
412
|
-
"name": "
|
413
|
-
"size": {
|
414
|
-
"expr": "num_qubits"
|
415
|
-
},
|
349
|
+
"target": {
|
350
|
+
"name": "target",
|
416
351
|
"direction": "inout"
|
417
352
|
}
|
418
353
|
},
|
@@ -503,9 +438,6 @@ QAOA_MIXER_LAYER = QuantumFunctionDeclaration.parse_raw(
|
|
503
438
|
"""{
|
504
439
|
"name": "qaoa_mixer_layer",
|
505
440
|
"param_decls": {
|
506
|
-
"num_qubits": {
|
507
|
-
"kind": "int"
|
508
|
-
},
|
509
441
|
"b": {
|
510
442
|
"kind": "real"
|
511
443
|
}
|
@@ -513,9 +445,6 @@ QAOA_MIXER_LAYER = QuantumFunctionDeclaration.parse_raw(
|
|
513
445
|
"port_declarations": {
|
514
446
|
"target": {
|
515
447
|
"name": "target",
|
516
|
-
"size": {
|
517
|
-
"expr": "num_qubits"
|
518
|
-
},
|
519
448
|
"direction": "inout"
|
520
449
|
}
|
521
450
|
},
|
@@ -528,9 +457,6 @@ QAOA_COST_LAYER = QuantumFunctionDeclaration.parse_raw(
|
|
528
457
|
"""{
|
529
458
|
"name": "qaoa_cost_layer",
|
530
459
|
"param_decls": {
|
531
|
-
"num_qubits": {
|
532
|
-
"kind": "int"
|
533
|
-
},
|
534
460
|
"g": {
|
535
461
|
"kind": "real"
|
536
462
|
},
|
@@ -548,9 +474,6 @@ QAOA_COST_LAYER = QuantumFunctionDeclaration.parse_raw(
|
|
548
474
|
"port_declarations": {
|
549
475
|
"target": {
|
550
476
|
"name": "target",
|
551
|
-
"size": {
|
552
|
-
"expr": "num_qubits"
|
553
|
-
},
|
554
477
|
"direction": "inout"
|
555
478
|
}
|
556
479
|
},
|
@@ -563,9 +486,6 @@ QAOA_LAYER = QuantumFunctionDeclaration.parse_raw(
|
|
563
486
|
"""{
|
564
487
|
"name": "qaoa_layer",
|
565
488
|
"param_decls": {
|
566
|
-
"num_qubits": {
|
567
|
-
"kind": "int"
|
568
|
-
},
|
569
489
|
"g": {
|
570
490
|
"kind": "real"
|
571
491
|
},
|
@@ -586,9 +506,6 @@ QAOA_LAYER = QuantumFunctionDeclaration.parse_raw(
|
|
586
506
|
"port_declarations": {
|
587
507
|
"target": {
|
588
508
|
"name": "target",
|
589
|
-
"size": {
|
590
|
-
"expr": "num_qubits"
|
591
|
-
},
|
592
509
|
"direction": "inout"
|
593
510
|
}
|
594
511
|
},
|
@@ -600,17 +517,10 @@ QAOA_LAYER = QuantumFunctionDeclaration.parse_raw(
|
|
600
517
|
QAOA_INIT = QuantumFunctionDeclaration.parse_raw(
|
601
518
|
"""{
|
602
519
|
"name": "qaoa_init",
|
603
|
-
"param_decls": {
|
604
|
-
"num_qubits": {
|
605
|
-
"kind": "int"
|
606
|
-
}
|
607
|
-
},
|
520
|
+
"param_decls": {},
|
608
521
|
"port_declarations": {
|
609
522
|
"target": {
|
610
523
|
"name": "target",
|
611
|
-
"size": {
|
612
|
-
"expr": "num_qubits"
|
613
|
-
},
|
614
524
|
"direction": "inout"
|
615
525
|
}
|
616
526
|
},
|
@@ -1,8 +1,7 @@
|
|
1
|
-
import abc
|
2
1
|
import uuid
|
3
2
|
from datetime import datetime
|
4
3
|
from pathlib import Path
|
5
|
-
from typing import Dict, List,
|
4
|
+
from typing import Dict, List, Optional, Tuple, Union
|
6
5
|
|
7
6
|
import pydantic
|
8
7
|
from typing_extensions import TypeAlias
|
@@ -17,9 +16,7 @@ from classiq.interface.generator.circuit_code.types_and_constants import (
|
|
17
16
|
VENDOR_TO_INSTRUCTION_SET,
|
18
17
|
CodeAndSyntax,
|
19
18
|
)
|
20
|
-
from classiq.interface.generator.function_params import ArithmeticIODict
|
21
19
|
from classiq.interface.generator.generated_circuit_data import (
|
22
|
-
ExecutionCircuitData,
|
23
20
|
FunctionDebugInfo,
|
24
21
|
GeneratedCircuitData,
|
25
22
|
)
|
@@ -28,7 +25,6 @@ from classiq.interface.generator.model.model import ExecutionModel, SynthesisMod
|
|
28
25
|
from classiq.interface.generator.synthesis_metadata.synthesis_duration import (
|
29
26
|
SynthesisStepDurations,
|
30
27
|
)
|
31
|
-
from classiq.interface.helpers.pydantic_model_helpers import get_discriminator_field
|
32
28
|
from classiq.interface.helpers.versioned_model import VersionedModel
|
33
29
|
from classiq.interface.ide.ide_data import CircuitMetrics
|
34
30
|
|
@@ -55,12 +51,15 @@ def get_uuid_as_str() -> str:
|
|
55
51
|
return str(uuid.uuid4())
|
56
52
|
|
57
53
|
|
58
|
-
class
|
54
|
+
class GeneratedCircuit(VersionedModel, CircuitCodeInterface):
|
59
55
|
hardware_data: SynthesisHardwareData
|
60
|
-
data: Union[GeneratedCircuitData, ExecutionCircuitData]
|
61
56
|
initial_values: Optional[InitialConditions]
|
62
|
-
|
63
|
-
|
57
|
+
data: GeneratedCircuitData
|
58
|
+
model: SynthesisModel
|
59
|
+
transpiled_circuit: Optional[TranspiledCircuitData]
|
60
|
+
creation_time: str = pydantic.Field(default_factory=datetime.utcnow().isoformat)
|
61
|
+
synthesis_duration: Optional[SynthesisStepDurations]
|
62
|
+
debug_info: Optional[List[FunctionDebugInfo]]
|
64
63
|
program_id: str = pydantic.Field(default_factory=get_uuid_as_str)
|
65
64
|
|
66
65
|
def _hardware_agnostic_program_code(self) -> CodeAndSyntax:
|
@@ -135,41 +134,6 @@ class GeneratedCircuitBase(abc.ABC, VersionedModel, CircuitCodeInterface):
|
|
135
134
|
for name, init_value in initial_values.items()
|
136
135
|
}
|
137
136
|
|
138
|
-
@property
|
139
|
-
@abc.abstractmethod
|
140
|
-
def program_circuit(self) -> CircuitCodeInterface:
|
141
|
-
pass
|
142
|
-
|
143
|
-
@property
|
144
|
-
@abc.abstractmethod
|
145
|
-
def execution_model(self) -> ExecutionModel:
|
146
|
-
pass
|
147
|
-
|
148
|
-
|
149
|
-
class ExecutionCircuit(GeneratedCircuitBase):
|
150
|
-
circuit_type: Literal["execution"] = get_discriminator_field("execution")
|
151
|
-
data: ExecutionCircuitData
|
152
|
-
model: ExecutionModel
|
153
|
-
arithmetic_outputs: ArithmeticIODict = dict()
|
154
|
-
|
155
|
-
@property
|
156
|
-
def program_circuit(self) -> CircuitCodeInterface:
|
157
|
-
return self
|
158
|
-
|
159
|
-
@property
|
160
|
-
def execution_model(self) -> ExecutionModel:
|
161
|
-
return self.model
|
162
|
-
|
163
|
-
|
164
|
-
class GeneratedCircuit(GeneratedCircuitBase):
|
165
|
-
circuit_type: Literal["generated"] = get_discriminator_field("generated")
|
166
|
-
data: GeneratedCircuitData
|
167
|
-
model: SynthesisModel
|
168
|
-
transpiled_circuit: Optional[TranspiledCircuitData]
|
169
|
-
creation_time: str = pydantic.Field(default_factory=datetime.utcnow().isoformat)
|
170
|
-
synthesis_duration: Optional[SynthesisStepDurations]
|
171
|
-
debug_info: List[FunctionDebugInfo]
|
172
|
-
|
173
137
|
def save_results(self, filename: Optional[Union[str, Path]] = None) -> None:
|
174
138
|
"""
|
175
139
|
Saves generated circuit results as json.
|
@@ -83,26 +83,17 @@ class GeneratedFunction(pydantic.BaseModel):
|
|
83
83
|
)
|
84
84
|
|
85
85
|
|
86
|
-
class
|
86
|
+
class GeneratedCircuitData(pydantic.BaseModel):
|
87
87
|
width: int
|
88
88
|
circuit_parameters: List[ParameterName] = pydantic.Field(default_factory=list)
|
89
89
|
qubit_mapping: QubitMapping = pydantic.Field(default_factory=QubitMapping)
|
90
90
|
execution_data: Optional[ExecutionData] = pydantic.Field(default=None)
|
91
91
|
|
92
92
|
@classmethod
|
93
|
-
def from_empty_logic_flow(cls) -> "
|
93
|
+
def from_empty_logic_flow(cls) -> "GeneratedCircuitData":
|
94
94
|
return cls(width=0)
|
95
95
|
|
96
96
|
|
97
|
-
class ExecutionCircuitData(CircuitDataBase):
|
98
|
-
depth: Optional[int]
|
99
|
-
count_ops: Optional[Dict[str, int]]
|
100
|
-
|
101
|
-
|
102
|
-
class GeneratedCircuitData(CircuitDataBase):
|
103
|
-
pass
|
104
|
-
|
105
|
-
|
106
97
|
class FunctionDebugInfo(pydantic.BaseModel):
|
107
98
|
generated_function: Optional[GeneratedFunction]
|
108
99
|
children: List[Optional["FunctionDebugInfo"]]
|
@@ -89,9 +89,9 @@ class Preferences(pydantic.BaseModel, extra=pydantic.Extra.forbid):
|
|
89
89
|
description="Custom hardware settings which will be used during optimization. "
|
90
90
|
"This field is ignored if backend preferences are given.",
|
91
91
|
)
|
92
|
-
|
92
|
+
debug_mode: bool = pydantic.Field(
|
93
93
|
default=True,
|
94
|
-
description="
|
94
|
+
description="Add debug information to the synthesized result. "
|
95
95
|
"Setting this option to False can potentially speed up the synthesis, and is "
|
96
96
|
"recommended for executing iterative algorithms.",
|
97
97
|
)
|
classiq/interface/hardware.py
CHANGED
classiq/interface/ide/show.py
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
import re
|
2
|
-
from typing import Union
|
3
2
|
|
4
3
|
import pydantic
|
5
4
|
|
6
5
|
from classiq.interface.analyzer.result import QasmCode
|
7
|
-
from classiq.interface.generator.generated_circuit import ExecutionCircuit
|
8
6
|
|
9
7
|
from classiq import GeneratedCircuit
|
10
8
|
from classiq._internals.api_wrapper import ApiWrapper
|
@@ -26,22 +24,11 @@ qasm_show_interactive = syncify_function(qasm_show_interactive_async)
|
|
26
24
|
CANT_PARSE_QUANTUM_PROGRAM_MSG = (
|
27
25
|
"Can not parse quantum_program into GeneratedCircuit, \n"
|
28
26
|
)
|
29
|
-
CANT_SHOW_EXECUTION_CIRCUIT_MSG = (
|
30
|
-
"It looks like the flag `support_circuit_visualization` in the model preferences "
|
31
|
-
"has been turned off. \n"
|
32
|
-
"The resulting circuit does not support visualization. \n"
|
33
|
-
"Make sure to set the flag to True, the default setting, and try again."
|
34
|
-
)
|
35
|
-
_Circuit = Union[GeneratedCircuit, ExecutionCircuit]
|
36
27
|
|
37
28
|
|
38
29
|
def show(quantum_program: SerializedQuantumProgram) -> None:
|
39
30
|
try:
|
40
31
|
circuit = GeneratedCircuit.parse_raw(quantum_program)
|
41
32
|
except pydantic.error_wrappers.ValidationError as exc:
|
42
|
-
|
43
|
-
ExecutionCircuit.parse_raw(quantum_program)
|
44
|
-
raise ClassiqValueError(CANT_SHOW_EXECUTION_CIRCUIT_MSG) from None
|
45
|
-
except pydantic.error_wrappers.ValidationError:
|
46
|
-
raise ClassiqValueError(CANT_PARSE_QUANTUM_PROGRAM_MSG) from exc
|
33
|
+
raise ClassiqValueError(CANT_PARSE_QUANTUM_PROGRAM_MSG) from exc
|
47
34
|
circuit.show() # type: ignore[attr-defined]
|