Skip to content
Draft
Changes from all commits
Commits
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
121 changes: 121 additions & 0 deletions rats-devtools/src/rats/aml/_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,127 @@

time.sleep(2)

@cli.command()
@click.argument("args", nargs=-1)
@click.option("--wait", is_flag=True, default=False, help="wait for completion of aml job.")
def _submit_cmd(

Check warning on line 552 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

rats-devtools/src/rats/aml/_app.py#L549-L552

Added lines #L549 - L552 were not covered by tests
self,
args: tuple[str, ...],
wait: bool,
) -> None:
"""Submit a single cli command to aml."""
from azure.ai.ml import Input, Output, command # type: ignore[reportUnknownVariableType]
from azure.ai.ml.entities import Environment

Check warning on line 559 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

rats-devtools/src/rats/aml/_app.py#L558-L559

Added lines #L558 - L559 were not covered by tests

if self._request is not None:
print(self._request)
raise runtime.DuplicateRequestError()

Check warning on line 563 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

rats-devtools/src/rats/aml/_app.py#L562-L563

Added lines #L562 - L563 were not covered by tests

if len(args) == 0:
raise RuntimeError("No cli args were provided to the command")

Check warning on line 566 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L566 was not covered by tests

env: dict[str, str] = {}

Check warning on line 568 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L568 was not covered by tests
for env_map in self._app.get_group(AppConfigs.CLI_ENVS):
env.update(env_map)

Check warning on line 570 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L570 was not covered by tests

cli_command = cli.Command(

Check warning on line 572 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L572 was not covered by tests
cwd=self._app.get(AppConfigs.CLI_CWD),
argv=tuple([*args]),
env=env,
)
Comment on lines +572 to +576
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think in a lower level API, the right abstraction for submitting arbitrary commands should be tuple[str, ...], and no cwd and no env.

Reason of why this is important is because the user should control the appearance of what actually shows remotely, if they are to debug it...


pre_cmds: list[str] = []

Check warning on line 578 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L578 was not covered by tests
for pre_cmd in self._app.get_group(AppConfigs.CLI_PRE_CMD):
pre_cmds.append(shlex.join(["cd", pre_cmd.cwd]))
pre_cmds.append(

Check warning on line 581 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

rats-devtools/src/rats/aml/_app.py#L580-L581

Added lines #L580 - L581 were not covered by tests
shlex.join(
[
*[f"{k}={shlex.quote(v)}" for k, v in pre_cmd.env.items()],
*pre_cmd.argv,
]
)
)

post_cmds: list[str] = []

Check warning on line 590 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L590 was not covered by tests
for post_cmd in self._app.get_group(AppConfigs.CLI_POST_CMD):
post_cmds.append(shlex.join(["cd", post_cmd.cwd]))
post_cmds.append(

Check warning on line 593 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

rats-devtools/src/rats/aml/_app.py#L592-L593

Added lines #L592 - L593 were not covered by tests
shlex.join(
[
*[f"{k}={shlex.quote(v)}" for k, v in post_cmd.env.items()],
*post_cmd.argv,
]
)
)

config = self._app.get(AppConfigs.JOB_DETAILS)
env_ops = self._app.get(AppServices.AML_ENVIRONMENT_OPS)
job_ops = self._app.get(AppServices.AML_JOB_OPS)

Check warning on line 604 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

rats-devtools/src/rats/aml/_app.py#L602-L604

Added lines #L602 - L604 were not covered by tests

input_keys = config.inputs.keys()
output_keys = config.outputs.keys()

Check warning on line 607 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

rats-devtools/src/rats/aml/_app.py#L606-L607

Added lines #L606 - L607 were not covered by tests

input_envs = (

Check warning on line 609 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L609 was not covered by tests
[
# double escape double curly braces for aml to later replace with dataset values
f"export RATS_AML_PATH_{k.upper()}=${{{{inputs.{k}}}}}"
for k in input_keys
]
if len(input_keys) > 0
else []
)

output_keys = (

Check warning on line 619 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L619 was not covered by tests
[
# double escape double curly braces for aml to later replace with dataset values
f"export RATS_AML_PATH_{k.upper()}=${{{{outputs.{k}}}}}"
for k in output_keys
]
if len(output_keys) > 0
else []
)

cmd = " && ".join(

Check warning on line 629 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L629 was not covered by tests
[
# make sure we know the original directory and any input/output paths
"export RATS_AML_ORIGINAL_PWD=${PWD}",
*input_envs,
*output_keys,
*pre_cmds,
shlex.join(["cd", cli_command.cwd]),
shlex.join(cli_command.argv),
*post_cmds,
]
)

env_ops.create_or_update(Environment(**config.environment._asdict()))
extra_aml_command_args = self._app.get(AppConfigs.COMMAND_KWARGS)

Check warning on line 643 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

rats-devtools/src/rats/aml/_app.py#L642-L643

Added lines #L642 - L643 were not covered by tests

job = command(

Check warning on line 645 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L645 was not covered by tests
command=cmd,
compute=config.compute,
environment=config.environment.full_name,
outputs={
k: Output(type=v.type, path=v.path, mode=v.mode) for k, v in config.outputs.items()
},
inputs={
k: Input(type=v.type, path=v.path, mode=v.mode) for k, v in config.inputs.items()
},
environment_variables=dict(cli_command.env),
**extra_aml_command_args,
)
returned_job = job_ops.create_or_update(job) # type: ignore[reportUnknownMemberType]
logger.info(f"created job: {returned_job.name}")

Check warning on line 659 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

rats-devtools/src/rats/aml/_app.py#L658-L659

Added lines #L658 - L659 were not covered by tests

self._request = Request(

Check warning on line 661 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L661 was not covered by tests
job_name=str(returned_job.name),
wait=wait,
)

if wait:
logger.info(f"waiting for completion of job: {returned_job.name}")
job_ops.stream(str(returned_job.name))

Check warning on line 668 in rats-devtools/src/rats/aml/_app.py

View check run for this annotation

Codecov / codecov/patch

rats-devtools/src/rats/aml/_app.py#L667-L668

Added lines #L667 - L668 were not covered by tests

@cache # noqa: B019
def _runtime_list(self) -> tuple[str, ...]:
"""
Expand Down
Loading