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

Implement decorators in pyiron_base #1667

Merged
merged 12 commits into from
Oct 15, 2024
Merged

Implement decorators in pyiron_base #1667

merged 12 commits into from
Oct 15, 2024

Conversation

jan-janssen
Copy link
Member

First implementation with decorator arguments:

from pyiron_base import pyiron_job, Project

pr = Project("test")

@pyiron_job(project=pr, cores=2)
def my_function(a, b=8):
    return a + b

c = my_function(a=1, b=2)
d = my_function(a=c, b=3)
d.pull()
>>> 6

The disadvantage of this approach is that the decorator requires the () even without parameters:

@pyiron_job()
def my_function(a, b=8):
    return a + b

To address this limitation I created a second implementation:

from pyiron_base import pyiron_job_simple, Project

@pyiron_job_simple
def my_function(a, b=8):
    return a + b

pr = Project("test")
c = my_function(a=1, b=2, project=pr)
d = my_function(a=c, b=3, project=pr, resource_dict={"cores": 2})
d.pull()
>>> 6

@samwaseda
Copy link
Member

@jan-janssen I unified pyiron_job_simple and pyiron_job so that pyiron_job works with or without parentheses. If you don't like it you can revert it.

@jan-janssen
Copy link
Member Author

@jan-janssen I unified pyiron_job_simple and pyiron_job so that pyiron_job works with or without parentheses. If you don't like it you can revert it.

Nice catch - I really like the suggestion. From my perspective it is ready to be merged.

@samwaseda
Copy link
Member

Can you copy and paste your first comment in this PR in the doc string?

Base automatically changed from delayed_server_obj to main October 14, 2024 13:00
@jan-janssen jan-janssen marked this pull request as draft October 14, 2024 14:20
@jan-janssen jan-janssen marked this pull request as ready for review October 14, 2024 16:05
@jan-janssen jan-janssen changed the title Implement two suggestions for decorators in pyiron_base Implement decorators in pyiron_base Oct 14, 2024
@jan-janssen
Copy link
Member Author

I updated the pull request based on the feedback from the pyiron meeting today.

@jan-janssen
Copy link
Member Author

Can you copy and paste your first comment in this PR in the doc string?

@samwaseda I added the doc strings as requested.

pyiron_base/project/decorator.py Show resolved Hide resolved
pyiron_base/project/decorator.py Outdated Show resolved Hide resolved
jan-janssen and others added 2 commits October 15, 2024 09:22
Co-authored-by: Sam Dareska <37879103+samwaseda@users.noreply.github.com>
Co-authored-by: Sam Dareska <37879103+samwaseda@users.noreply.github.com>
@jan-janssen jan-janssen merged commit 67c806a into main Oct 15, 2024
26 checks passed
@jan-janssen jan-janssen deleted the decorator branch October 15, 2024 07:29
@jan-janssen
Copy link
Member Author

For future reference, the decorators in pyiron_base are inspired by the decorators in desk with the added ability to control the computing resources assigned to a given function https://docs.dask.org/en/stable/delayed.html#decorator .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants