{ "info": { "author": "Asterio Gonzalez", "author_email": "asterio.gonzalez@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Operating System :: OS Independent", "Topic :: Software Development :: Testing" ], "description": "# resume module\n\nThis module provide a support for saving and restoring the same interpreter\nstate in different executions saving the locals and some internal status\nlike random state in a checkpoint file.\n\nThe integration as been designed to be seamless:\n\n1. just create a checkpoint at the begging of the function\n2. set the 1st run time variables\n3. call restore() before the evolutionary process\n4. performs any computation cycles\n5. call sync() or save() meanwhile as your convenience to store current state.\n\nIf the code is interrupted for an reason, the next execution will:\n\n1. use the same checkpoint definition to locate the saved state.\n2. define the same variables as initial placeholders\n3. calling restore() will load these variables from disk\n4. the computation cycles continue from last saved state.\n5. the same sync() or save() will keep your step forward work save.\n\n**Notes**:\n\n- the name of the checkpoint is auto-magically selected from the function name.\n- sync() will save state only if the elapsed time from last save if bigger\n than a rate (passed in constructor)\n- save() always dump state into disk\n- use numpy.random module instead python random module due the lack of seed\n recovery in python library.\n On the contrary numpy provide a get_state() and set_state() for this propose.\n\n\n## Abstract\n\nIn situations where we are developing an application or library that will be use to create long computation reports or results, we want to recover the progress of the computation in case of failure or environmental changes.\n\nThe integration with existing code must be seamless, hiding all the details to the user. Actually there is only 3 code lines you should insert in your existing code.\n\n1. instantiate a checkpoint, usually at the begining of the function of code.\n2. select the restoration point in case of re-run\n3. decide when save the internal state within loop calculations.\n\n## Show me an example\n\nLet' say that we have this code for compute prime numbers:\n\n```python\ndef compute_primes(n=10):\n \"compute n 1st primes\"\n # define initial state of the algorithm\n i = 2\n primes = [i]\n candidate = primes[-1]\n\n while n > 0:\n candidate += 1\n for p in primes:\n if not candidate % p:\n break\n else:\n primes.append(candidate)\n n -= 1\n return primes\n```\n\nWe can reuse previous computation using checkpoint support.\n\nThe changes in the code are:\n\n```python\ndef compute_primes(n=10):\n \"compute n next primes\"\n chp = Checkpoint()\n # define initial state of the algorithm\n i = 2\n primes = [i]\n candidate = primes[-1]\n\n # restore previous work (if any)\n chp.restore() # note that 'n' preserve the current calling value\n\n # continue from last time (or initial state)\n while n > 0:\n candidate += 1\n for p in primes:\n if not candidate % p:\n break\n else:\n primes.append(candidate)\n n -= 1\n # dump current state to disk. Next call will continue from here\n chp.save()\n return primes\n```\n\nand some code for testing\n\n```python\n>>> N=5\n>>> primes_1 = compute_primes()\n[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]\n>>> primes_2 = compute_primes(n=N)\n[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53]\n>>> assert len(primes_1) > 0\n>>> assert len(primes_2) == len(primes_1) + N\n```\n\n## Notes\n\n- The checkpoint is stored in compressed pickle format\n- Checkpoints preserve numpy random state to guarantee the same results as if the process will not be interrupted\n- Checkpoints are stored in '.checkpoints/' hidden folder by default.\n- checkpoints will be discarded if las update is beyond of CACHE_EXPIRE by default.\n- checkpoints store all basic types and numpy types by default.\n- The code is in alpha version, any comment of pull request is welcome.\n\n## Install\n\n```\n$ pip install resume\n```\n\nor download and improve the code by yourself :) installing in develop mode in your home directory\n\n```\n python setup.py develop --user\n```\n\n\n## Python versions\n\nIs tested only in python 2.7 yet, but there is not any deliberated incompatibility with python 3.x versions.\n\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/asteriogonzalez/resume", "keywords": "testing,pytest,long_run,resume", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "resume", "package_url": "https://pypi.org/project/resume/", "platform": "", "project_url": "https://pypi.org/project/resume/", "project_urls": { "Homepage": "https://github.com/asteriogonzalez/resume" }, "release_url": "https://pypi.org/project/resume/0.13/", "requires_dist": [ "numpy" ], "requires_python": "", "summary": "Save/Restore interpreter running state to resume interruped computations", "version": "0.13" }, "last_serial": 3209758, "releases": { "0.12": [ { "comment_text": "", "digests": { "md5": "8d8bf053a59b8a7f3e3ba4f6c319a9dc", "sha256": "ad6a8ce8d3c692172fd21ec8e4079541c13e9f9490f636e2a250fd4533196679" }, "downloads": -1, "filename": "resume-0.12-py2-none-any.whl", "has_sig": false, "md5_digest": "8d8bf053a59b8a7f3e3ba4f6c319a9dc", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 8889, "upload_time": "2017-09-28T10:56:41", "url": "https://files.pythonhosted.org/packages/3f/e9/7ba51ef338fff11d80ec63fef6801614a4bfa0a39e80ffed74871e1df5e4/resume-0.12-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "54c001c374988ba0383bee1f5c408782", "sha256": "a81088df42c920d0205a07c0cc07669e3b1284cb1d3ba43be8e6cd86e6f7ad41" }, "downloads": -1, "filename": "resume-0.12.tar.gz", "has_sig": false, "md5_digest": "54c001c374988ba0383bee1f5c408782", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3550, "upload_time": "2017-09-28T10:56:42", "url": "https://files.pythonhosted.org/packages/b9/76/2afbdce94c18f4879bc8592ed6c4bb6220f5ba1c41ff75f8b2dcff38d714/resume-0.12.tar.gz" } ], "0.13": [ { "comment_text": "", "digests": { "md5": "5e7b7fe64bd284d919dbff5933cf6534", "sha256": "bac238187198798a3cb0bec341bc4a2ab4638f57ca7ef0cce6c5b5cbf9009615" }, "downloads": -1, "filename": "resume-0.13-py2-none-any.whl", "has_sig": false, "md5_digest": "5e7b7fe64bd284d919dbff5933cf6534", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 8875, "upload_time": "2017-09-28T11:13:32", "url": "https://files.pythonhosted.org/packages/57/72/ea697408ad9fcc695dc50d979fb92a908c84fd6b89c427eeb11198ab45dc/resume-0.13-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2de159e3b5ef5dd62ddf03e7a3bdb272", "sha256": "21790557acd43d398c2377143b7ab2fa5df38696402fe3d3bc8713c4b12a1f8a" }, "downloads": -1, "filename": "resume-0.13.tar.gz", "has_sig": false, "md5_digest": "2de159e3b5ef5dd62ddf03e7a3bdb272", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5927, "upload_time": "2017-09-28T11:13:33", "url": "https://files.pythonhosted.org/packages/91/48/ad8ab4b6b52a767202944050512c3c5e4a988275fcb8b853983c9659c44a/resume-0.13.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5e7b7fe64bd284d919dbff5933cf6534", "sha256": "bac238187198798a3cb0bec341bc4a2ab4638f57ca7ef0cce6c5b5cbf9009615" }, "downloads": -1, "filename": "resume-0.13-py2-none-any.whl", "has_sig": false, "md5_digest": "5e7b7fe64bd284d919dbff5933cf6534", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 8875, "upload_time": "2017-09-28T11:13:32", "url": "https://files.pythonhosted.org/packages/57/72/ea697408ad9fcc695dc50d979fb92a908c84fd6b89c427eeb11198ab45dc/resume-0.13-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2de159e3b5ef5dd62ddf03e7a3bdb272", "sha256": "21790557acd43d398c2377143b7ab2fa5df38696402fe3d3bc8713c4b12a1f8a" }, "downloads": -1, "filename": "resume-0.13.tar.gz", "has_sig": false, "md5_digest": "2de159e3b5ef5dd62ddf03e7a3bdb272", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5927, "upload_time": "2017-09-28T11:13:33", "url": "https://files.pythonhosted.org/packages/91/48/ad8ab4b6b52a767202944050512c3c5e4a988275fcb8b853983c9659c44a/resume-0.13.tar.gz" } ] }