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

Change init from a function into a context manager #112

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open

Conversation

BvB93
Copy link
Collaborator

@BvB93 BvB93 commented Dec 1, 2021

This PR changes plams.init from a function into a context manager.

In addition to calling it as a normal function, as could be done previously, plams.init can now be used on conjunction with the with statement. In the latter case plams.finish will be automatically called upon exiting the context manager.

Examples

>>> from scm.plams import Molecule, Settings, AMSJob, init, finish

>>> mol: Molecule = ...
>>> settings: Settings = ...

>>> with init():
...     job1 = AMSJob(molecule=mol, settings=settings)
...     result1 = job1.run()

# Equivalently:
>>> init()
>>> job2 = AMSJob(molecule=mol, settings=settings)
>>> result2 = job2.run()
>>> finish()

@BvB93 BvB93 force-pushed the init branch 3 times, most recently from e93e37f to 0393e96 Compare May 27, 2022 13:22
core/functions.py Outdated Show resolved Hide resolved
core/functions.py Outdated Show resolved Hide resolved
core/functions.py Outdated Show resolved Hide resolved
core/functions.py Outdated Show resolved Hide resolved
@miron-scm
Copy link
Contributor

If possible it would be nice to have a unit test proving that both the context manager syntax and the normal syntax work.

Co-Authored-By: miron-scm <[email protected]>
@BvB93
Copy link
Collaborator Author

BvB93 commented Jun 16, 2023

If possible it would be nice to have a unit test proving that both the context manager syntax and the normal syntax work.

Sorry, but considering the PLAMS test suite (at least on github) currently lacks any sort of infrastructure for testing the likes of init, job managers or running actual jobs I'm going to have to decline here, as this would involve this would effectively require setting up a whole new suite of testing infrastructure.

@dormrod dormrod deleted the branch trunk August 27, 2024 12:08
@dormrod dormrod closed this Aug 27, 2024
@dormrod dormrod reopened this Aug 27, 2024
@dormrod dormrod changed the base branch from master to trunk August 27, 2024 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants