Skip to content

Commit af6ece5

Browse files
ms-lolojzazo
authored andcommitted
improve the rats.aml api
- print the studio url when submitting a job to aml - create rats.aml.job() factory function for access to the app container - add more relevant details to rats.aml.Request
1 parent 5865f1b commit af6ece5

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

rats-devtools/src/rats/aml/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
AmlWorkspace,
3939
)
4040
from ._request import Request
41-
from ._submission import submit
41+
from ._submission import job, submit
4242

4343
__all__ = [
4444
"AmlEnvironment",
@@ -50,6 +50,7 @@
5050
"AppServices",
5151
"Application",
5252
"Request",
53+
"job",
5354
"main",
5455
"submit",
5556
]

rats-devtools/src/rats/aml/_app.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,13 +525,16 @@ def _submit(
525525
**extra_aml_command_args,
526526
)
527527
returned_job = job_ops.create_or_update(job) # type: ignore[reportUnknownMemberType]
528-
logger.info(f"created job: {returned_job}")
529528

530529
self._request = Request(
531-
job_name=str(returned_job.name),
530+
name=str(returned_job.name),
531+
experiment_name=str(returned_job.experiment_name),
532+
studio_url=str(returned_job.studio_url),
532533
wait=wait,
533534
)
534535

536+
print(f"created job: {self._request}")
537+
535538
while wait:
536539
job_details = job_ops.get(str(returned_job.name))
537540
logger.info(f"job {returned_job.name} status: {job_details.status}")

rats-devtools/src/rats/aml/_request.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33

44
class Request(NamedTuple):
5-
job_name: str
5+
name: str
66
"""The aml job name, often generated by the aml apis."""
7+
experiment_name: str
8+
"""The aml experiment where the job was submitted, typically our component name."""
9+
studio_url: str
10+
"""Link to the portal page for the submitted job."""
711

812
wait: bool
913
"""Whether the application will wait for the completion of the aml job before returning."""

rats-devtools/src/rats/aml/_submission.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,42 @@ def submit(
1414
"""
1515
Submit an AML job programmatically instead of calling `rats-aml submit`.
1616
17+
Args:
18+
app_ids: list of the application to run on the remote aml job as found in pyproject.toml.
19+
container_plugin: a plugin container for passing services into [rats.aml.Application][].
20+
context: context to send to the remote aml job.
21+
wait: wait for the successful completion of the submitted aml job.
22+
"""
23+
submitter = job(
24+
*app_ids,
25+
container_plugin=container_plugin,
26+
context=context,
27+
wait=wait,
28+
)
29+
submitter.execute()
30+
31+
32+
def job(
33+
*app_ids: str,
34+
container_plugin: apps.ContainerPlugin = apps.EMPTY_PLUGIN,
35+
context: app_context.Collection[Any] = app_context.EMPTY_COLLECTION,
36+
wait: bool = False,
37+
) -> apps.AppContainer:
38+
"""
39+
Convenience factory function for creating [rats.aml.Application][] instances.
40+
41+
Use this function if you want access to the underlying container in order to reach relevant
42+
services before, after, or during the execution of the aml job.
43+
44+
```python
45+
from rats import aml
46+
47+
job = aml.app("rats_e2e.aml.basic", wait=True)
48+
job.execute()
49+
request = job.get(aml.AppServices.REQUEST)
50+
print(request.name)
51+
```
52+
1753
Args:
1854
app_ids: list of the application to run on the remote aml job as found in pyproject.toml.
1955
container_plugin: a plugin container for passing services into [rats.aml.Application][].
@@ -29,11 +65,10 @@ def submit(
2965
app_context.dumps(context),
3066
*w,
3167
)
32-
submitter = apps.AppBundle(
68+
return apps.AppBundle(
3369
app_plugin=Application,
3470
container_plugin=container_plugin,
3571
context=apps.StaticContainer(
3672
apps.static_service(cli.PluginConfigs.ARGV, lambda: cmd),
3773
),
3874
)
39-
submitter.execute()

0 commit comments

Comments
 (0)