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

Add PyHPS CLI #3091

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Add PyHPS CLI #3091

wants to merge 13 commits into from

Conversation

germa89
Copy link
Collaborator

@germa89 germa89 commented May 14, 2024

As the title.

The idea is you can have:

$ pymapdl submit main_file.py 
$ pymapdl submit --name="my project" main_file.py --requirements_file=requirements.txt

The help shows:

(venv) pymapdl $ pymapdl submit --help
Usage: pymapdl submit [OPTIONS] MAIN_FILE

  Submit jobs to an HPC cluster using PyHPS package.

Options:
  --name TEXT                 Name of the PyHPS project to be created.
  --url TEXT                  URL where the HPS cluster is deployed. For
                              example: "https://myserver:3000/hps"
  --user TEXT                 Username to login into the HPC cluster.
  --password TEXT             Password used to login into the HPC cluster.
  --python TEXT               Set python version to be used to create the
                              virtual environment and run the python file. By
                              default it uses python3 (default in cluster).
  --output_files TEXT         Set the output files to be monitored.
  --shell_file TEXT           If desired, you can provide a shell script to
                              execute instead of the python file. You can call
                              your python file from it if you wish. By
                              default, it is not used.
  --requirements_file TEXT    If provided, the created virtual environment is
                              installed with the libraries specified in this
                              file. If not, the activated virtual environment
                              is cloned through a temporary 'pip list' file.
                              If you are using editable package, it is
                              recommended you attach your own requirement file
                              using ``pip freeze``
  --extra_files TEXT          To upload extra files which can be called from
                              your main python file (or from the shell file).
  --config_file TEXT          To load job configuration from a file.
  --num_cores TEXT            Set the amount of CPU cores reserved for the
                              job. By default it is 1 CPU.
  --memory TEXT               Set the amount of memory RAM in MB reserved for
                              the job. By default it is 100 MB.
  --disk_space TEXT           Set the amount of hard drive space in MB
                              reserved for the job. By default it is 100 MB.
  --exclusive TEXT            Set the job to run in a machine exclusively,
                              without sharing it with other jobs. By default
                              it is False
  --max_execution_time TEXT   Set the maximum execution time for the job. By
                              default it is zero (unlimited).
  --wait TEXT                 Set the terminal to wait for job completion
                              before return the control to the user.
  --save_config_file BOOLEAN  Writes the configuration to the config file,
                              after successfully submit the job. It overwrites
                              the configuration file. The configuration file
                              path is given using ``config_file`` argument.
  --debug BOOLEAN             Set PyMAPDL to prints the debug logging to the
                              console output.
  --help                      Show this message and exit.

@germa89 germa89 added the New Feature Request or proposal for a new feature label May 14, 2024
@germa89 germa89 requested a review from koubaa May 14, 2024 15:41
@germa89 germa89 self-assigned this May 14, 2024
@ansys-reviewer-bot
Copy link
Contributor

Thanks for opening a Pull Request. If you want to perform a review write a comment saying:

@ansys-reviewer-bot review

@github-actions github-actions bot added the Enhancement Improve any current implemented feature label May 14, 2024
@codecov-commenter
Copy link

codecov-commenter commented May 14, 2024

Codecov Report

Attention: Patch coverage is 6.29371% with 536 lines in your changes missing coverage. Please review.

Project coverage is 79.74%. Comparing base (3dcb798) to head (a7adf0b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3091      +/-   ##
==========================================
- Coverage   86.61%   79.74%   -6.88%     
==========================================
  Files          52       54       +2     
  Lines        9528    10100     +572     
==========================================
- Hits         8253     8054     -199     
- Misses       1275     2046     +771     

)

if config_file is None:
config_file = os.path.join(os.getcwd(), "hps_config.json")
Copy link
Contributor

Choose a reason for hiding this comment

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

@germa89 should the config be in appdirs instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

MMhhh... if we use a file in the root directory, we could point to different files.... and hence multiple configurations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But maybe you are right... maybe it is better to use appdirs.... buttt... it might be a bit hidden for the user...

Copy link
Collaborator Author

@germa89 germa89 May 16, 2024

Choose a reason for hiding this comment

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

And we have many options to be keep in the file:

{
    "url": "https://10.231.106.91:3000/hps",
    "user": "repuser",
    "password": "repuser",
    "python": "3.9",
    "name": "my job",
    "num_cores": 1,
    "memory": 100,
    "disk_space": 100,
    "exclusive": false,
    "max_execution_time": 1000
}

keeping so many important options hidden in a appdir path might bring some complications.

Copy link
Contributor

Choose a reason for hiding this comment

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

@germa89 use keyring for user/password. I don't think its secure enough to put that in plaintext like this. For everything else I would agree

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree.

max_execution_time=max_execution_time,
)

if save_config_file:
Copy link
Contributor

Choose a reason for hiding this comment

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

@germa89 ideally there could be multiple configurations that can be saved so that users can switch between clusters easily.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You can easily change the file path in config_file to point to other configurations

max_execution_time: int = None,
):

if python not in [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12]:
Copy link
Contributor

@koubaa koubaa May 14, 2024

Choose a reason for hiding this comment

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

why not 3.8+?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you mean 3.8.X ??

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In theory, only major and minor needs to be specified in the bash command (python3.12 -m venv...), hence we do not need to use the "patch" number.

Copy link
Contributor

Choose a reason for hiding this comment

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

@germa89 no, I mean, why bother supporting python < 3.8

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some hpc clusters have old python versions. So i dont want to limitate the compatibility. But probably, HPS might force you to some python version minimal requirement.

requirements_file = create_tmp_file("requirements.txt", content)
logger.debug(f"Requirements file in: {requirements_file}")

if not shell_file:
Copy link
Contributor

@koubaa koubaa May 14, 2024

Choose a reason for hiding this comment

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

Shell file is needed because pyhps doesn't support python jobs with a venv. I think we should see if that feature can be added to pyhps itself. Maybe using pip-run

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree we need to support venv within pyhps. Using pip-run seems interesting. For flexibility I would keep an optional shell file though.

requirements_file: str = None,
extra_files: Optional[Union[str, list]] = None,
config_file: str = None,
num_cores: int = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

option to download the result files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am not aware if we can do that from the PyHPS library... i will check it out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, It can be done.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com>
src/ansys/mapdl/core/cli/hpc.py Outdated Show resolved Hide resolved
src/ansys/mapdl/core/cli/hpc.py Outdated Show resolved Hide resolved
@germa89
Copy link
Collaborator Author

germa89 commented May 21, 2024

(To be merged from top to bottom to main)

* Adding inputs and outputs

* Changing arguments order

* Apply suggestions from code review

Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com>

* Update src/ansys/mapdl/core/cli/hpc.py

---------

Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com>
* Adding inputs and outputs

* Supporting pure APDL jobs

* Changing arguments order

* Allowing force mode

* Apply suggestions from code review

Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com>

---------

Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com>
germa89 and others added 2 commits May 31, 2024 17:29
* Adding inputs and outputs

* Supporting pure APDL jobs

* Allowing force mode

* Initial implementation.

Making task object detachable

* Apply suggestions from code review

Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com>

* Added job definition bypasser

* Adapting CLI

* Adding option for output and wait

* fixing python and cpu issues

* Using dict for taskdefinition
Allowing outputs in apdl mode

* Adding `close_client` method

---------

Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com>
@germa89 germa89 requested a review from a team as a code owner June 5, 2024 10:12

pymapdl convert input_file.inp -o output_file.out ...

For more information please visit: https://mapdl.docs.pyansys.com/version/dev/user_guide/cli.html
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
For more information please visit: https://mapdl.docs.pyansys.com/version/dev/user_guide/cli.html
For more information, see `PyMAPDL command line interface <https://mapdl.docs.pyansys.com/version/dev/user_guide/cli.html>`_.

Is there a reason, you don't use a :ref: role for a link?

help="""URL where the HPS cluster is deployed. For example: "https://myserver:3000/hps" """,
)
@click.option(
"--user", default=None, type=str, help="Username to login into the HPC cluster."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"--user", default=None, type=str, help="Username to login into the HPC cluster."
"--user", default=None, type=str, help="Username for logging into the HPC cluster."

Comment on lines +81 to +83
Input arguments for the simulation. You can specify several arguments by
joining them with commas. Thus, strings defined in this way cannot contain
commas. Only integers, floats and strings are allowed.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Input arguments for the simulation. You can specify several arguments by
joining them with commas. Thus, strings defined in this way cannot contain
commas. Only integers, floats and strings are allowed.
Input arguments for the simulation. Because you can specify several arguments by
joining them with commas, strings defined in this way cannot contain
commas. Only integers, floats, and strings are allowed.

Comment on lines +101 to +102
help="""Output files to monitor. Because you use commas to separate
the file names, the names cannot contain commas. For example,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
help="""Output files to monitor. Because you use commas to separate
the file names, the names cannot contain commas. For example,
help="""Output files to monitor. Because you use commas to separate
filenames, the names cannot contain commas. For example,

help="""Optional created virtual environment to install with the
libraries specified in this requirements file. If not, the activated virtual environment is
cloned through a temporary ``pip list`` file. If you are using an editable package,
you should attach your own requirement file using ``pip freeze`` """,
Copy link
Member

@PipKat PipKat Jun 5, 2024

Choose a reason for hiding this comment

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

Suggested change
you should attach your own requirement file using ``pip freeze`` """,
you should attach your own requirement file using ``pip freeze``.""",

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. """,
Copy link
Member

Choose a reason for hiding this comment

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

Not sure I understand this: It requires to use --wait value too.

type=bool,
is_flag=False,
flag_value=True,
help="""Whether PyMAPDL is to print debug logging to the console output.""",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
help="""Whether PyMAPDL is to print debug logging to the console output.""",
help="""Whether PyMAPDL is to print debug logging to the console.""",

It doesn't seem output is needed.

}

logger.debug(
f"Saving the following configuration to the config file ({config_file}):\n{config}"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
f"Saving the following configuration to the config file ({config_file}):\n{config}"
f"Saving the following configuration to the config file ({config_file}):\n{config}."

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

Choose a reason for hiding this comment

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

Messages should conclude with punctuation, but I don't enforce this when a colon is used to provide a URL or filename

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Improve any current implemented feature New Feature Request or proposal for a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants