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

Execute jobs in separate conda environments #1315

Merged
merged 20 commits into from
Feb 8, 2024
Merged

Execute jobs in separate conda environments #1315

merged 20 commits into from
Feb 8, 2024

Conversation

jan-janssen
Copy link
Member

@jan-janssen jan-janssen commented Feb 4, 2024

Caution: Executing pyiron_base jobs in separate conda environments introduces additional overhead. When possible it is highly recommended to create one conda environment which combines all dependencies.

Feature:

For specific application it is required to execute parts of a given workflow in separate conda environments. For example in BAMresearch/NFDI4IngScientificWorkflowRequirements. For these special cases this pull request adds the functionality to pyiron_base to execute individual jobs in separate conda environments. Additional conda environments can be created with the Project() object using pr.conda_environment.create() and can be assigned to individual jobs using job.server.conda_environment_path = pr.conda_environment.py312.

Example:

pr = Project("Test")
pr.conda_environment.create(env_name="py312", env_file="env.yaml")
pr.create_job_class(
    class_name="PythonVersionJob",
    executable_str="python --version",
)
job = pr.create.job.PythonVersionJob(job_name="job_conda_path")
job.server.conda_environment_path = pr.conda_environment.py312
job.run()

jan-janssen and others added 5 commits January 22, 2024 11:08
Any pyiron job object which defines an external executable `job.executable` can now be executed in a separate conda environment. This is achieved by:

```
job.server.conda_environment_name = "py312"
job.run()
```
@jan-janssen jan-janssen marked this pull request as draft February 4, 2024 18:38
@jan-janssen
Copy link
Member Author

It would be great if we would have python bindings for the creation of conda environments - pyiron/conda_subprocess#4

Copy link
Member

@niklassiemer niklassiemer left a comment

Choose a reason for hiding this comment

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

I see the value of the addition in principle, however, tab completion would only show create and the getitem is hidden. Just using pr.conda_environment would only inform that this is a property.
Therefore, I would add a get method and provide a reasonable repr such that things are clear from the user perspective.

@jan-janssen
Copy link
Member Author

I see the value of the addition in principle, however, tab completion would only show create and the getitem is hidden. Just using pr.conda_environment would only inform that this is a property. Therefore, I would add a get method and provide a reasonable repr such that things are clear from the user perspective.

I agree a __repr__ function should be added for visualisation. Still I do not understand your concerns about the tab completion, as I overload the __dir__ method. I just missed to add the create method in the __dir__ function.

Copy link
Member

@niklassiemer niklassiemer left a comment

Choose a reason for hiding this comment

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

Yes, sorry I misread getattr and getitem and was confused!

pyiron_base/project/condaenv.py Outdated Show resolved Hide resolved
pyiron_base/project/condaenv.py Outdated Show resolved Hide resolved
pyiron_base/project/generic.py Outdated Show resolved Hide resolved
@jan-janssen jan-janssen added the format_black reformat the code using the black standard label Feb 5, 2024
@jan-janssen jan-janssen marked this pull request as ready for review February 7, 2024 09:45
@jan-janssen jan-janssen changed the title Add conda_environment property to Project Execute jobs in separate conda environments Feb 7, 2024
@niklassiemer
Copy link
Member

I did understand correctly, that you only use the other conda environment for starting the shell script running the actual computation? Or is it required that pyiron(_base) is also installed in the other conda environment?

super().setUpClass()
with open("env.yaml", "w") as f:
f.writelines(conda_env)
cls.project.conda_environment.create(env_name="py312", env_file="env.yaml")
Copy link
Member Author

Choose a reason for hiding this comment

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

The creation of conda environments fails on windows, so the windows tests are skipped for now.

@jan-janssen
Copy link
Member Author

I did understand correctly, that you only use the other conda environment for starting the shell script running the actual computation? Or is it required that pyiron(_base) is also installed in the other conda environment?

That is correct, only the external executable is executed in the different environment. This allows the external environments to be small and simplifies the integration on the pyiron side. Calling python functions in other conda environments is currently not supported.

@jan-janssen jan-janssen merged commit 440459c into main Feb 8, 2024
46 of 47 checks passed
@jan-janssen jan-janssen deleted the conda_env branch February 8, 2024 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
format_black reformat the code using the black standard
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants