classiq 0.87.0__py3-none-any.whl → 0.88.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.
Potentially problematic release.
This version of classiq might be problematic. Click here for more details.
- classiq/applications/__init__.py +1 -2
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +1 -1
- classiq/applications/hamiltonian/pauli_decomposition.py +1 -1
- classiq/evaluators/qmod_annotated_expression.py +30 -7
- classiq/evaluators/qmod_expression_visitors/qmod_expression_bwc.py +0 -5
- classiq/evaluators/qmod_expression_visitors/qmod_expression_evaluator.py +18 -11
- classiq/evaluators/qmod_expression_visitors/qmod_expression_renamer.py +14 -7
- classiq/evaluators/qmod_expression_visitors/qmod_expression_simplifier.py +39 -16
- classiq/evaluators/qmod_node_evaluators/attribute_evaluation.py +1 -1
- classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +18 -8
- classiq/evaluators/qmod_node_evaluators/compare_evaluation.py +8 -0
- classiq/evaluators/qmod_node_evaluators/constant_evaluation.py +4 -1
- classiq/evaluators/qmod_node_evaluators/numeric_attrs_utils.py +1 -1
- classiq/evaluators/qmod_node_evaluators/struct_instantiation_evaluation.py +1 -1
- classiq/evaluators/qmod_node_evaluators/subscript_evaluation.py +3 -3
- classiq/evaluators/qmod_node_evaluators/utils.py +1 -1
- classiq/evaluators/qmod_type_inference/classical_type_inference.py +4 -4
- classiq/evaluators/qmod_type_inference/quantum_type_inference.py +38 -0
- classiq/evaluators/type_type_match.py +1 -1
- classiq/execution/execution_session.py +17 -2
- classiq/interface/_version.py +1 -1
- classiq/interface/execution/primitives.py +1 -0
- classiq/interface/generator/application_apis/__init__.py +0 -1
- classiq/interface/generator/expressions/atomic_expression_functions.py +0 -2
- classiq/interface/generator/function_param_list.py +0 -4
- classiq/interface/generator/functions/classical_type.py +8 -0
- classiq/interface/generator/functions/type_name.py +6 -0
- classiq/interface/generator/transpiler_basis_gates.py +5 -1
- classiq/interface/generator/types/builtin_enum_declarations.py +0 -8
- classiq/interface/model/classical_if.py +16 -8
- classiq/interface/model/classical_parameter_declaration.py +4 -0
- classiq/interface/model/port_declaration.py +12 -0
- classiq/interface/model/quantum_function_declaration.py +12 -0
- classiq/interface/model/quantum_type.py +56 -0
- classiq/interface/pretty_print/expression_to_qmod.py +3 -17
- classiq/model_expansions/quantum_operations/allocate.py +1 -1
- classiq/model_expansions/quantum_operations/handle_evaluator.py +2 -8
- classiq/open_library/functions/__init__.py +1 -0
- classiq/open_library/functions/lcu.py +2 -2
- classiq/open_library/functions/state_preparation.py +47 -5
- classiq/qmod/builtins/__init__.py +0 -3
- classiq/qmod/builtins/classical_functions.py +0 -28
- classiq/qmod/builtins/enums.py +24 -18
- classiq/qmod/builtins/functions/__init__.py +0 -5
- classiq/qmod/builtins/operations.py +142 -0
- classiq/qmod/builtins/structs.py +0 -11
- classiq/qmod/native/pretty_printer.py +1 -1
- classiq/qmod/pretty_print/expression_to_python.py +3 -6
- classiq/qmod/pretty_print/pretty_printer.py +4 -1
- classiq/qmod/qmod_variable.py +94 -2
- classiq/qmod/semantics/annotation/call_annotation.py +4 -2
- classiq/qmod/semantics/annotation/qstruct_annotator.py +20 -5
- {classiq-0.87.0.dist-info → classiq-0.88.0.dist-info}/METADATA +3 -3
- {classiq-0.87.0.dist-info → classiq-0.88.0.dist-info}/RECORD +55 -67
- classiq/applications/finance/__init__.py +0 -15
- classiq/interface/finance/__init__.py +0 -0
- classiq/interface/finance/finance_modelling_params.py +0 -11
- classiq/interface/finance/function_input.py +0 -102
- classiq/interface/finance/gaussian_model_input.py +0 -50
- classiq/interface/finance/log_normal_model_input.py +0 -40
- classiq/interface/finance/model_input.py +0 -22
- classiq/interface/generator/application_apis/finance_declarations.py +0 -108
- classiq/interface/generator/expressions/enums/__init__.py +0 -0
- classiq/interface/generator/expressions/enums/finance_functions.py +0 -12
- classiq/interface/generator/finance.py +0 -107
- classiq/qmod/builtins/functions/finance.py +0 -34
- {classiq-0.87.0.dist-info → classiq-0.88.0.dist-info}/WHEEL +0 -0
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
from collections.abc import Mapping
|
|
2
|
-
from enum import Enum
|
|
3
|
-
|
|
4
|
-
from classiq.interface.generator.expressions.expression import Expression
|
|
5
|
-
from classiq.interface.generator.functions.classical_function_declaration import (
|
|
6
|
-
ClassicalFunctionDeclaration,
|
|
7
|
-
)
|
|
8
|
-
from classiq.interface.generator.functions.classical_type import Real
|
|
9
|
-
from classiq.interface.generator.functions.port_declaration import (
|
|
10
|
-
PortDeclarationDirection,
|
|
11
|
-
)
|
|
12
|
-
from classiq.interface.generator.functions.type_modifier import TypeModifier
|
|
13
|
-
from classiq.interface.generator.functions.type_name import Struct
|
|
14
|
-
from classiq.interface.model.classical_parameter_declaration import (
|
|
15
|
-
ClassicalParameterDeclaration,
|
|
16
|
-
)
|
|
17
|
-
from classiq.interface.model.port_declaration import PortDeclaration
|
|
18
|
-
from classiq.interface.model.quantum_function_declaration import (
|
|
19
|
-
NamedParamsQuantumFunctionDeclaration,
|
|
20
|
-
)
|
|
21
|
-
from classiq.interface.model.quantum_type import QuantumBit, QuantumBitvector
|
|
22
|
-
|
|
23
|
-
FUNCTION_PORT_NAME = "func_port"
|
|
24
|
-
OBJECTIVE_PORT_NAME = "obj_port"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
class FinanceModelType(Enum):
|
|
28
|
-
LogNormal = "log_normal"
|
|
29
|
-
Gaussian = "gaussian"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
FINANCE_FUNCTION_PORT_SIZE_MAPPING: Mapping[FinanceModelType, str] = {
|
|
33
|
-
FinanceModelType.Gaussian: "get_field(finance_model, 'num_qubits') + get_field(get_field(finance_model, 'rhos'), 'len') + floor(log(sum(get_field(finance_model, 'loss')), 2)) + 1",
|
|
34
|
-
FinanceModelType.LogNormal: "get_field(finance_model, 'num_qubits')",
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def _generate_finance_function(
|
|
39
|
-
finance_model: FinanceModelType,
|
|
40
|
-
) -> NamedParamsQuantumFunctionDeclaration:
|
|
41
|
-
return NamedParamsQuantumFunctionDeclaration(
|
|
42
|
-
name=f"{finance_model.value}_finance",
|
|
43
|
-
positional_arg_declarations=[
|
|
44
|
-
ClassicalParameterDeclaration(
|
|
45
|
-
name="finance_model",
|
|
46
|
-
classical_type=Struct(name=f"{finance_model.name}Model"),
|
|
47
|
-
),
|
|
48
|
-
ClassicalParameterDeclaration(
|
|
49
|
-
name="finance_function", classical_type=Struct(name="FinanceFunction")
|
|
50
|
-
),
|
|
51
|
-
PortDeclaration(
|
|
52
|
-
name=FUNCTION_PORT_NAME,
|
|
53
|
-
quantum_type=QuantumBitvector(
|
|
54
|
-
length=Expression(
|
|
55
|
-
expr=FINANCE_FUNCTION_PORT_SIZE_MAPPING[finance_model]
|
|
56
|
-
)
|
|
57
|
-
),
|
|
58
|
-
direction=PortDeclarationDirection.Inout,
|
|
59
|
-
type_modifier=TypeModifier.Mutable,
|
|
60
|
-
),
|
|
61
|
-
PortDeclaration(
|
|
62
|
-
name=OBJECTIVE_PORT_NAME,
|
|
63
|
-
quantum_type=QuantumBit(),
|
|
64
|
-
direction=PortDeclarationDirection.Inout,
|
|
65
|
-
type_modifier=TypeModifier.Mutable,
|
|
66
|
-
),
|
|
67
|
-
],
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
LOG_NORMAL_FINANCE_FUNCTION = _generate_finance_function(FinanceModelType.LogNormal)
|
|
72
|
-
|
|
73
|
-
GAUSSIAN_FINANCE_FUNCTION = _generate_finance_function(FinanceModelType.Gaussian)
|
|
74
|
-
|
|
75
|
-
LOG_NORMAL_FINANCE_POST_PROCESS = ClassicalFunctionDeclaration(
|
|
76
|
-
name="log_normal_finance_post_process",
|
|
77
|
-
positional_parameters=[
|
|
78
|
-
ClassicalParameterDeclaration(
|
|
79
|
-
name="finance_model", classical_type=Struct(name="LogNormalModel")
|
|
80
|
-
),
|
|
81
|
-
ClassicalParameterDeclaration(
|
|
82
|
-
name="estimation_method", classical_type=Struct(name="FinanceFunction")
|
|
83
|
-
),
|
|
84
|
-
ClassicalParameterDeclaration(name="probability", classical_type=Real()),
|
|
85
|
-
],
|
|
86
|
-
return_type=Real(),
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
GAUSSIAN_FINANCE_POST_PROCESS = ClassicalFunctionDeclaration(
|
|
90
|
-
name="gaussian_finance_post_process",
|
|
91
|
-
positional_parameters=[
|
|
92
|
-
ClassicalParameterDeclaration(
|
|
93
|
-
name="finance_model", classical_type=Struct(name="GaussianModel")
|
|
94
|
-
),
|
|
95
|
-
ClassicalParameterDeclaration(
|
|
96
|
-
name="estimation_method", classical_type=Struct(name="FinanceFunction")
|
|
97
|
-
),
|
|
98
|
-
ClassicalParameterDeclaration(name="probability", classical_type=Real()),
|
|
99
|
-
],
|
|
100
|
-
return_type=Real(),
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
__all__ = [
|
|
104
|
-
"GAUSSIAN_FINANCE_FUNCTION",
|
|
105
|
-
"GAUSSIAN_FINANCE_POST_PROCESS",
|
|
106
|
-
"LOG_NORMAL_FINANCE_FUNCTION",
|
|
107
|
-
"LOG_NORMAL_FINANCE_POST_PROCESS",
|
|
108
|
-
]
|
|
File without changes
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
from classiq.interface.generator.types.builtin_enum_declarations import (
|
|
2
|
-
FinanceFunctionType,
|
|
3
|
-
)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def get_finance_function_dict() -> dict[str, "FinanceFunctionType"]:
|
|
7
|
-
return {
|
|
8
|
-
"var": FinanceFunctionType.VAR,
|
|
9
|
-
"expected shortfall": FinanceFunctionType.SHORTFALL,
|
|
10
|
-
"x**2": FinanceFunctionType.X_SQUARE,
|
|
11
|
-
"european call option": FinanceFunctionType.EUROPEAN_CALL_OPTION,
|
|
12
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from typing import Union
|
|
4
|
-
|
|
5
|
-
import pydantic
|
|
6
|
-
|
|
7
|
-
from classiq.interface.finance.function_input import FinanceFunctionInput
|
|
8
|
-
from classiq.interface.finance.gaussian_model_input import GaussianModelInput
|
|
9
|
-
from classiq.interface.finance.log_normal_model_input import LogNormalModelInput
|
|
10
|
-
from classiq.interface.generator import function_params
|
|
11
|
-
from classiq.interface.generator.arith.register_user_input import RegisterUserInput
|
|
12
|
-
from classiq.interface.generator.function_params import DEFAULT_ZERO_NAME
|
|
13
|
-
|
|
14
|
-
FUNCTION_INPUT_NAME = "function_in"
|
|
15
|
-
FUNCTION_OUTPUT_NAME = "function_out"
|
|
16
|
-
OBJECTIVE_INPUT_NAME = "objective_in"
|
|
17
|
-
OBJECTIVE_OUTPUT_NAME = "objective_out"
|
|
18
|
-
DEFAULT_POST_INPUT_NAME = "post_function_input"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class Finance(function_params.FunctionParams):
|
|
22
|
-
model: Union[GaussianModelInput, LogNormalModelInput] = pydantic.Field(
|
|
23
|
-
description="Load a financial model", discriminator="kind"
|
|
24
|
-
)
|
|
25
|
-
finance_function: FinanceFunctionInput = pydantic.Field(
|
|
26
|
-
description="The finance function to solve the model"
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
def _create_ios(self) -> None:
|
|
30
|
-
finance_model = FinanceModels(model=self.model)
|
|
31
|
-
# 1 for the objective qubit
|
|
32
|
-
function_size = sum(
|
|
33
|
-
reg.size for reg in finance_model._outputs.values() if reg is not None
|
|
34
|
-
)
|
|
35
|
-
self._inputs = {
|
|
36
|
-
FUNCTION_INPUT_NAME: RegisterUserInput(
|
|
37
|
-
name=FUNCTION_INPUT_NAME, size=function_size
|
|
38
|
-
),
|
|
39
|
-
OBJECTIVE_INPUT_NAME: RegisterUserInput(name=OBJECTIVE_INPUT_NAME, size=1),
|
|
40
|
-
}
|
|
41
|
-
self._outputs = {
|
|
42
|
-
FUNCTION_OUTPUT_NAME: RegisterUserInput(
|
|
43
|
-
name=FUNCTION_OUTPUT_NAME, size=function_size
|
|
44
|
-
),
|
|
45
|
-
OBJECTIVE_OUTPUT_NAME: RegisterUserInput(
|
|
46
|
-
name=OBJECTIVE_OUTPUT_NAME, size=1
|
|
47
|
-
),
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
DEFAULT_INPUT_NAME = "in"
|
|
52
|
-
DEFAULT_OUTPUT_NAME = "out"
|
|
53
|
-
DEFAULT_BERNOULLI_OUTPUT_NAME = "bernoulli_random_variables"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
class FinanceModels(function_params.FunctionParams):
|
|
57
|
-
model: Union[GaussianModelInput, LogNormalModelInput] = pydantic.Field(
|
|
58
|
-
description="Load a financial model"
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
def _create_ios(self) -> None:
|
|
62
|
-
self._outputs = {
|
|
63
|
-
DEFAULT_OUTPUT_NAME: RegisterUserInput(
|
|
64
|
-
name=DEFAULT_OUTPUT_NAME, size=self.model.num_output_qubits
|
|
65
|
-
)
|
|
66
|
-
}
|
|
67
|
-
if isinstance(self.model, GaussianModelInput):
|
|
68
|
-
self._inputs = {
|
|
69
|
-
DEFAULT_INPUT_NAME: RegisterUserInput(
|
|
70
|
-
name=DEFAULT_INPUT_NAME, size=self.model.num_bernoulli_qubits
|
|
71
|
-
)
|
|
72
|
-
}
|
|
73
|
-
self._create_zero_input_registers(
|
|
74
|
-
{DEFAULT_ZERO_NAME: self.model.num_output_qubits}
|
|
75
|
-
)
|
|
76
|
-
self._outputs[DEFAULT_BERNOULLI_OUTPUT_NAME] = RegisterUserInput(
|
|
77
|
-
name=DEFAULT_BERNOULLI_OUTPUT_NAME,
|
|
78
|
-
size=self.model.num_bernoulli_qubits,
|
|
79
|
-
)
|
|
80
|
-
elif isinstance(self.model, LogNormalModelInput):
|
|
81
|
-
self._inputs = {
|
|
82
|
-
DEFAULT_INPUT_NAME: RegisterUserInput(
|
|
83
|
-
name=DEFAULT_INPUT_NAME, size=self.model.num_model_qubits
|
|
84
|
-
)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
class FinancePayoff(function_params.FunctionParams):
|
|
89
|
-
finance_function: FinanceFunctionInput = pydantic.Field(
|
|
90
|
-
description="The finance function to solve the model"
|
|
91
|
-
)
|
|
92
|
-
num_qubits: pydantic.PositiveInt
|
|
93
|
-
distribution_range: tuple[float, float]
|
|
94
|
-
|
|
95
|
-
def _create_ios(self) -> None:
|
|
96
|
-
self._inputs = {
|
|
97
|
-
DEFAULT_INPUT_NAME: RegisterUserInput(
|
|
98
|
-
name=DEFAULT_INPUT_NAME, size=self.num_qubits
|
|
99
|
-
)
|
|
100
|
-
}
|
|
101
|
-
self._create_zero_input_registers({DEFAULT_ZERO_NAME: 1})
|
|
102
|
-
self._outputs = {
|
|
103
|
-
DEFAULT_OUTPUT_NAME: RegisterUserInput(name=DEFAULT_OUTPUT_NAME, size=1),
|
|
104
|
-
DEFAULT_POST_INPUT_NAME: RegisterUserInput(
|
|
105
|
-
name=DEFAULT_INPUT_NAME, size=self.num_qubits
|
|
106
|
-
),
|
|
107
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
from typing import Literal
|
|
2
|
-
|
|
3
|
-
from classiq.qmod.builtins.structs import (
|
|
4
|
-
FinanceFunction,
|
|
5
|
-
GaussianModel,
|
|
6
|
-
LogNormalModel,
|
|
7
|
-
)
|
|
8
|
-
from classiq.qmod.qfunc import qfunc
|
|
9
|
-
from classiq.qmod.qmod_variable import QArray, QBit
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
@qfunc(external=True)
|
|
13
|
-
def log_normal_finance(
|
|
14
|
-
finance_model: LogNormalModel,
|
|
15
|
-
finance_function: FinanceFunction,
|
|
16
|
-
func_port: QArray[QBit, Literal["get_field(finance_model, 'num_qubits')"]],
|
|
17
|
-
obj_port: QBit,
|
|
18
|
-
) -> None:
|
|
19
|
-
pass
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
@qfunc(external=True)
|
|
23
|
-
def gaussian_finance(
|
|
24
|
-
finance_model: GaussianModel,
|
|
25
|
-
finance_function: FinanceFunction,
|
|
26
|
-
func_port: QArray[
|
|
27
|
-
QBit,
|
|
28
|
-
Literal[
|
|
29
|
-
"get_field(finance_model, 'num_qubits') + get_field(get_field(finance_model, 'rhos'), 'len') + floor(log(sum(get_field(finance_model, 'loss')), 2)) + 1"
|
|
30
|
-
],
|
|
31
|
-
],
|
|
32
|
-
obj_port: QBit,
|
|
33
|
-
) -> None:
|
|
34
|
-
pass
|
|
File without changes
|