Optimization Data Interface
IndexSets (ixmp4.data.optimization.indexset)
Data Transfer Object
- class ixmp4.data.optimization.indexset.dto.IndexSet(*, created_at: datetime | None, created_by: str | None, id: int, name: str, run__id: int, data: list[int] | list[float] | list[str], data_type: Type | None)
Bases:
BaseModel,HasCreationInfoOptimization index set model.
- model_config = {'from_attributes': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Service
- class ixmp4.data.optimization.indexset.service.IndexSetService(transport: Transport)
Bases:
DocsService,GetByIdService- executor: SessionExecutor
- items: ItemRepository
- data: IndexSetDataItemRepository
- pandas: PandasRepository
- versions: VersionRepository
- equations: ItemRepository
- parameters: ItemRepository
- tables: ItemRepository
- variables: ItemRepository
- create(run_id: int, name: str) IndexSet
Creates an indexset.
- Parameters:
run_id (int) – The id of the
ixmp4.data.run.dto.Runfor which this IndexSet is defined.name (str) – The name of the IndexSet.
- Raises:
ixmp4.data.optimization.indexset.exceptions.IndexSetNotUnique – If the indexset is not unique.
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
The created indexset.
- Return type:
- create_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, run_id: int, name: str) None
- get(run_id: int, name: str) IndexSet
Retrieves an indexset by its name and run_id.
- Parameters:
- Raises:
ixmp4.data.optimization.indexset.exceptions.IndexSetNotFound – If the indexset with name does not exist.
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
The retrieved indexset.
- Return type:
- get_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, run_id: int, name: str) None
- get_by_id(id: int) IndexSet
Retrieves an indexset by its id.
- Parameters:
id (int) – The integer id of the indexset.
- Raises:
ixmp4.data.optimization.indexset.exceptions.IndexSetNotFound – If the indexset with id does not exist.
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
The retrieved indexset.
- Return type:
- delete_by_id(id: int) None
Deletes an indexset.
- Parameters:
id (int) – The unique integer id of the indexset.
- Raises:
ixmp4.data.optimization.indexset.exceptions.IndexSetNotFound – If the indexset with id does not exist.
ixmp4.data.optimization.indexset.exceptions.IndexSetDeletionPrevented – If the indexset with id is used in the database, preventing it’s deletion.
Unauthorized – If the current user is not authorized to perform this action.
- delete_by_id_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, id: int) None
- data_to_data_list(data: float | int | str | List[float] | List[int] | List[str]) List[float] | List[int] | List[str]
- add_data(id: int, data: float | int | str | List[float] | List[int] | List[str]) None
Adds data to an existing IndexSet.
- add_data_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, id: int, data: float | int | str | List[float] | List[int] | List[str]) None
- remove_data(id: int, data: float | int | str | List[float] | List[int] | List[str], remove_dependent_data: bool = True) None
Removes data from an existing IndexSet.
- remove_data_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, id: int, data: float | int | str | List[float] | List[int] | List[str], remove_dependent_data: bool = True) None
- list(**kwargs: Unpack[IndexSetFilter]) list[IndexSet]
Lists indexsets by specified criteria.
- Parameters:
**kwargs (any) – Filter parameters as specified in
IndexSetFilter.- Raises:
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
List of indexsets.
- Return type:
list[
IndexSet]
- paginated_list(pagination: Pagination, **kwargs: Unpack[IndexSetFilter]) PaginatedResult[List[IndexSet]]
- tabulate(**kwargs: Unpack[IndexSetFilter]) WithJsonSchema(json_schema={'properties': {'index': {'anyOf': [{'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Index'}, 'columns': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Columns'}, 'dtypes': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Dtypes'}, 'data': {'anyOf': [{'items': {'items': {'anyOf': [{'type': 'boolean'}, {'type': 'integer'}, {'type': 'number'}, {'type': 'string'}, {'additionalProperties': True, 'type': 'object'}, {'items': {'type': 'number'}, 'type': 'array'}, {'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'format': 'date-time', 'type': 'string'}, {'type': 'null'}]}, 'type': 'array'}, 'type': 'array'}, {'type': 'null'}], 'title': 'Data'}}, 'required': ['data'], 'title': 'DataFrameTypeAdapter', 'type': 'object'}, mode=serialization)]
Tabulates indexsets by specified criteria.
- Parameters:
**kwargs (any) – Filter parameters as specified in
IndexSetFilter.- Returns:
- A data frame with the columns:
id
name
data
run__id
created_at
created_by
- Return type:
- paginated_tabulate(pagination: Pagination, **kwargs: Unpack[IndexSetFilter]) PaginatedResult[Annotated[DataFrame, PlainValidator, PlainSerializer, WithJsonSchema]]
Filters
Scalars (ixmp4.data.optimization.scalar)
Data Transfer Object
- class ixmp4.data.optimization.scalar.dto.Scalar(*, created_at: datetime | None, created_by: str | None, id: int, name: str, value: float, unit: Unit, unit__id: int, run__id: int)
Bases:
BaseModel,HasCreationInfoOptimization scalar data model.
- model_config = {'from_attributes': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Service
- class ixmp4.data.optimization.scalar.service.ScalarService(transport: Transport)
Bases:
DocsService,GetByIdService- executor: SessionExecutor
- items: ItemRepository
- pandas: PandasRepository
- versions: VersionRepository
- runs: ItemRepository
- indexsets: ItemRepository
- create(run_id: int, name: str, value: float | int, unit_name: str) Scalar
Creates a scalar.
- Parameters:
run_id (int) – The id of the
ixmp4.data.run.dto.Runfor which this Scalar is defined.name (str) – The name of the Scalar.
value (float) – The value of the Scalar.
unit_name (str) – The name of the
ixmp4.data.abstract.Unitfor which this Scalar is defined.
- Raises:
ScalarNotUnique – If the scalar is not unique.
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
The created scalar.
- Return type:
- create_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, run_id: int, name: str, value: float | int, unit_name: str) None
- get(run_id: int, name: str) Scalar
Retrieves a scalar by its name and run_id.
- Parameters:
- Raises:
ScalarNotFound – If the scalar with name does not exist.
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
The retrieved scalar.
- Return type:
- get_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, run_id: int, name: str) None
- get_by_id(id: int) Scalar
Retrieves a scalar by its id.
- Parameters:
id (int) – The integer id of the scalar.
- Raises:
ScalarNotFound – If the scalar with id does not exist.
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
The retrieved scalar.
- Return type:
- delete_by_id(id: int) None
Deletes a scalar.
- Parameters:
id (int) – The unique integer id of the scalar.
- Raises:
ScalarNotFound – If the scalar with id does not exist.
ScalarDeletionPrevented – If the scalar with id is used in the database, preventing it’s deletion.
Unauthorized – If the current user is not authorized to perform this action.
- delete_by_id_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, id: int) None
- update_by_id(id: int, value: float | int | None = None, unit_name: str | None = None) Scalar
Updates a Scalar.
- update_by_id_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, id: int, value: float | int | None = None, unit_name: str | None = None) None
- list(**kwargs: Unpack[ScalarFilter]) list[Scalar]
Lists scalars by specified criteria.
- Parameters:
**kwargs (any) – Filter scalars as specified in
ScalarFilter.- Raises:
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
List of scalars.
- Return type:
list[
Scalar]
- paginated_list(pagination: Pagination, **kwargs: Unpack[ScalarFilter]) PaginatedResult[List[Scalar]]
- tabulate(**kwargs: Unpack[ScalarFilter]) WithJsonSchema(json_schema={'properties': {'index': {'anyOf': [{'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Index'}, 'columns': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Columns'}, 'dtypes': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Dtypes'}, 'data': {'anyOf': [{'items': {'items': {'anyOf': [{'type': 'boolean'}, {'type': 'integer'}, {'type': 'number'}, {'type': 'string'}, {'additionalProperties': True, 'type': 'object'}, {'items': {'type': 'number'}, 'type': 'array'}, {'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'format': 'date-time', 'type': 'string'}, {'type': 'null'}]}, 'type': 'array'}, 'type': 'array'}, {'type': 'null'}], 'title': 'Data'}}, 'required': ['data'], 'title': 'DataFrameTypeAdapter', 'type': 'object'}, mode=serialization)]
Tabulates scalars by specified criteria.
- Parameters:
**kwargs (any) – Filter scalars as specified in
ScalarFilter.- Returns:
- A data frame with the columns:
id
name
- Return type:
- paginated_tabulate(pagination: Pagination, **kwargs: Unpack[ScalarFilter]) PaginatedResult[Annotated[DataFrame, PlainValidator, PlainSerializer, WithJsonSchema]]
Filters
Equations (ixmp4.data.optimization.equation)
Data Transfer Object
- class ixmp4.data.optimization.equation.dto.Equation(*, created_at: datetime | None, created_by: str | None, id: int, name: str, data: dict[str, list[float] | list[int] | list[str]], indexset_names: list[str] | None, column_names: list[str] | None, run__id: int)
Bases:
BaseModel,HasCreationInfoOptimization equation model.
- model_config = {'from_attributes': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Service
- class ixmp4.data.optimization.equation.service.EquationService(transport: Transport)
Bases:
DocsService,IndexSetAssociatedService- executor: SessionExecutor
- items: ItemRepository
- pandas: PandasRepository
- versions: VersionRepository
- associations: AssociationRepository
- indexsets: ItemRepository
- create(run_id: int, name: str, constrained_to_indexsets: list[str] | None = None, column_names: list[str] | None = None) Equation
Creates a equation.
Each column of the Equation needs to be constrained to an existing
ixmp4.data.abstract.optimization.IndexSet. These are specified by name and per default, these will be the column names. They can be overwritten by specifying column_names, which needs to specify a unique name for each column.- Parameters:
run_id (int) – The id of the
ixmp4.data.run.dto.Runfor which this Equation is defined.name (str) – The unique name of the Equation.
constrained_to_indexsets (list[str] | None = None) – List of
ixmp4.data.abstract.optimization.IndexSetnames that define the allowed contents of the Equation’s columns. If None, no data can be added beyond levels and marginals!column_names (list[str] | None = None) – Optional list of names to use as column names. If given, overwrites the names inferred from constrained_to_indexsets.
- Raises:
EquationNotUnique – If the equation is not unique.
OptimizationItemUsageError – If the equation arguments are not valid.
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
The created equation.
- Return type:
- create_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, run_id: int, name: str, constrained_to_indexsets: list[str] | None = None, column_names: list[str] | None = None) None
- get(run_id: int, name: str) Equation
Retrieves a equation by its name and run_id.
- Parameters:
- Raises:
EquationNotFound – If the equation with name does not exist.
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
The retrieved equation.
- Return type:
- get_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, run_id: int, name: str) None
- get_by_id(id: int) Equation
Retrieves a equation by its id.
- Parameters:
id (int) – The integer id of the equation.
- Raises:
EquationNotFound – If the equation with id does not exist.
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
The retrieved equation.
- Return type:
- delete_by_id(id: int) None
Deletes a equation.
- Parameters:
id (int) – The unique integer id of the equation.
- Raises:
EquationNotFound – If the equation with id does not exist.
EquationDeletionPrevented – If the equation with id is used in the database, preventing it’s deletion.
Unauthorized – If the current user is not authorized to perform this action.
- delete_by_id_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, id: int) None
- add_data(id: int, data: Any]) None
Adds data to an Equation.
The data will be validated with the linked constrained
ixmp4.data.abstract.optimization.IndexSet`s. For that, `data.keys()must correspond to the names of the Equation’s columns. Each column can only contain values that are in the linked IndexSet.data. Each row of entries must be unique. No values can be missing, None, or NaN. If data.keys() contains names already present in Equation.data, existing values will be overwritten.- Parameters:
id (int) – The id of the
ixmp4.data.abstract.optimization.Equation.data (dict[str, Any] | pandas.DataFrame) – The data to be added.
- Raises:
ixmp4.data.optimization.exceptions.OptimizationItemUsageError –
If values are missing,
None, orNaN- If values are not allowed based on constraints toIndexsets - If rows are not unique
Unauthorized – If the current user is not authorized to perform this action.
- Return type:
None
- add_data_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, id: int, data: Any]) None
- remove_data(id: int, data: Any] | None = None) None
Removes data from an Equation.
- Parameters:
id (int) – The id of the
ixmp4.data.abstract.optimization.Equation.data (dict[str, Any] | pandas.DataFrame, optional) – The data to be removed. If specified, remove only specific data. This must specify all indexed columns. All other keys/columns are ignored. Otherwise, remove all data (the default).
- Raises:
Unauthorized – If the current user is not authorized to perform this action.
- Return type:
None
- remove_data_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, id: int, data: Any] | None = None) None
- list(**kwargs: Unpack[EquationFilter]) list[Equation]
Lists equations by specified criteria.
- Parameters:
**kwargs (any) – Filter parameters as specified in
EquationFilter.- Raises:
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
List of equations.
- Return type:
list[
Equation]
- paginated_list(pagination: Pagination, **kwargs: Unpack[EquationFilter]) PaginatedResult[List[Equation]]
- tabulate(**kwargs: Unpack[EquationFilter]) WithJsonSchema(json_schema={'properties': {'index': {'anyOf': [{'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Index'}, 'columns': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Columns'}, 'dtypes': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Dtypes'}, 'data': {'anyOf': [{'items': {'items': {'anyOf': [{'type': 'boolean'}, {'type': 'integer'}, {'type': 'number'}, {'type': 'string'}, {'additionalProperties': True, 'type': 'object'}, {'items': {'type': 'number'}, 'type': 'array'}, {'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'format': 'date-time', 'type': 'string'}, {'type': 'null'}]}, 'type': 'array'}, 'type': 'array'}, {'type': 'null'}], 'title': 'Data'}}, 'required': ['data'], 'title': 'DataFrameTypeAdapter', 'type': 'object'}, mode=serialization)]
Tabulates equations by specified criteria.
- Parameters:
**kwargs (any) – Filter parameters as specified in
EquationFilter.- Returns:
- A data frame with the columns:
id
name
data
run__id
created_at
created_by
- Return type:
- paginated_tabulate(pagination: Pagination, **kwargs: Unpack[EquationFilter]) PaginatedResult[Annotated[DataFrame, PlainValidator, PlainSerializer, WithJsonSchema]]
Filters
Paramters (ixmp4.data.optimization.parameter)
Data Transfer Object
- class ixmp4.data.optimization.parameter.dto.Parameter(*, created_at: datetime | None, created_by: str | None, id: int, name: str, data: dict[str, Any], indexset_names: list[str], column_names: list[str] | None, run__id: int)
Bases:
BaseModel,HasCreationInfoOptimization parameter data model.
- model_config = {'from_attributes': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Service
- class ixmp4.data.optimization.parameter.service.ParameterService(transport: Transport)
Bases:
DocsService,IndexSetAssociatedService- executor: SessionExecutor
- items: ItemRepository
- pandas: PandasRepository
- versions: VersionRepository
- associations: AssociationRepository
- indexsets: ItemRepository
- create(run_id: int, name: str, constrained_to_indexsets: list[str], column_names: list[str] | None = None) Parameter
Creates a Parameter.
Each column of the Parameter needs to be constrained to an existing
ixmp4.data.abstract.optimization.IndexSet. These are specified by name and per default, these will be the column names. They can be overwritten by specifying column_names, which needs to specify a unique name for each column.- Parameters:
run_id (int) – The id of the
ixmp4.data.run.dto.Runfor which this Parameter is defined.name (str) – The unique name of the Parameter.
constrained_to_indexsets (list[str]) – List of
ixmp4.data.abstract.optimization.IndexSetnames that define the allowed contents of the Parameter’s columns.column_names (list[str] | None = None) – Optional list of names to use as column names. If given, overwrites the names inferred from constrained_to_indexsets.
- Raises:
ParameterNotUnique – If the parameter is not unique.
OptimizationItemUsageError – If the parameter arguments are not valid.
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
The created parameter.
- Return type:
- create_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, run_id: int, name: str, constrained_to_indexsets: list[str], column_names: list[str] | None = None) None
- get(run_id: int, name: str) Parameter
Retrieves a parameter by its name and run_id.
- Parameters:
- Raises:
ParameterNotFound – If the parameter with name does not exist.
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
The retrieved parameter.
- Return type:
- get_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, run_id: int, name: str) None
- get_by_id(id: int) Parameter
Retrieves a parameter by its id.
- Parameters:
id (int) – The integer id of the parameter.
- Raises:
ParameterNotFound – If the parameter with id does not exist.
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
The retrieved parameter.
- Return type:
- delete_by_id(id: int) None
Deletes a parameter.
- Parameters:
id (int) – The unique integer id of the parameter.
- Raises:
ParameterNotFound – If the parameter with id does not exist.
ParameterDeletionPrevented – If the parameter with id is used in the database, preventing its deletion.
Unauthorized – If the current user is not authorized to perform this action.
- delete_by_id_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, id: int) None
- add_data(id: int, data: dict[str, ~typing.Any] | ~typing.Annotated[~pandas.DataFrame, ~pydantic.functional_validators.PlainValidator(func=~ixmp4.data.dataframe.parse_df, json_schema_input_type=~typing.Any), ~pydantic.functional_serializers.PlainSerializer(func=~ixmp4.data.dataframe.serialize_df, return_type=dict, when_used=json), ~pydantic.json_schema.WithJsonSchema(json_schema={'properties': {'index': {'anyOf': [{'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Index'}, 'columns': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Columns'}, 'dtypes': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Dtypes'}, 'data': {'anyOf': [{'items': {'items': {'anyOf': [{'type': 'boolean'}, {'type': 'integer'}, {'type': 'number'}, {'type': 'string'}, {'additionalProperties': True, 'type': 'object'}, {'items': {'type': 'number'}, 'type': 'array'}, {'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'format': 'date-time', 'type': 'string'}, {'type': 'null'}]}, 'type': 'array'}, 'type': 'array'}, {'type': 'null'}], 'title': 'Data'}}, 'required': ['data'], 'title': 'DataFrameTypeAdapter', 'type': 'object'}, mode=serialization)]) None
Adds data to a Parameter.
The data will be validated with the linked constrained
ixmp4.data.abstract.optimization.IndexSet`s. For that, `data.keys()must correspond to the names of the Parameter’s columns. Each column can only contain values that are in the linked IndexSet.data. Each row of entries must be unique. No values can be missing, None, or NaN. If data.keys() contains names already present in Parameter.data, existing values will be overwritten.- Parameters:
id (int) – The id of the
ixmp4.data.abstract.optimization.Parameter.data (dict[str, Any] | pandas.DataFrame) – The data to be added.
- Raises:
ixmp4.core.exceptions.OptimizationDataValidationError –
If values are missing,
None, orNaN- If values are not allowed based on constraints toIndexsets - If rows are not unique
- Return type:
None
- add_data_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, id: int, data: dict[str, ~typing.Any] | ~typing.Annotated[~pandas.DataFrame, ~pydantic.functional_validators.PlainValidator(func=~ixmp4.data.dataframe.parse_df, json_schema_input_type=~typing.Any), ~pydantic.functional_serializers.PlainSerializer(func=~ixmp4.data.dataframe.serialize_df, return_type=dict, when_used=json), ~pydantic.json_schema.WithJsonSchema(json_schema={'properties': {'index': {'anyOf': [{'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Index'}, 'columns': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Columns'}, 'dtypes': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Dtypes'}, 'data': {'anyOf': [{'items': {'items': {'anyOf': [{'type': 'boolean'}, {'type': 'integer'}, {'type': 'number'}, {'type': 'string'}, {'additionalProperties': True, 'type': 'object'}, {'items': {'type': 'number'}, 'type': 'array'}, {'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'format': 'date-time', 'type': 'string'}, {'type': 'null'}]}, 'type': 'array'}, 'type': 'array'}, {'type': 'null'}], 'title': 'Data'}}, 'required': ['data'], 'title': 'DataFrameTypeAdapter', 'type': 'object'}, mode=serialization)]) None
- remove_data(id: int, data: Any] | None = None) None
Removes data from a Parameter.
- Parameters:
id (int) – The id of the
ixmp4.data.abstract.optimization.Parameter.data (dict[str, Any] | pandas.DataFrame) – The data to be removed. This must specify all indexed columns. All other keys/columns are ignored.
- Return type:
None
- remove_data_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, id: int, data: Any] | None = None) None
- list(**kwargs: Unpack[ParameterFilter]) list[Parameter]
Lists parameters by specified criteria.
- Parameters:
**kwargs (any) – Filter parameters as specified in
ParameterFilter.- Raises:
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
List of parameters.
- Return type:
list[
Parameter]
- paginated_list(pagination: Pagination, **kwargs: Unpack[ParameterFilter]) PaginatedResult[List[Parameter]]
- tabulate(**kwargs: Unpack[ParameterFilter]) WithJsonSchema(json_schema={'properties': {'index': {'anyOf': [{'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Index'}, 'columns': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Columns'}, 'dtypes': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Dtypes'}, 'data': {'anyOf': [{'items': {'items': {'anyOf': [{'type': 'boolean'}, {'type': 'integer'}, {'type': 'number'}, {'type': 'string'}, {'additionalProperties': True, 'type': 'object'}, {'items': {'type': 'number'}, 'type': 'array'}, {'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'format': 'date-time', 'type': 'string'}, {'type': 'null'}]}, 'type': 'array'}, 'type': 'array'}, {'type': 'null'}], 'title': 'Data'}}, 'required': ['data'], 'title': 'DataFrameTypeAdapter', 'type': 'object'}, mode=serialization)]
Tabulates parameters by specified criteria.
- Parameters:
**kwargs (any) – Filter parameters as specified in
ParameterFilter.- Returns:
- A data frame with the columns:
id
name
data
run__id
created_at
created_by
- Return type:
- paginated_tabulate(pagination: Pagination, **kwargs: Unpack[ParameterFilter]) PaginatedResult[Annotated[DataFrame, PlainValidator, PlainSerializer, WithJsonSchema]]
Filters
Tables (ixmp4.data.optimization.table)
Data Transfer Object
- class ixmp4.data.optimization.table.dto.Table(*, created_at: datetime | None, created_by: str | None, id: int, name: str, data: dict[str, list[float] | list[int] | list[str]], indexset_names: list[str], column_names: list[str] | None, run__id: int)
Bases:
BaseModel,HasCreationInfoOptimization table data model.
- model_config = {'from_attributes': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Service
- class ixmp4.data.optimization.table.service.TableService(transport: Transport)
Bases:
DocsService,IndexSetAssociatedService- executor: SessionExecutor
- items: ItemRepository
- pandas: PandasRepository
- versions: VersionRepository
- associations: AssociationRepository
- indexsets: ItemRepository
- runs: ItemRepository
- create(run_id: int, name: str, constrained_to_indexsets: list[str], column_names: list[str] | None = None) Table
Creates a table.
Each column of the Table needs to be constrained to an existing
ixmp4.data.abstract.optimization.IndexSet. These are specified by name and per default, these will be the column names. They can be overwritten by specifying column_names, which needs to specify a unique name for each column.- Parameters:
run_id (int) – The id of the
Runfor which this Table is defined.name (str) – The unique name of the Table.
constrained_to_indexsets (list[str]) – List of
IndexSetnames that define the allowed contents of the Table’s columns.column_names (list[str] | None = None) – Optional list of names to use as column names. If given, overwrites the names inferred from constrained_to_indexsets.
- Raises:
TableNotUnique – If the table is not unique.
OptimizationItemUsageError – If the table arguments are not valid.
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
The created table.
- Return type:
- create_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, run_id: int, name: str, constrained_to_indexsets: list[str], column_names: list[str] | None = None) None
- get(run_id: int, name: str) Table
Retrieves a table by its name and run_id.
- Parameters:
- Raises:
TableNotFound – If the table with name does not exist.
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
The retrieved table.
- Return type:
- get_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, run_id: int, name: str) None
- get_by_id(id: int) Table
Retrieves a table by its id.
- Parameters:
id (int) – The integer id of the table.
- Raises:
TableNotFound – If the table with id does not exist.
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
The retrieved table.
- Return type:
- delete_by_id(id: int) None
Deletes a table.
- Parameters:
id (int) – The unique integer id of the table.
- Raises:
TableNotFound – If the table with id does not exist.
TableDeletionPrevented – If the table with id is used in the database, preventing it’s deletion.
Unauthorized – If the current user is not authorized to perform this action.
- delete_by_id_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, id: int) None
- add_data(id: int, data: dict[str, ~typing.Any] | ~typing.Annotated[~pandas.DataFrame, ~pydantic.functional_validators.PlainValidator(func=~ixmp4.data.dataframe.parse_df, json_schema_input_type=~typing.Any), ~pydantic.functional_serializers.PlainSerializer(func=~ixmp4.data.dataframe.serialize_df, return_type=dict, when_used=json), ~pydantic.json_schema.WithJsonSchema(json_schema={'properties': {'index': {'anyOf': [{'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Index'}, 'columns': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Columns'}, 'dtypes': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Dtypes'}, 'data': {'anyOf': [{'items': {'items': {'anyOf': [{'type': 'boolean'}, {'type': 'integer'}, {'type': 'number'}, {'type': 'string'}, {'additionalProperties': True, 'type': 'object'}, {'items': {'type': 'number'}, 'type': 'array'}, {'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'format': 'date-time', 'type': 'string'}, {'type': 'null'}]}, 'type': 'array'}, 'type': 'array'}, {'type': 'null'}], 'title': 'Data'}}, 'required': ['data'], 'title': 'DataFrameTypeAdapter', 'type': 'object'}, mode=serialization)]) None
Adds data to a Table.
The data will be validated with the linked constrained
ixmp4.data.abstract.optimization.IndexSet`s. For that, `data.keys()must correspond to the names of the Table’s columns. Each column can only contain values that are in the linked IndexSet.data. Each row of entries must be unique. No values can be missing, None, or NaN. If data.keys() contains names already present in Table.data, existing values will be overwritten.- Parameters:
data (dict[str, Any] | pandas.DataFrame) – The data to be added.
- Raises:
OptimizationDataValidationError –
If values are missing,
None, orNaN- If values are not allowed based on constraints toIndexsets - If rows are not unique
- Return type:
None
- add_data_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, id: int, data: dict[str, ~typing.Any] | ~typing.Annotated[~pandas.DataFrame, ~pydantic.functional_validators.PlainValidator(func=~ixmp4.data.dataframe.parse_df, json_schema_input_type=~typing.Any), ~pydantic.functional_serializers.PlainSerializer(func=~ixmp4.data.dataframe.serialize_df, return_type=dict, when_used=json), ~pydantic.json_schema.WithJsonSchema(json_schema={'properties': {'index': {'anyOf': [{'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Index'}, 'columns': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Columns'}, 'dtypes': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Dtypes'}, 'data': {'anyOf': [{'items': {'items': {'anyOf': [{'type': 'boolean'}, {'type': 'integer'}, {'type': 'number'}, {'type': 'string'}, {'additionalProperties': True, 'type': 'object'}, {'items': {'type': 'number'}, 'type': 'array'}, {'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'format': 'date-time', 'type': 'string'}, {'type': 'null'}]}, 'type': 'array'}, 'type': 'array'}, {'type': 'null'}], 'title': 'Data'}}, 'required': ['data'], 'title': 'DataFrameTypeAdapter', 'type': 'object'}, mode=serialization)]) None
- remove_data(id: int, data: Any] | None = None) None
Removes data from a Table.
- Parameters:
id (int) – The id of the
ixmp4.data.abstract.optimization.Table.data (dict[str, Any] | pandas.DataFrame) – The data to be removed. This must specify all indexed columns. All other keys/columns are ignored.
- Return type:
None
- remove_data_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, id: int, data: Any] | None = None) None
- list(**kwargs: Unpack[TableFilter]) list[Table]
Lists tables by specified criteria.
- Parameters:
**kwargs (any) – Filter tables as specified in
TableFilter.- Raises:
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
List of tables.
- Return type:
list[
Table]
- paginated_list(pagination: Pagination, **kwargs: Unpack[TableFilter]) PaginatedResult[List[Table]]
- tabulate(**kwargs: Unpack[TableFilter]) WithJsonSchema(json_schema={'properties': {'index': {'anyOf': [{'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Index'}, 'columns': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Columns'}, 'dtypes': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Dtypes'}, 'data': {'anyOf': [{'items': {'items': {'anyOf': [{'type': 'boolean'}, {'type': 'integer'}, {'type': 'number'}, {'type': 'string'}, {'additionalProperties': True, 'type': 'object'}, {'items': {'type': 'number'}, 'type': 'array'}, {'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'format': 'date-time', 'type': 'string'}, {'type': 'null'}]}, 'type': 'array'}, 'type': 'array'}, {'type': 'null'}], 'title': 'Data'}}, 'required': ['data'], 'title': 'DataFrameTypeAdapter', 'type': 'object'}, mode=serialization)]
Tabulates tables by specified criteria.
- Parameters:
**kwargs (any) – Filter tables as specified in
TableFilter.- Returns:
- A data frame with the columns:
id
name
data
run__id
created_at
created_by
- Return type:
- paginated_tabulate(pagination: Pagination, **kwargs: Unpack[TableFilter]) PaginatedResult[Annotated[DataFrame, PlainValidator, PlainSerializer, WithJsonSchema]]
Filters
Variables (ixmp4.data.optimization.variable)
Data Transfer Object
- class ixmp4.data.optimization.variable.dto.Variable(*, created_at: datetime | None, created_by: str | None, id: int, name: str, data: dict[str, list[float] | list[int] | list[str]], indexset_names: list[str] | None, column_names: list[str] | None, run__id: int)
Bases:
BaseModel,HasCreationInfoOptimization variable data model.
- model_config = {'from_attributes': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Service
- class ixmp4.data.optimization.variable.service.VariableService(transport: Transport)
Bases:
DocsService,IndexSetAssociatedService- executor: SessionExecutor
- items: ItemRepository
- pandas: PandasRepository
- versions: VersionRepository
- associations: AssociationRepository
- indexsets: ItemRepository
- runs: ItemRepository
- create(run_id: int, name: str, constrained_to_indexsets: list[str] | None = None, column_names: list[str] | None = None) Variable
Creates a table.
- Raises:
VariableNotUnique – If the table is not unique.
OptimizationItemUsageError – If the table arguments are not valid.
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
The created table.
- Return type:
- create_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, run_id: int, name: str, constrained_to_indexsets: list[str] | None = None, column_names: list[str] | None = None) None
- get(run_id: int, name: str) Variable
Retrieves a table by its name and run_id.
- Parameters:
- Raises:
VariableNotFound – If the table with name does not exist.
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
The retrieved table.
- Return type:
Variable
- get_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, run_id: int, name: str) None
- get_by_id(id: int) Variable
Retrieves a table by its id.
- Parameters:
id (int) – The integer id of the table.
- Raises:
VariableNotFound – If the table with id does not exist.
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
The retrieved table.
- Return type:
Variable
- delete_by_id(id: int) None
Deletes a table.
- Parameters:
id (int) – The unique integer id of the table.
- Raises:
VariableNotFound – If the table with id does not exist.
VariableDeletionPrevented – If the table with id is used in the database, preventing it’s deletion.
Unauthorized – If the current user is not authorized to perform this action.
- delete_by_id_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, id: int) None
- add_data(id: int, data: dict[str, ~typing.Any] | ~typing.Annotated[~pandas.DataFrame, ~pydantic.functional_validators.PlainValidator(func=~ixmp4.data.dataframe.parse_df, json_schema_input_type=~typing.Any), ~pydantic.functional_serializers.PlainSerializer(func=~ixmp4.data.dataframe.serialize_df, return_type=dict, when_used=json), ~pydantic.json_schema.WithJsonSchema(json_schema={'properties': {'index': {'anyOf': [{'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Index'}, 'columns': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Columns'}, 'dtypes': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Dtypes'}, 'data': {'anyOf': [{'items': {'items': {'anyOf': [{'type': 'boolean'}, {'type': 'integer'}, {'type': 'number'}, {'type': 'string'}, {'additionalProperties': True, 'type': 'object'}, {'items': {'type': 'number'}, 'type': 'array'}, {'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'format': 'date-time', 'type': 'string'}, {'type': 'null'}]}, 'type': 'array'}, 'type': 'array'}, {'type': 'null'}], 'title': 'Data'}}, 'required': ['data'], 'title': 'DataFrameTypeAdapter', 'type': 'object'}, mode=serialization)]) None
Adds data to a Variable.
The data will be validated with the linked constrained
ixmp4.data.abstract.optimization.IndexSet`s. For that, `data.keys()must correspond to the names of the Variable’s columns. Each column can only contain values that are in the linked IndexSet.data. Each row of entries must be unique. No values can be missing, None, or NaN. If data.keys() contains names already present in Variable.data, existing values will be overwritten.- Parameters:
id (int) – The id of the
ixmp4.data.abstract.optimization.Variable.data (dict[str, Any] | pandas.DataFrame) – The data to be added.
- Raises:
ixmp4.core.exceptions.OptimizationItemUsageError –
If values are missing,
None, orNaN- If values are not allowed based on constraints toVariabless - If rows are not unique
- Return type:
None
- add_data_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, id: int, data: dict[str, ~typing.Any] | ~typing.Annotated[~pandas.DataFrame, ~pydantic.functional_validators.PlainValidator(func=~ixmp4.data.dataframe.parse_df, json_schema_input_type=~typing.Any), ~pydantic.functional_serializers.PlainSerializer(func=~ixmp4.data.dataframe.serialize_df, return_type=dict, when_used=json), ~pydantic.json_schema.WithJsonSchema(json_schema={'properties': {'index': {'anyOf': [{'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Index'}, 'columns': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Columns'}, 'dtypes': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Dtypes'}, 'data': {'anyOf': [{'items': {'items': {'anyOf': [{'type': 'boolean'}, {'type': 'integer'}, {'type': 'number'}, {'type': 'string'}, {'additionalProperties': True, 'type': 'object'}, {'items': {'type': 'number'}, 'type': 'array'}, {'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'format': 'date-time', 'type': 'string'}, {'type': 'null'}]}, 'type': 'array'}, 'type': 'array'}, {'type': 'null'}], 'title': 'Data'}}, 'required': ['data'], 'title': 'DataFrameTypeAdapter', 'type': 'object'}, mode=serialization)]) None
- remove_data(id: int, data: Any] | None = None) None
Removes data from a Variable.
- Parameters:
id (int) – The id of the
ixmp4.data.abstract.optimization.Variable.data (dict[str, Any] | pandas.DataFrame, optional) – The data to be removed. If specified, remove only specific data. This must specify all indexed columns. All other keys/columns are ignored. Otherwise, remove all data (the default).
- Return type:
None
- remove_data_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, /, id: int, data: Any] | None = None) None
- list(**kwargs: Unpack[VariableFilter]) List[Variable]
Lists variables by specified criteria.
- Parameters:
**kwargs (any) – Filter variables as specified in
VariableFilter.- Raises:
Unauthorized – If the current user is not authorized to perform this action.
- Returns:
List of variables.
- Return type:
list[
Variable]
- list_auth_check(auth_ctx: AuthorizationContext, platform: PlatformProtocol, **kwargs: Unpack[VariableFilter]) None
- paginated_list(pagination: Pagination, **kwargs: Unpack[VariableFilter]) PaginatedResult[List[Variable]]
- tabulate(**kwargs: Unpack[VariableFilter]) WithJsonSchema(json_schema={'properties': {'index': {'anyOf': [{'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Index'}, 'columns': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Columns'}, 'dtypes': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'}, {'type': 'null'}], 'default': None, 'title': 'Dtypes'}, 'data': {'anyOf': [{'items': {'items': {'anyOf': [{'type': 'boolean'}, {'type': 'integer'}, {'type': 'number'}, {'type': 'string'}, {'additionalProperties': True, 'type': 'object'}, {'items': {'type': 'number'}, 'type': 'array'}, {'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'array'}, {'format': 'date-time', 'type': 'string'}, {'type': 'null'}]}, 'type': 'array'}, 'type': 'array'}, {'type': 'null'}], 'title': 'Data'}}, 'required': ['data'], 'title': 'DataFrameTypeAdapter', 'type': 'object'}, mode=serialization)]
Tabulates variables by specified criteria.
- Parameters:
**kwargs (any) – Filter variables as specified in
VariableFilter.- Returns:
- A data frame with the columns:
id
name
- Return type:
- paginated_tabulate(pagination: Pagination, **kwargs: Unpack[VariableFilter]) PaginatedResult[Annotated[DataFrame, PlainValidator, PlainSerializer, WithJsonSchema]]
Filters
Base Filters
- class ixmp4.data.filters.optimization.EquationFilter
Bases:
IdFilter,NameFilter,RunIdFilter
- class ixmp4.data.filters.optimization.IndexSetFilter
Bases:
IdFilter,NameFilter,RunIdFilter
- class ixmp4.data.filters.optimization.ParameterFilter
Bases:
IdFilter,NameFilter,RunIdFilter
- class ixmp4.data.filters.optimization.ScalarFilter
Bases:
IdFilter,NameFilter,RunIdFilter
- class ixmp4.data.filters.optimization.TableFilter
Bases:
IdFilter,NameFilter,RunIdFilter