aiida-calcmonitor


Nameaiida-calcmonitor JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryDescription pending.
upload_time2023-06-09 16:25:52
maintainerNone
docs_urlNone
authorFFR
requires_python>=3.8
licenseNone
keywords aiida plugin
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # aiida-calcmonitor

AiiDA plugin that contains tools for monitoring ongoing calculations.

## Development Install

```shell
git clone git@github.com:ramirezfranciscof/aiida-calcmonitor.git .
cd aiida-calcmonitor
pip install --upgrade pip
pip install -e .

# These are not available yet!
pip install -e .[pre-commit,testing]  # install extra dependencies
pre-commit install  # install pre-commit hooks
pytest -v  # discover and run all tests
```

## Running the monitor test

To run the monitoring test you need to have an existing aiida profile.
You must set up a computer in which to run the toymodel code (the `aiida_calcmonitor/utils/toymodel_code.sh` needs to be copied into the computer and you also need to setup a code in AiiDA).
You can set up the localhost like this:

``` console
$ verdi computer setup -L localhost -H localhost -T local -S direct -w /scratch/{username}/aiida/ --mpiprocs-per-machine 1 -n
$ verdi computer configure local localhost --safe-interval 5 -n
```

For running the calcjob monitor calcjob, you will need to set up a special kind of localhost with the following Mpirun command: `verdi -p <PROFILE_NAME> run` (replacing `<PROFILE_NAME>` with the corresponding one).
It also needs to have a prepend that activates the virtual environment that aiida is using.
For a typical python virtual environment you can do something like this:

``` console
source /home/username/.virtualenvs/aiida/bin/activate
```

Once all if this is set up, you can use the example in `/examples/example01/submit_everything.py` as a template on how to prepare and submit a toymodel calculation and monitor.


## Creating your own monitors

To create your own monitor, you need to subclass the `MonitorBase` class.
This is a data type derived from `Dict`, so the idea is that you are going to create a sub-data type with a method that describes the checking procedure, you then are going to create a data node from that subtype which contains a dict with the options for that procedure, and the monitor code will get that data node input and call the checking method.

This is just an example to show the critical variables that are accessible from the parent class (`self[...]`) and the returns that need to be used, but the structure can be modified however it is necessary (no need to set and use the `error_detected` boolean for example, you can just return error messages in the middle of the checks).

``` python
class NewMonitorSubclass(MonitorBase):  # pylint: disable=too-many-ancestors
    """Example of monitor for the toy model."""

    def monitor_analysis(self):
        
        sources = self['sources']
        # this contains the mapping to the actual filepaths (see below)

        options = self['options']
        # this contains the specific options for this method (the structure is determined here in this method and the user must know what is expected when constructing it)

        retrieve = self['retrieve']
        # there will also be a list of files to retrieve if the original calculation is killed, but this should probably not be needed here

        internal_naming = sources['internal_naming']['filepath']
        # This is how you access the mapping for the files; now internal_naming contains the actual path to the file it requires

        with open(internal_naming) as fileobj:
            # Here one performs the parsing of the files and checking.
            # Setups the variables error_detected and error_msg or equivalent

        if error_detected:
            return f'An error was detected: {error_msg}'        
            # The calcjob_monitor will interpret string returns as errors and will kill the process
        else:
            return None
            # The calcjob_monitor will interpret None returns to mean everything is going fine
```

In order to be usable, you also need to add this as an entry point / plugin, inside of the `pyproject.toml` for example:

``` toml
[project.entry-points."aiida.data"]
"calcmonitor.monitor.toymodel" = "aiida_calcmonitor.data.monitors.monitor_toymodel:MonitorToymodel"
"calcmonitor.monitor.newmonitor" = "aiida_calcmonitor.data.monitors.newmonitor_file:NewMonitorSubclass"
```

## License

MIT



            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "aiida-calcmonitor",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "aiida,plugin",
    "author": "FFR",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/35/b1/f12958f0e764b5ce38809fc362886996a95701965164e290a6df3347b013/aiida_calcmonitor-0.1.0.tar.gz",
    "platform": null,
    "description": "# aiida-calcmonitor\n\nAiiDA plugin that contains tools for monitoring ongoing calculations.\n\n## Development Install\n\n```shell\ngit clone git@github.com:ramirezfranciscof/aiida-calcmonitor.git .\ncd aiida-calcmonitor\npip install --upgrade pip\npip install -e .\n\n# These are not available yet!\npip install -e .[pre-commit,testing]  # install extra dependencies\npre-commit install  # install pre-commit hooks\npytest -v  # discover and run all tests\n```\n\n## Running the monitor test\n\nTo run the monitoring test you need to have an existing aiida profile.\nYou must set up a computer in which to run the toymodel code (the `aiida_calcmonitor/utils/toymodel_code.sh` needs to be copied into the computer and you also need to setup a code in AiiDA).\nYou can set up the localhost like this:\n\n``` console\n$ verdi computer setup -L localhost -H localhost -T local -S direct -w /scratch/{username}/aiida/ --mpiprocs-per-machine 1 -n\n$ verdi computer configure local localhost --safe-interval 5 -n\n```\n\nFor running the calcjob monitor calcjob, you will need to set up a special kind of localhost with the following Mpirun command: `verdi -p <PROFILE_NAME> run` (replacing `<PROFILE_NAME>` with the corresponding one).\nIt also needs to have a prepend that activates the virtual environment that aiida is using.\nFor a typical python virtual environment you can do something like this:\n\n``` console\nsource /home/username/.virtualenvs/aiida/bin/activate\n```\n\nOnce all if this is set up, you can use the example in `/examples/example01/submit_everything.py` as a template on how to prepare and submit a toymodel calculation and monitor.\n\n\n## Creating your own monitors\n\nTo create your own monitor, you need to subclass the `MonitorBase` class.\nThis is a data type derived from `Dict`, so the idea is that you are going to create a sub-data type with a method that describes the checking procedure, you then are going to create a data node from that subtype which contains a dict with the options for that procedure, and the monitor code will get that data node input and call the checking method.\n\nThis is just an example to show the critical variables that are accessible from the parent class (`self[...]`) and the returns that need to be used, but the structure can be modified however it is necessary (no need to set and use the `error_detected` boolean for example, you can just return error messages in the middle of the checks).\n\n``` python\nclass NewMonitorSubclass(MonitorBase):  # pylint: disable=too-many-ancestors\n    \"\"\"Example of monitor for the toy model.\"\"\"\n\n    def monitor_analysis(self):\n        \n        sources = self['sources']\n        # this contains the mapping to the actual filepaths (see below)\n\n        options = self['options']\n        # this contains the specific options for this method (the structure is determined here in this method and the user must know what is expected when constructing it)\n\n        retrieve = self['retrieve']\n        # there will also be a list of files to retrieve if the original calculation is killed, but this should probably not be needed here\n\n        internal_naming = sources['internal_naming']['filepath']\n        # This is how you access the mapping for the files; now internal_naming contains the actual path to the file it requires\n\n        with open(internal_naming) as fileobj:\n            # Here one performs the parsing of the files and checking.\n            # Setups the variables error_detected and error_msg or equivalent\n\n        if error_detected:\n            return f'An error was detected: {error_msg}'        \n            # The calcjob_monitor will interpret string returns as errors and will kill the process\n        else:\n            return None\n            # The calcjob_monitor will interpret None returns to mean everything is going fine\n```\n\nIn order to be usable, you also need to add this as an entry point / plugin, inside of the `pyproject.toml` for example:\n\n``` toml\n[project.entry-points.\"aiida.data\"]\n\"calcmonitor.monitor.toymodel\" = \"aiida_calcmonitor.data.monitors.monitor_toymodel:MonitorToymodel\"\n\"calcmonitor.monitor.newmonitor\" = \"aiida_calcmonitor.data.monitors.newmonitor_file:NewMonitorSubclass\"\n```\n\n## License\n\nMIT\n\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Description pending.",
    "version": "0.1.0",
    "project_urls": {
        "Source": "https://github.com/ramirezfranciscof/aiida-calcmonitor"
    },
    "split_keywords": [
        "aiida",
        "plugin"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3360c5032f381b8f1c8d0084bba3f3ace9136b7f9b29d982e1c1bb6dfd125b48",
                "md5": "31b3ba9da56936e6692e4fb54ef0db84",
                "sha256": "cff141b562f6c74a48cf75d2a1b7a0da2387f238f4b4dc7150e5d6e7ac4b7320"
            },
            "downloads": -1,
            "filename": "aiida_calcmonitor-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "31b3ba9da56936e6692e4fb54ef0db84",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 19740,
            "upload_time": "2023-06-09T16:25:39",
            "upload_time_iso_8601": "2023-06-09T16:25:39.743726Z",
            "url": "https://files.pythonhosted.org/packages/33/60/c5032f381b8f1c8d0084bba3f3ace9136b7f9b29d982e1c1bb6dfd125b48/aiida_calcmonitor-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "35b1f12958f0e764b5ce38809fc362886996a95701965164e290a6df3347b013",
                "md5": "d8683c3764e0590d4b2e12378127456b",
                "sha256": "d1648730bc16df856f466805613dab79aa3b78969e0de351fa547cc0a1765ed2"
            },
            "downloads": -1,
            "filename": "aiida_calcmonitor-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d8683c3764e0590d4b2e12378127456b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 100544,
            "upload_time": "2023-06-09T16:25:52",
            "upload_time_iso_8601": "2023-06-09T16:25:52.796707Z",
            "url": "https://files.pythonhosted.org/packages/35/b1/f12958f0e764b5ce38809fc362886996a95701965164e290a6df3347b013/aiida_calcmonitor-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-09 16:25:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ramirezfranciscof",
    "github_project": "aiida-calcmonitor",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "aiida-calcmonitor"
}
        
FFR
Elapsed time: 0.07342s