Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simulators API #2006

Open
wants to merge 128 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
f42cc6c
tmp: happy mypy locally
doctrino Oct 6, 2024
8e936c2
refactor: generated data and api classes
doctrino Oct 6, 2024
67f3680
refactor: remove crud methods
doctrino Oct 6, 2024
2852e9f
refactor: setup shell
doctrino Oct 6, 2024
4fb7728
fix: added forgotten
doctrino Oct 6, 2024
8a96799
add support for integrations and models listing
lpereiracgn Nov 1, 2024
f061996
filtering for simulator integrations
lpereiracgn Nov 1, 2024
2a67cb5
listing revisions
lpereiracgn Nov 5, 2024
966f31d
docstrings
lpereiracgn Nov 5, 2024
947c0c2
routine revisions
lpereiracgn Nov 5, 2024
f25b46d
move filters to its own file
lpereiracgn Nov 5, 2024
741c6a0
filters
lpereiracgn Nov 6, 2024
7c5fc0f
Merge branch 'master' into simulator-resources
lpereiracgn Nov 6, 2024
3460781
retrieve byids
lpereiracgn Nov 6, 2024
7d5e13c
retrieve byids
lpereiracgn Nov 6, 2024
4061ed2
retrieve byids
lpereiracgn Nov 6, 2024
ef47c43
Merge branch 'master' into simulator-resources
lpereiracgn Nov 21, 2024
7de0581
fix ci
lpereiracgn Nov 21, 2024
bd058e4
lint
lpereiracgn Nov 21, 2024
0fd679d
simulator resource - writable
lpereiracgn Nov 24, 2024
76d3c51
simulator integration resource - writeable
lpereiracgn Nov 24, 2024
a70bab1
fix API maturity level
lpereiracgn Nov 27, 2024
74ae117
remove beta header
lpereiracgn Nov 27, 2024
e041dad
Update cognite/client/_api/simulators/simulator_integrations.py
lpereiracgn Nov 28, 2024
c940dbc
Update cognite/client/_api/simulators/simulator_routines.py
lpereiracgn Nov 28, 2024
5a9f01e
Update cognite/client/_api/simulators/simulator_routines.py
lpereiracgn Nov 28, 2024
079075b
Update cognite/client/_api/simulators/simulator_routines.py
lpereiracgn Nov 28, 2024
27fe6bd
Update cognite/client/_api/simulators/simulator_routines.py
lpereiracgn Nov 28, 2024
8e7ae96
Update cognite/client/_api/simulators/simulator_integrations.py
lpereiracgn Nov 28, 2024
2001b37
Update cognite/client/_api/simulators/simulator_routines.py
lpereiracgn Nov 28, 2024
3a5a139
Update cognite/client/_api/simulators/simulators.py
lpereiracgn Nov 28, 2024
75c6189
Update cognite/client/_api/simulators/simulator_integrations.py
lpereiracgn Nov 28, 2024
334bfad
fix docstrings
lpereiracgn Nov 28, 2024
281a669
chane structure for revisions
lpereiracgn Nov 28, 2024
5947ad7
fmt
lpereiracgn Nov 28, 2024
b6672ff
Update cognite/client/_api/simulators/simulation_runs.py
lpereiracgn Nov 28, 2024
5d09fb0
update docstrings
lpereiracgn Dec 2, 2024
016227c
update docstrings
lpereiracgn Dec 2, 2024
7bd1684
add retrieve_multiple method and clean up seed data
lpereiracgn Dec 2, 2024
a3d3a04
Merge branch 'master' into simulator-resources
lpereiracgn Dec 2, 2024
e01cec3
fix docstrings
lpereiracgn Dec 2, 2024
e9bde70
fix docstrings
lpereiracgn Dec 2, 2024
47d33a7
fix docstrings
lpereiracgn Dec 2, 2024
985e1ff
fix docstrings
lpereiracgn Dec 2, 2024
ce5c8f1
fix test
lpereiracgn Dec 2, 2024
0a37df1
fix model revisions to writable class
lpereiracgn Dec 2, 2024
5fff3a4
fix mock
lpereiracgn Dec 2, 2024
6b82751
fix mock
lpereiracgn Dec 2, 2024
774252b
fix spec definition for mock client
lpereiracgn Dec 3, 2024
8991a38
fix meta tests for simulators
lpereiracgn Dec 3, 2024
e4d437e
fix sim runs
lpereiracgn Dec 3, 2024
00e56c6
remove simulationrunwrite
abdullah-cognite Dec 5, 2024
5342df5
use InternalIdTransformerMixin in run
abdullah-cognite Dec 5, 2024
70833ab
fix
lpereiracgn Dec 5, 2024
2a6ae37
Merge branch 'master' into simulator-resources
lpereiracgn Dec 6, 2024
aa7702b
fix tests
lpereiracgn Dec 9, 2024
3473533
add missing dump calls in parent class
abdullah-cognite Dec 9, 2024
2400a67
fix schedule test
lpereiracgn Dec 9, 2024
78d2d79
fix tests
lpereiracgn Dec 9, 2024
cd40c3b
print dataset
lpereiracgn Dec 9, 2024
5e4e0af
disable fixture
lpereiracgn Dec 9, 2024
f0139d0
fix
lpereiracgn Dec 9, 2024
bb51ef6
fix
lpereiracgn Dec 9, 2024
2fb1eef
fix
lpereiracgn Dec 9, 2024
b668282
fix
lpereiracgn Dec 9, 2024
c8527a9
fix
lpereiracgn Dec 9, 2024
9798475
fix
lpereiracgn Dec 9, 2024
c076dc9
fix
lpereiracgn Dec 9, 2024
77d431b
fix
lpereiracgn Dec 9, 2024
e43ce27
fix
lpereiracgn Dec 9, 2024
f49d9fa
fix
lpereiracgn Dec 9, 2024
b683f02
fix dataset
lpereiracgn Dec 9, 2024
b1b5c9d
verify
lpereiracgn Dec 9, 2024
7084a4d
slight change
abdullah-cognite Dec 10, 2024
4d5fa3b
slight change
abdullah-cognite Dec 10, 2024
dbbe91a
slight change
abdullah-cognite Dec 10, 2024
9520e8a
slight change
abdullah-cognite Dec 10, 2024
66f4074
slight change
abdullah-cognite Dec 10, 2024
655d298
slight change
abdullah-cognite Dec 10, 2024
92b3d9a
slight change
abdullah-cognite Dec 10, 2024
c316ce3
slight change
abdullah-cognite Dec 10, 2024
560188b
slight change
abdullah-cognite Dec 10, 2024
7b7d82b
fix
lpereiracgn Dec 10, 2024
5a77f2e
fix filtered check
lpereiracgn Dec 10, 2024
fd3342b
fix lint
lpereiracgn Dec 10, 2024
d7236a8
remove limits from docstrings
lpereiracgn Dec 10, 2024
64cd8b5
fix dataset
lpereiracgn Dec 10, 2024
2a06f98
fix
lpereiracgn Dec 10, 2024
6e795d6
fix
lpereiracgn Dec 10, 2024
3560687
fix
lpereiracgn Dec 10, 2024
48d6195
fix
lpereiracgn Dec 10, 2024
eb024db
fix
lpereiracgn Dec 10, 2024
c75f492
fix
lpereiracgn Dec 10, 2024
c104a3b
fix
lpereiracgn Dec 10, 2024
6718fb4
fix
lpereiracgn Dec 10, 2024
960775a
model tests
lpereiracgn Dec 10, 2024
6bdc7f3
dataset retrigger
lpereiracgn Dec 10, 2024
1cdc8b2
fix
lpereiracgn Dec 10, 2024
9fead1a
fix
lpereiracgn Dec 10, 2024
5d125bd
fix
lpereiracgn Dec 10, 2024
d15226f
fix
lpereiracgn Dec 10, 2024
eef86be
fix test and delete fixture
lpereiracgn Dec 10, 2024
bb04cca
fix test and delete fixture
lpereiracgn Dec 10, 2024
a48b626
remove unknown change
lpereiracgn Dec 10, 2024
c76eab1
Update cognite/client/_api/simulators/simulator_models.py
lpereiracgn Dec 10, 2024
d5600fb
Update cognite/client/_api/simulators/simulators.py
lpereiracgn Dec 10, 2024
f12fb21
Update cognite/client/_api/simulators/simulator_routines.py
lpereiracgn Dec 10, 2024
60c83a0
Update cognite/client/_api/simulators/simulator_routines.py
lpereiracgn Dec 10, 2024
4898f54
Update cognite/client/_api/simulators/simulator_routines.py
lpereiracgn Dec 10, 2024
9945ff8
Update cognite/client/_api/simulators/simulator_models.py
lpereiracgn Dec 10, 2024
c8180cb
Update cognite/client/_api/simulators/simulator_models.py
lpereiracgn Dec 10, 2024
16fe676
Update cognite/client/_api/simulators/simulator_routines.py
lpereiracgn Dec 10, 2024
cd4498c
Update cognite/client/_api/simulators/simulator_models.py
lpereiracgn Dec 10, 2024
1c85b88
Update cognite/client/_api/simulators/simulation_runs.py
lpereiracgn Dec 10, 2024
7def138
Update cognite/client/_api/simulators/simulator_routines.py
lpereiracgn Dec 10, 2024
49ad5fc
Update cognite/client/_api/simulators/simulator_routines.py
lpereiracgn Dec 10, 2024
6e4f8bb
Update cognite/client/_api/simulators/simulator_models.py
lpereiracgn Dec 10, 2024
0a9d007
Update cognite/client/_api/simulators/simulator_integrations.py
lpereiracgn Dec 10, 2024
68bf6a8
Merge branch 'master' into simulator-resources
abdullah-cognite Dec 10, 2024
d79b8ff
Merge branch 'master' into simulator-resources
lpereiracgn Dec 11, 2024
daf3e8a
Update cognite/client/_api/simulators/simulator_routines.py
lpereiracgn Dec 12, 2024
f614c49
Update cognite/client/_api/simulators/simulator_integrations.py
lpereiracgn Dec 12, 2024
88446b4
Update cognite/client/_api/simulators/simulation_runs.py
lpereiracgn Dec 12, 2024
6b31e78
Update cognite/client/_api/simulators/simulator_models.py
lpereiracgn Dec 12, 2024
ebfe644
Apply suggestions from code review
lpereiracgn Dec 12, 2024
433e585
sort
lpereiracgn Dec 12, 2024
9428ecb
tests
lpereiracgn Dec 12, 2024
7401368
fix docstrings
lpereiracgn Dec 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
58 changes: 58 additions & 0 deletions cognite/client/_api/simulators/simulation_runs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any

from cognite.client._api_client import APIClient
from cognite.client._constants import DEFAULT_LIMIT_READ
from cognite.client.data_classes.simulators.filters import SimulationRunsFilter
from cognite.client.data_classes.simulators.simulators import SimulationRun, SimulationRunsList
from cognite.client.utils._experimental import FeaturePreviewWarning

if TYPE_CHECKING:
from cognite.client import ClientConfig, CogniteClient


class SimulatorRunsAPI(APIClient):
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved
_RESOURCE_PATH = "/simulators/runs"

def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None:
super().__init__(config, api_version, cognite_client)
self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators")
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

def list(
self, limit: int = DEFAULT_LIMIT_READ, filter: SimulationRunsFilter | dict[str, Any] | None = None
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved
) -> SimulationRunsList:
"""`Filter simulation runs <https://api-docs.cogheim.net/redoc/#tag/Simulation-Runs/operation/filter_simulation_runs_simulators_runs_list_post>`_
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

List all simulation runs
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Args:
limit (int): The maximum number of simulation runs to return. Defaults to 100.
filter (SimulationRunsFilter | dict[str, Any] | None): The filter to narrow down simulator models.
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Returns:
SimulationRunsList: List of simulator models
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Examples:

List simulators:
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> res = client.simulators.list()
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

"""
self._warning.warn()
return self._list(
method="POST",
limit=limit,
url_path="/simulators/runs/list",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed as this follows the API design guidelines

Suggested change
url_path="/simulators/runs/list",

resource_cls=SimulationRun,
list_cls=SimulationRunsList,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list class needs to be renamed:

Suggested change
list_cls=SimulationRunsList,
list_cls=SimulationRunList,

headers={"cdf-version": "beta"},
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved
filter=filter.dump()
if isinstance(filter, SimulationRunsFilter)
else filter
if isinstance(filter, dict)
else None, # fix this
)
64 changes: 64 additions & 0 deletions cognite/client/_api/simulators/simulator_integrations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any

from cognite.client._api_client import APIClient
from cognite.client._constants import DEFAULT_LIMIT_READ
from cognite.client.data_classes.simulators.filters import SimulatorIntegrationFilter
from cognite.client.data_classes.simulators.simulators import (
SimulatorIntegration,
SimulatorIntegrationList,
)
from cognite.client.utils._experimental import FeaturePreviewWarning

if TYPE_CHECKING:
from cognite.client import ClientConfig, CogniteClient


class SimulatorIntegrationsAPI(APIClient):
_RESOURCE_PATH = "/simulators/integrations"

def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None:
super().__init__(config, api_version, cognite_client)
self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators")
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

def list(
self,
limit: int = DEFAULT_LIMIT_READ,
filter: SimulatorIntegrationFilter | dict[str, Any] | None = None,
) -> SimulatorIntegrationList:
"""`Filter Simulators <https://api-docs.cognite.com/20230101-alpha/tag/Simulators/operation/filter_simulators_simulators_list_post>`_
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

List simulators
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Args:
limit (int): The maximum number of simulators to return. Defaults to 100.
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved
filter (SimulatorIntegrationFilter | dict[str, Any] | None): The filter to narrow down simulator integrations.
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Returns:
SimulatorIntegrationList: List of simulators
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Examples:

List simulators:
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> res = client.simulators.list_integrations()
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an example showcasing the usage of filter

"""

self._warning.warn()
return self._list(
method="POST",
limit=limit,
url_path="/simulators/integrations/list",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
url_path="/simulators/integrations/list",

resource_cls=SimulatorIntegration,
list_cls=SimulatorIntegrationList,
headers={"cdf-version": "beta"},
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved
filter=filter.dump()
if isinstance(filter, SimulatorIntegrationFilter)
else filter
if isinstance(filter, dict)
else None, # fix this
)
162 changes: 162 additions & 0 deletions cognite/client/_api/simulators/simulator_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any

from cognite.client._api_client import APIClient
from cognite.client._constants import DEFAULT_LIMIT_READ
from cognite.client.data_classes.simulators.filters import SimulatorModelRevisionsFilter, SimulatorModelsFilter
from cognite.client.data_classes.simulators.simulators import (
SimulatorModel,
SimulatorModelList,
SimulatorModelRevision,
SimulatorModelRevisionList,
)
from cognite.client.utils._experimental import FeaturePreviewWarning
from cognite.client.utils._identifier import IdentifierSequence

if TYPE_CHECKING:
from cognite.client import ClientConfig, CogniteClient


class SimulatorModelsAPI(APIClient):
_RESOURCE_PATH = "/simulators/models"

def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None:
super().__init__(config, api_version, cognite_client)
self._warning = FeaturePreviewWarning(api_maturity="beta", sdk_maturity="alpha", feature_name="Simulators")
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

def list(
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved
self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorModelsFilter | dict[str, Any] | None = None
) -> SimulatorModelList:
"""`Filter Simulator Models <https://api-docs.cogheim.net/redoc/#tag/Simulator-Models/operation/filter_simulator_models_simulators_models_list_post>`_
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

List all simulation models
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Args:
limit (int): The maximum number of simulator models to return. Defaults to 100.
filter (SimulatorModelsFilter | dict[str, Any] | None): The filter to narrow down simulator models.

Returns:
SimulatorModelList: List of simulator models

Examples:

List simulators:
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> res = client.simulators.list_models()
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

"""
self._warning.warn()
return self._list(
method="POST",
limit=limit,
url_path="/simulators/models/list",
resource_cls=SimulatorModel,
list_cls=SimulatorModelList,
headers={"cdf-version": "beta"},
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved
filter=filter.dump()
if isinstance(filter, SimulatorModelsFilter)
else filter
if isinstance(filter, dict)
else None, # fix this
)

def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorModel | None:
"""`Retrieve Simulator Model <https://api-docs.cogheim.net/redoc/#tag/Simulator-Models/operation/retrieve_simulator_model_simulators_models_byids_post>`_
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Get a simulator model by id/externalId
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Args:
id (int | None): The id of the simulator model.
external_id (str | None): The external id of the simulator model.

Returns:
SimulatorModel | None: Requested simulator model

Examples:

List simulators:

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> res = client.simulators.retrieve_model()
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

"""
identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton()
return self._retrieve_multiple(
list_cls=SimulatorModelList,
resource_cls=SimulatorModel,
identifiers=identifiers,
resource_path="/simulators/models",
headers={"cdf-version": "beta"},
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved
)

def list_revisions(
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved
self, limit: int = DEFAULT_LIMIT_READ, filter: SimulatorModelRevisionsFilter | dict[str, Any] | None = None
) -> SimulatorModelRevisionList:
"""`Filter simulator model revisions <https://api-docs.cognite.com/20230101-alpha/tag/Simulators/operation/filter_simulators_simulators_list_post>`_
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

List all simulation model revisions
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Args:
limit (int): The maximum number of model revisions to return. Defaults to 100.
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved
filter (SimulatorModelRevisionsFilter | dict[str, Any] | None): The filter to narrow down simulator model revisions.

Returns:
SimulatorModelRevisionList: List all simulation model revisions
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Examples:

List simulators:

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> res = client.simulators.list_revisions()
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs an example showcasing filter & sort

"""
self._warning.warn()
return self._list(
method="POST",
limit=limit,
url_path="/simulators/models/revisions/list",
resource_cls=SimulatorModelRevision,
list_cls=SimulatorModelRevisionList,
headers={"cdf-version": "beta"},
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved
filter=filter.dump()
if isinstance(filter, SimulatorModelRevisionsFilter)
else filter
if isinstance(filter, dict)
else None, # fix this
)

def retrieve_revision(self, id: int | None = None, external_id: str | None = None) -> SimulatorModelRevision | None:
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved
"""`Retrieve Simulator Model Revisions <https://api-docs.cogheim.net/redoc/#tag/Simulator-Models/operation/retrieve_simulator_model_revisions_simulators_models_revisions_byids_post>`_
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Retrieve simulator model revisions by IDs or external IDs
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Args:
id (int | None): The id of the simulator model revision.
external_id (str | None): The external id of the simulator model revision.

Returns:
SimulatorModelRevision | None: Requested simulator model revision

Examples:

List simulators:

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> res = client.simulators.retrieve_revision()
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

"""
identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton()
return self._retrieve_multiple(
list_cls=SimulatorModelRevisionList,
resource_cls=SimulatorModelRevision,
identifiers=identifiers,
resource_path="/simulators/models/revisions",
headers={"cdf-version": "beta"},
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved
)
Loading
Loading