{ "cells": [ { "cell_type": "markdown", "id": "alert-prague", "metadata": {}, "source": [ "# 1.7 Integration with Sacred\n", "\n", "\n", "
\n", "NOTE: These cells are not executable code, but are meant to serve as a guideline for setting up a Sacred project with signac\n", " \n", "
" ] }, { "cell_type": "markdown", "id": "final-virus", "metadata": {}, "source": [ "\n", "Here we demonstrate how to integrate a [sacred](https://sacred.readthedocs.io/) experiment with **signac-flow**.\n", "Assuming the following sacred experiment defined in a ``experiment.py`` module:\n", "\n", "\n", "``` python\n", "from sacred import Experiment\n", "\n", "ex = Experiment('jupyter_ex', interactive=True)\n", "\n", "\n", "@ex.automain\n", "def hello(foo):\n", " print(\"hello\", foo)\n", " \n", "```" ] }, { "cell_type": "markdown", "id": "registered-margin", "metadata": {}, "source": [ "Then we can integrate that experiment on a *per job* basis as defined in `project.py` :\n", "\n", "```python\n", "from flow import FlowProject\n", "class SacredProject(FlowProject):\n", " pass\n", "\n", "\n", "@SacredProject.operation\n", "def run_experiment(job):\n", " ex.add_config(**job.sp())\n", " ex.observers[:] = [FileStorageObserver.create(job.fn(\"my_runs\"))]\n", " ex.run()\n", "```\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.5" } }, "nbformat": 4, "nbformat_minor": 5 }