Skip to content

Commit ff0864b

Browse files
committed
Merge branch 'dev' into feature/pagination
2 parents 598c9fb + 21409b2 commit ff0864b

28 files changed

Lines changed: 1209 additions & 203 deletions

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ repos:
2323
args: [--branch, main, --branch, dev]
2424
- id: check-added-large-files
2525
- repo: https://github.com/astral-sh/ruff-pre-commit
26-
rev: v0.9.9
26+
rev: v0.11.2
2727
hooks:
2828
- id: ruff
2929
args: [ --fix, --exit-non-zero-on-fix, "--ignore=C901" ]

CHANGELOG.md

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change log
22

3+
## Unreleased
4+
* Added sorting to server queries, users can now specify to sort by columns during data retrieval from the database.
5+
## [v2.0.1](https://github.com/simvue-io/client/releases/tag/v2.0.1) - 2025-03-24
6+
* Improvements to docstrings on methods, classes and functions.
37
## [v2.0.0](https://github.com/simvue-io/client/releases/tag/v2.0.0) - 2025-03-07
48
* Add new example notebooks
59
* Update and refactor examples to work with v2.0
@@ -51,28 +55,28 @@
5155
* Adds additional functionality and support for offline mode.
5256
* Support for Simvue servers `>=3`.
5357

54-
## [v1.1.4](https://github.com/simvue-io/client/releases/tag/v1.1.4) - 2024-12-11
58+
## [v1.1.4](https://github.com/simvue-io/python-api/releases/tag/v1.1.4) - 2024-12-11
5559

5660
* Remove incorrect identifier reference for latest Simvue servers during reconnection.
5761
* Fixed missing online mode selection when retrieving configuration for `Client` class.
5862

59-
## [v1.1.3](https://github.com/simvue-io/client/releases/tag/v1.1.3) - 2024-12-09
63+
## [v1.1.3](https://github.com/simvue-io/python-api/releases/tag/v1.1.3) - 2024-12-09
6064

6165
* Fixed bug with `requirements.txt` metadata read.
6266
* Added Simvue server version check.
6367
* Remove checking of server version in offline mode and add default run mode to configuration options.
6468
* Fix offline mode class initialisation, and propagation of configuration.
6569

66-
## [v1.1.2](https://github.com/simvue-io/client/releases/tag/v1.1.2) - 2024-11-06
70+
## [v1.1.2](https://github.com/simvue-io/python-api/releases/tag/v1.1.2) - 2024-11-06
6771

6872
* Fix bug in offline mode directory retrieval.
6973

70-
## [v1.1.1](https://github.com/simvue-io/client/releases/tag/v1.1.1) - 2024-10-22
74+
## [v1.1.1](https://github.com/simvue-io/python-api/releases/tag/v1.1.1) - 2024-10-22
7175

7276
* Add missing `offline.cache` key to TOML config.
7377
* Fix repetition of server URL validation for each call to configuration.
7478

75-
## [v1.1.0](https://github.com/simvue-io/client/releases/tag/v1.1.0) - 2024-10-21
79+
## [v1.1.0](https://github.com/simvue-io/python-api/releases/tag/v1.1.0) - 2024-10-21
7680

7781
* Add option to specify a callback executed when an alert is triggered for a run.
7882
* Allow retrieval of all alerts when no constraints are specified.
@@ -83,35 +87,35 @@
8387
* Indicate the source used for token and URL.
8488
* Migrate to `simvue.toml` from `simvue.ini`, allowing more defaults to be set during runs.
8589

86-
## [v1.0.6](https://github.com/simvue-io/client/releases/tag/v1.0.6) - 2024-10-10
90+
## [v1.0.6](https://github.com/simvue-io/python-api/releases/tag/v1.0.6) - 2024-10-10
8791

8892
* Fix incorrect usage of `retry` when attempting connections to the server.
8993

90-
## [v1.0.5](https://github.com/simvue-io/client/releases/tag/v1.0.5) - 2024-10-09
94+
## [v1.0.5](https://github.com/simvue-io/python-api/releases/tag/v1.0.5) - 2024-10-09
9195

9296
* Ensure all functionality is deactivated when mode is set to `disabled`.
9397
* When an exception is thrown an event is sent to Simvue displaying the traceback.
9498
* If `add_process` is used and an exception is thrown, `.err` and `.out` files are still uploaded.
9599

96-
## [v1.0.4](https://github.com/simvue-io/client/releases/tag/v1.0.4) - 2024-09-24
100+
## [v1.0.4](https://github.com/simvue-io/python-api/releases/tag/v1.0.4) - 2024-09-24
97101

98102
* Set resource metrics to be recorded by default.
99103

100-
## [v1.0.3](https://github.com/simvue-io/client/releases/tag/v1.0.3) - 2024-09-23
104+
## [v1.0.3](https://github.com/simvue-io/python-api/releases/tag/v1.0.3) - 2024-09-23
101105

102106
* Fix issue of hanging threads when exception raised by script using the API.
103107

104-
## [v1.0.2](https://github.com/simvue-io/client/releases/tag/v1.0.2) - 2024-08-21
108+
## [v1.0.2](https://github.com/simvue-io/python-api/releases/tag/v1.0.2) - 2024-08-21
105109

106110
* Fix incorrect HTTP status code in `Client` when checking if object exists.
107111
* Fix issue with `running=False` when launching a `Run` caused by incorrect system metadata being sent to the server.
108112

109-
## [v1.0.1](https://github.com/simvue-io/client/releases/tag/v1.0.1) - 2024-07-16
113+
## [v1.0.1](https://github.com/simvue-io/python-api/releases/tag/v1.0.1) - 2024-07-16
110114

111115
* Fix to `add_process` with list of strings as arguments, the executable no longer returns the string `"None"`.
112116
* Fix callbacks and triggers for `add_process` being executed only on `Run` class termination, not on process completion.
113117

114-
## [v1.0.0](https://github.com/simvue-io/client/releases/tag/v1.0.0) - 2024-06-14
118+
## [v1.0.0](https://github.com/simvue-io/python-api/releases/tag/v1.0.0) - 2024-06-14
115119

116120
* Refactor and re-write of codebase to align with latest developments in version 2 of the Simvue server.
117121
* Added `Executor` to Simvue runs allowing users to start shell based processes as part of a run and handle termination of these.
@@ -121,119 +125,119 @@
121125
* Fixed issue whereby metrics would still have to wait for the next iteration of dispatch before being sent to the server, even if the queue was not full.
122126
* Added support for `'user'` alerts.
123127

124-
## [v0.14.3](https://github.com/simvue-io/client/releases/tag/v0.14.3) - 2023-06-29
128+
## [v0.14.3](https://github.com/simvue-io/python-api/releases/tag/v0.14.3) - 2023-06-29
125129

126130
* Ensure import of the `requests` module is only done if actually used.
127131

128-
## [v0.14.0](https://github.com/simvue-io/client/releases/tag/v0.14.0) - 2023-04-04
132+
## [v0.14.0](https://github.com/simvue-io/python-api/releases/tag/v0.14.0) - 2023-04-04
129133

130134
* Added a method to the `Client` class for retrieving events.
131135

132-
## [v0.13.3](https://github.com/simvue-io/client/releases/tag/v0.13.3) - 2023-04-04
136+
## [v0.13.3](https://github.com/simvue-io/python-api/releases/tag/v0.13.3) - 2023-04-04
133137

134138
* Allow files (`input` and `code` only) to be saved for runs in the `created` state.
135139
* Allow metadata and tags to be updated for runs in the `created` state.
136140

137-
## [v0.13.2](https://github.com/simvue-io/client/releases/tag/v0.13.2) - 2023-04-04
141+
## [v0.13.2](https://github.com/simvue-io/python-api/releases/tag/v0.13.2) - 2023-04-04
138142

139143
* Added `plot_metrics` method to the `Client` class to simplify plotting metrics.
140144
* (Bug fix) `reconnect` works without a uuid being specified when `offline` mode isn't being used.
141145
* (Bug fix) Restrict version of Pydantic to prevent v2 from accidentally being used.
142146

143-
## [v0.13.1](https://github.com/simvue-io/client/releases/tag/v0.13.1) - 2023-03-28
147+
## [v0.13.1](https://github.com/simvue-io/python-api/releases/tag/v0.13.1) - 2023-03-28
144148

145149
* Set `sample_by` to 0 by default (no sampling) in `get_metrics_multiple`.
146150

147-
## [v0.13.0](https://github.com/simvue-io/client/releases/tag/v0.13.0) - 2023-03-28
151+
## [v0.13.0](https://github.com/simvue-io/python-api/releases/tag/v0.13.0) - 2023-03-28
148152

149153
* Added methods to the `Client` class for retrieving metrics.
150154
* CPU architecture and processor obtained on Apple hardware.
151155
* Client now reports to server when files have been successfully uploaded.
152156
* `User-Agent` header now included in HTTP requests.
153157

154-
## [v0.12.0](https://github.com/simvue-io/client/releases/tag/v0.12.0) - 2023-03-13
158+
## [v0.12.0](https://github.com/simvue-io/python-api/releases/tag/v0.12.0) - 2023-03-13
155159

156160
* Add methods to the `Client` class for deleting runs and folders.
157161
* Confusing messages about `process no longer exists` or `NVML Shared Library Not Found` no longer displayed.
158162

159-
## [v0.11.4](https://github.com/simvue-io/client/releases/tag/v0.11.4) - 2023-03-13
163+
## [v0.11.4](https://github.com/simvue-io/python-api/releases/tag/v0.11.4) - 2023-03-13
160164

161165
* (Bug fix) Ensure `simvue_sender` can be run when installed from PyPI.
162166
* (Bug fix) Runs created in `offline` mode using a context manager weren't automatically closed.
163167

164-
## [v0.11.3](https://github.com/simvue-io/client/releases/tag/v0.11.3) - 2023-03-07
168+
## [v0.11.3](https://github.com/simvue-io/python-api/releases/tag/v0.11.3) - 2023-03-07
165169

166170
* Added logging messages for debugging when debug level set to `debug`.
167171

168-
## [v0.11.2](https://github.com/simvue-io/client/releases/tag/v0.11.2) - 2023-03-06
172+
## [v0.11.2](https://github.com/simvue-io/python-api/releases/tag/v0.11.2) - 2023-03-06
169173

170174
* Raise exceptions in `Client` class methods if run does not exist or artifact does not exist.
171175
* (Bug fix) `list_artifacts` optional category restriction now works.
172176

173-
## [v0.11.1](https://github.com/simvue-io/client/releases/tag/v0.11.1) - 2023-03-05
177+
## [v0.11.1](https://github.com/simvue-io/python-api/releases/tag/v0.11.1) - 2023-03-05
174178

175179
* Support different runs having different metadata in `get_runs` dataframe output.
176180
* (Bug fix) Error message when creating a duplicate run is now more clear.
177181
* (Bug fix) Correction to stopping the worker thread in situations where the run never started.
178182

179-
## [v0.11.0](https://github.com/simvue-io/client/releases/tag/v0.11.0) - 2023-03-04
183+
## [v0.11.0](https://github.com/simvue-io/python-api/releases/tag/v0.11.0) - 2023-03-04
180184

181185
* Support optional dataframe output from `get_runs`.
182186

183-
## [v0.10.1](https://github.com/simvue-io/client/releases/tag/v0.10.1) - 2023-03-03
187+
## [v0.10.1](https://github.com/simvue-io/python-api/releases/tag/v0.10.1) - 2023-03-03
184188

185189
* The worker process now no longer gives a long delay when a run has finished (now at most ~1 second).
186190
* The worker process ends when the `Run()` context ends or `close` is called, rather than only when the main process exits.
187191

188-
## [v0.10.0](https://github.com/simvue-io/client/releases/tag/v0.10.0) - 2023-02-07
192+
## [v0.10.0](https://github.com/simvue-io/python-api/releases/tag/v0.10.0) - 2023-02-07
189193

190194
* The `client` class can now be used to retrieve runs.
191195

192-
## [v0.9.1](https://github.com/simvue-io/client/releases/tag/v0.9.1) - 2023-01-25
196+
## [v0.9.1](https://github.com/simvue-io/python-api/releases/tag/v0.9.1) - 2023-01-25
193197

194198
* (Bug fix) Retries in POST/PUTs to REST APIs didn't happen.
195199
* Warn users if `allow_pickle=True` is required.
196200

197-
## [v0.9.0](https://github.com/simvue-io/client/releases/tag/v0.9.0) - 2023-01-25
201+
## [v0.9.0](https://github.com/simvue-io/python-api/releases/tag/v0.9.0) - 2023-01-25
198202

199203
* Set status to `failed` or `terminated` if the context manager is used and there is an exception.
200204

201-
## [v0.8.0](https://github.com/simvue-io/client/releases/tag/v0.8.0) - 2023-01-23
205+
## [v0.8.0](https://github.com/simvue-io/python-api/releases/tag/v0.8.0) - 2023-01-23
202206

203207
* Support NumPy arrays, PyTorch tensors, Matplotlib and Plotly plots and picklable Python objects as artifacts.
204208
* (Bug fix) Events in offline mode didn't work.
205209

206-
## [v0.7.2](https://github.com/simvue-io/client/releases/tag/v0.7.2) - 2023-01-08
210+
## [v0.7.2](https://github.com/simvue-io/python-api/releases/tag/v0.7.2) - 2023-01-08
207211

208212
* Pydantic model is used for input validation.
209213
* Support NaN, -inf and inf in metadata and metrics.
210214

211-
## [v0.7.0](https://github.com/simvue-io/client/releases/tag/v0.7.0) - 2022-12-05
215+
## [v0.7.0](https://github.com/simvue-io/python-api/releases/tag/v0.7.0) - 2022-12-05
212216

213217
* Collect CPU, GPU and memory resource metrics.
214218
* Automatically delete temporary files used in offline mode once runs have entered a terminal state.
215219
* Warn users if their access token has expired.
216220
* Remove dependency on the randomname module, instead handle name generation server side.
217221

218-
## [v0.6.0](https://github.com/simvue-io/client/releases/tag/v0.6.0) - 2022-11-07
222+
## [v0.6.0](https://github.com/simvue-io/python-api/releases/tag/v0.6.0) - 2022-11-07
219223

220224
* `offline` and `disabled` options replaced with single `mode` flag.
221225

222-
## [v0.5.0](https://github.com/simvue-io/client/releases/tag/v0.5.0) - 2022-11-03
226+
## [v0.5.0](https://github.com/simvue-io/python-api/releases/tag/v0.5.0) - 2022-11-03
223227

224228
* Added option to disable all monitoring.
225229

226-
## [v0.4.0](https://github.com/simvue-io/client/releases/tag/v0.4.0) - 2022-11-03
230+
## [v0.4.0](https://github.com/simvue-io/python-api/releases/tag/v0.4.0) - 2022-11-03
227231

228232
* Offline mode added, enabling tracking of simulations running on worker nodes without outgoing network access.
229233
* Argument to `init` enabling runs to be left in the `created` state changed from `status="created"` to `running=True`.
230234
* Improvements to error handling.
231235

232-
## [v0.3.0](https://github.com/simvue-io/client/releases/tag/v0.3.0) - 2022-10-31
236+
## [v0.3.0](https://github.com/simvue-io/python-api/releases/tag/v0.3.0) - 2022-10-31
233237

234238
* Update `add_alert` method to support either metrics or events based alerts.
235239

236-
## [v0.2.0](https://github.com/simvue-io/client/releases/tag/v0.2.0) - 2022-10-26
240+
## [v0.2.0](https://github.com/simvue-io/python-api/releases/tag/v0.2.0) - 2022-10-26
237241

238242
* The previous `Simvue` class has been split into `Run` and `Client`. When creating a run use the new `Run` class rather than `Simvue`.
239243

CITATION.cff

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ keywords:
4242
- alerting
4343
- simulation
4444
license: Apache-2.0
45-
commit: 88bdd861e01153a2853191c0a8d1bb64dfabe296
46-
version: 2.0.0
47-
date-released: '2025-03-07'
45+
commit: 5084f9c17ae4b7f77e188f5aa8a51ebd3f790c9e
46+
version: 2.0.1
47+
date-released: '2025-03-24'
4848
references:
4949
- title: mlco2/codecarbon
5050
version: v2.8.2

notebooks/non_python_example.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"metadata": {},
3535
"source": [
3636
"### Install dependencies\n",
37-
"While you can use Simvue and Multiparser individually to achieve the tracking and monitoring of Non-Python files, we recommend using the `simvue-integrations` package which wraps these both together into a handy `WrappedRun` class. Install this if you have not done so already:"
37+
"While you can use Simvue and Multiparser individually to achieve the tracking and monitoring of Non-Python files, we recommend using the `simvue-connector` package which wraps these both together into a handy `WrappedRun` class. Install this if you have not done so already:"
3838
]
3939
},
4040
{
@@ -43,7 +43,7 @@
4343
"metadata": {},
4444
"outputs": [],
4545
"source": [
46-
"!pip install git+https://github.com/simvue-io/integrations.git"
46+
"!pip install simvue-connector"
4747
]
4848
},
4949
{
@@ -94,7 +94,7 @@
9494
"metadata": {},
9595
"outputs": [],
9696
"source": [
97-
"from simvue_integrations.connectors.generic import WrappedRun\n",
97+
"from simvue_connector.connector import WrappedRun\n",
9898
"import multiparser.parsing.tail as mp_tail_parser\n",
9999
"import time\n",
100100
"import pathlib\n",

simvue/api/objects/alert/base.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99
import http
1010
import pydantic
11+
import datetime
1112
import typing
1213
from simvue.api.objects.base import SimvueObject, staging_check, write_only
1314
from simvue.api.request import get as sv_get, get_json_from_response
1415
from simvue.api.url import URL
15-
from simvue.models import NAME_REGEX
16+
from simvue.models import NAME_REGEX, DATETIME_FORMAT
1617

1718

1819
class AlertBase(SimvueObject):
@@ -125,6 +126,20 @@ def abort(self) -> bool:
125126
"""Retrieve if alert can abort simulations"""
126127
return self._get_attribute("abort")
127128

129+
@property
130+
@staging_check
131+
def delay(self) -> int:
132+
"""Retrieve delay value for this alert"""
133+
return self._get_attribute("delay")
134+
135+
@property
136+
def created(self) -> datetime.datetime | None:
137+
"""Retrieve created datetime for the alert"""
138+
_created: str | None = self._get_attribute("created")
139+
return (
140+
datetime.datetime.strptime(_created, DATETIME_FORMAT) if _created else None
141+
)
142+
128143
@abort.setter
129144
@write_only
130145
@pydantic.validate_call

simvue/api/objects/alert/fetch.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88

99
import typing
1010
import http
11+
import json
1112

1213
import pydantic
1314

1415
from simvue.api.objects.alert.user import UserAlert
16+
from simvue.api.objects.base import Sort
1517
from simvue.api.request import get_json_from_response
1618
from simvue.api.request import get as sv_get
1719
from .events import EventsAlert
@@ -21,6 +23,15 @@
2123
AlertType = EventsAlert | UserAlert | MetricsThresholdAlert | MetricsRangeAlert
2224

2325

26+
class AlertSort(Sort):
27+
@pydantic.field_validator("column")
28+
@classmethod
29+
def check_column(cls, column: str) -> str:
30+
if column and column not in ("name", "created"):
31+
raise ValueError(f"Invalid sort column for alerts '{column}'")
32+
return column
33+
34+
2435
class Alert:
2536
"""Generic Simvue alert retrieval class"""
2637

@@ -50,11 +61,13 @@ def __new__(cls, identifier: str, **kwargs) -> AlertType:
5061
raise RuntimeError(f"Unknown source type '{_alert_pre.source}'")
5162

5263
@classmethod
64+
@pydantic.validate_call
5365
def get(
5466
cls,
5567
offline: bool = False,
5668
count: int | None = None,
5769
offset: int | None = None,
70+
sorting: list[AlertSort] | None = None,
5871
**kwargs,
5972
) -> typing.Generator[tuple[str, AlertType], None, None]:
6073
"""Fetch all alerts from the server for the current user.
@@ -65,6 +78,8 @@ def get(
6578
limit the number of results, default of None returns all.
6679
offset : int, optional
6780
start index for returned results, default of None starts at 0.
81+
sorting : list[dict] | None, optional
82+
list of sorting definitions in the form {'column': str, 'descending': bool}
6883
6984
Yields
7085
------
@@ -80,11 +95,15 @@ def get(
8095

8196
_class_instance = AlertBase(_local=True, _read_only=True)
8297
_url = f"{_class_instance._base_url}"
98+
_params: dict[str, int | str] = {"start": offset, "count": count}
99+
100+
if sorting:
101+
_params["sorting"] = json.dumps([sort.to_params() for sort in sorting])
83102

84103
_response = sv_get(
85104
_url,
86105
headers=_class_instance._headers,
87-
params={"start": offset, "count": count} | kwargs,
106+
params=_params | kwargs,
88107
)
89108

90109
_label: str = _class_instance.__class__.__name__.lower()

0 commit comments

Comments
 (0)