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

Refactoring PyHPS implementation #3117

Merged
merged 13 commits into from
May 31, 2024
50 changes: 35 additions & 15 deletions src/ansys/mapdl/core/cli/hpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@
By default, PyMAPDL detects the type of file from its extension.
""",
)
@click.option(
"--output_to_json",
default=None,
type=str,
is_flag=False,
flag_value=True,
help="""Print the output values to the terminal as json. It requires to use ``--wait`` value too. """,
)
@click.option(
"--debug",
default=False,
Expand Down Expand Up @@ -225,13 +233,13 @@
wait: bool = False,
debug: bool = False,
mode: Optional[Union["python", "shell", "apdl"]] = None,
output_to_json: Optional[bool] = False,
):
import json

from ansys.mapdl.core.hpc.pyhps import (
create_pymapdl_pyhps_job,
PyMAPDLJobSubmission,
get_value_from_json_or_default,
wait_for_completion,
)

if debug:
Expand Down Expand Up @@ -261,28 +269,29 @@
max_execution_time, config_file, "max_execution_time", 0
)

proj, _ = create_pymapdl_pyhps_job(
main_file=main_file,
name=name,
job = PyMAPDLJobSubmission(

Check warning on line 272 in src/ansys/mapdl/core/cli/hpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/hpc.py#L272

Added line #L272 was not covered by tests
url=url,
user=user,
password=password,
python=python,
main_file=main_file,
mode=mode,
inputs=inputs,
outputs=outputs,
output_files=output_files,
shell_file=shell_file,
requirements_file=requirements_file,
shell_file=shell_file,
extra_files=extra_files,
config_file=config_file,
output_files=output_files,
python=python,
num_cores=num_cores,
memory=memory,
disk_space=disk_space,
exclusive=exclusive,
max_execution_time=max_execution_time,
mode=mode,
name=name,
)

job.submit()

Check warning on line 293 in src/ansys/mapdl/core/cli/hpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/hpc.py#L293

Added line #L293 was not covered by tests

if save_config_file:
config = {
"url": url,
Expand All @@ -303,13 +312,24 @@
with open(config_file, "w") as fid:
json.dump(config, fid)

print(
f"You can check your project by visiting: {url}/projects#/projects/{proj.id}/jobs"
)
proj = job.project
if not output_to_json:
print(

Check warning on line 317 in src/ansys/mapdl/core/cli/hpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/hpc.py#L315-L317

Added lines #L315 - L317 were not covered by tests
f"You can check your project by visiting: {url}/projects#/projects/{proj.id}/jobs"
)

if wait:
print(f"Waiting for project {name} (id: {proj.id}) evaluation to complete...")
wait_for_completion(proj, evaluated=True, failed=True)
if not output_to_json:
print(

Check warning on line 323 in src/ansys/mapdl/core/cli/hpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/hpc.py#L322-L323

Added lines #L322 - L323 were not covered by tests
f"Waiting for project {name} (id: {proj.id}) evaluation to complete..."
)
job.wait_for_completion(evaluated=True, failed=True)

Check warning on line 326 in src/ansys/mapdl/core/cli/hpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/hpc.py#L326

Added line #L326 was not covered by tests

if output_to_json and wait:
if len(job.outputs) == 1:
print(job.output_values[0][job.outputs[0]])

Check warning on line 330 in src/ansys/mapdl/core/cli/hpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/hpc.py#L328-L330

Added lines #L328 - L330 were not covered by tests
else:
print(json.dumps(job.output_values))

Check warning on line 332 in src/ansys/mapdl/core/cli/hpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/hpc.py#L332

Added line #L332 was not covered by tests


def list_jobs():
Expand Down
Loading
Loading