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 104 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
1 change: 1 addition & 0 deletions cognite/client/_api/simulators/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from __future__ import annotations
59 changes: 59 additions & 0 deletions cognite/client/_api/simulators/simulation_runs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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="General Availability", sdk_maturity="alpha", feature_name="Simulators"
)

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://developer.cognite.com/api#tag/Simulation-Runs/operation/filter_simulation_runs_simulators_runs_list_post>`_

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

Args:
limit (int): The maximum number of simulation runs to return.
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
limit (int): The maximum number of simulation runs to return.
limit (int): Maximum number of results to return. Defaults to 1000. Set to -1, float(“inf”) or None to return all items.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect this will auto paginate if limit is set to None, -1 or float("inf"), following the normal Python SDK pattern

Copy link
Contributor

Choose a reason for hiding this comment

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

I almost agree with @evertoncolling comment above 😄

Suggested change
limit (int): The maximum number of simulation runs to return.
limit (int | None): Maximum number of assets to return. Defaults to 25. Set to -1, float("inf") or None to return all items.

filter (SimulationRunsFilter | dict[str, Any] | None): The filter that helps narrow down the list of simulation runs.
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Returns:
SimulationRunsList: List of simulation runs

Examples:

List simulation runs:

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> res = client.simulators.runs.list()
Comment on lines +49 to +53
Copy link
Contributor

Choose a reason for hiding this comment

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

Need one example showing where to import SimulationRunsFilter and how to use it (can include the sort in the same example)


"""
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,

filter=filter.dump()
if isinstance(filter, SimulationRunsFilter)
else filter
if isinstance(filter, dict)
else None,
Comment on lines +71 to +75
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 something like this:

if isinstance(filter, CogniteFilter):
    filter = filter.dump(camel_case=True)

Then we don't need this to take up 5 lines:

Suggested change
filter=filter.dump()
if isinstance(filter, SimulationRunsFilter)
else filter
if isinstance(filter, dict)
else None,
filter=filter,

)
66 changes: 66 additions & 0 deletions cognite/client/_api/simulators/simulator_integrations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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 CogniteClient
from cognite.client.config import ClientConfig


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="General Availability", sdk_maturity="alpha", feature_name="Simulators"
)

def list(
self,
limit: int = DEFAULT_LIMIT_READ,
filter: SimulatorIntegrationFilter | dict[str, Any] | None = None,
) -> SimulatorIntegrationList:
"""`Filter simulator integrations <https://developer.cognite.com/api#tag/Simulator-Integrations/operation/filter_simulator_integrations_simulators_integrations_list_post>`_

List simulator integrations
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Args:
limit (int): The maximum number of simulator integrations to return.
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
limit (int): The maximum number of simulator integrations to return.
limit (int): Maximum number of results to return. Defaults to 1000. Set to -1, float(“inf”) or None to return all items.

Copy link
Contributor

Choose a reason for hiding this comment

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

@polomani since the maximum number of integrations a project can have is 20, should we lower the default max limit to 20 as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

@evertoncolling this part Defaults to 1000. is not correct here, since the method applies limit: int = DEFAULT_LIMIT_READ, which is 25.
so it's not the same as API could potentially give and seems like SDK default it quite nice (so the output readable for the user by default)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, I was not aware the SDK limit had a different value. Sounds good then, but we need to update the description to account the SDK limit.

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 simulator integrations

Examples:

List simulator integrations:

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> res = client.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.

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,
filter=filter.dump()
if isinstance(filter, SimulatorIntegrationFilter)
else filter
if isinstance(filter, dict)
else None,
Comment on lines +61 to +65
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here as above

)
213 changes: 213 additions & 0 deletions cognite/client/_api/simulators/simulator_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
from __future__ import annotations

from collections.abc import Sequence
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
from cognite.client.utils.useful_types import SequenceNotStr

if TYPE_CHECKING:
from cognite.client import ClientConfig, CogniteClient


class SimulatorModelRevisionsAPI(APIClient):
_RESOURCE_PATH = "/simulators/models/revisions"

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="General Availability", sdk_maturity="alpha", feature_name="Simulators"
)

def list(
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://developer.cognite.com/api#tag/Simulator-Models/operation/filter_simulator_model_revisions_simulators_models_revisions_list_post>`_

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

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

Returns:
SimulatorModelRevisionList: List of simulator model revisions

Examples:

List simulator model revisions:
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
List simulator model revisions:
List simulator model revisions:

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> res = client.simulators.models.revisions.list()

"""
self._warning.warn()
return self._list(
method="POST",
limit=limit,
url_path="/simulators/models/revisions/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/models/revisions/list",

resource_cls=SimulatorModelRevision,
list_cls=SimulatorModelRevisionList,
filter=filter.dump()
if isinstance(filter, SimulatorModelRevisionsFilter)
else filter
if isinstance(filter, dict)
else None,
Comment on lines +67 to +71
Copy link
Contributor

Choose a reason for hiding this comment

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

See prev. comment

)

def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorModelRevision | None:
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't use retrieve_multiple anymore, it is a remnant from the "dark ages" when we didn't have typing.overload to indicate the correct return type depended on the given inputs.

Check out e.g. UserProfilesAPI.retrieve.

"""`Retrieve simulator model revision <https://developer.cognite.com/api#tag/Simulator-Models/operation/retrieve_simulator_model_revisions_simulators_models_revisions_byids_post>`_

Retrieve multiple 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:

Get simulator model revision by id:
>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> res = client.simulators.models.revisions.retrieve(id=123)

Get simulator model revision by external id:
>>> res = client.simulators.models.revisions.retrieve(external_id="abcdef")

"""
identifiers = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton()
return self._retrieve_multiple(
Copy link
Contributor

Choose a reason for hiding this comment

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

In order for this to chunk according to the API limits (100, right?), you need to set:

# in __init__():
self._RETRIEVE_LIMIT = 100

list_cls=SimulatorModelRevisionList,
resource_cls=SimulatorModelRevision,
identifiers=identifiers,
resource_path="/simulators/models/revisions",
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
resource_path="/simulators/models/revisions",

)

def retrieve_multiple(
self,
ids: Sequence[int] | None = None,
external_ids: SequenceNotStr[str] | None = None,
ignore_unknown_ids: bool = False,
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved
) -> SimulatorModelRevisionList:
"""`Retrieve simulator model revisions <https://developer.cognite.com/api#tag/Simulator-Models/operation/retrieve_simulator_model_revisions_simulators_models_revisions_byids_post>`_

lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved
Args:
ids (Sequence[int] | None): IDs
external_ids (SequenceNotStr[str] | None): External IDs
ignore_unknown_ids (bool): Ignore IDs and external IDs that are not found rather than throw an exception.

Returns:
SimulatorModelRevisionList: Requested simulator model revisions

Examples:

Get simulator model revisions by ids:
>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> res = client.simulators.models.revisions.retrieve_multiple(ids=[1, 2, 3])

Get simulator model revisions by external ids:
>>> res = client.simulators.models.revisions.retrieve_multiple(external_ids=["abc", "def"])
Copy link
Contributor

Choose a reason for hiding this comment

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

so there is an example of "retrieve_multiple", but there is no test, does it work?

"""
identifiers = IdentifierSequence.load(ids=ids, external_ids=external_ids)
return self._retrieve_multiple(
list_cls=SimulatorModelRevisionList,
resource_cls=SimulatorModelRevision,
identifiers=identifiers,
ignore_unknown_ids=ignore_unknown_ids,
)


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.revisions = SimulatorModelRevisionsAPI(config, api_version, cognite_client)
self._warning = FeaturePreviewWarning(
api_maturity="General Availability", sdk_maturity="alpha", feature_name="Simulators"
)

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://developer.cognite.com/api#tag/Simulator-Models/operation/filter_simulator_models_simulators_models_list_post>`_

List simulator models
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

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

Returns:
SimulatorModelList: List of simulator models

Examples:

List simulator models:

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> res = client.simulators.models.list()

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/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/models/list",

resource_cls=SimulatorModel,
list_cls=SimulatorModelList,
filter=filter.dump()
if isinstance(filter, SimulatorModelsFilter)
else filter
if isinstance(filter, dict)
else None,
Comment on lines +185 to +189
Copy link
Contributor

Choose a reason for hiding this comment

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

See previous comment

)

def retrieve(self, id: int | None = None, external_id: str | None = None) -> SimulatorModel | None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's also extend this to support multiple. It seems the API only returns 1 at the time, so you would need to set self._RETRIEVE_LIMIT = 1 in __init__

"""`Retrieve simulator model <https://developer.cognite.com/api#tag/Simulator-Models/operation/retrieve_simulator_model_simulators_models_byids_post>`_

Retrieve a single 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 simulator models:
>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> res = client.simulators.models.list()
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Get simulator model by id:
>>> res = client.simulators.models.retrieve(id=1)
lpereiracgn marked this conversation as resolved.
Show resolved Hide resolved

Get simulator model by external id:
>>> res = client.simulators.models.retrieve(external_id="1")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please avoid using numbers when illustrating usage of external ID 😄

Suggested change
>>> res = client.simulators.models.retrieve(external_id="1")
>>> res = client.simulators.models.retrieve(external_id="foo")


"""
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",
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
resource_path="/simulators/models",

)
Loading
Loading