-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
23 additions
and
23 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
_sources/notebooks/supplementary_examples/00_nearfield_ptychography.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
_sources/notebooks/supplementary_examples/01_object_regularisation.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
_sources/notebooks/supplementary_examples/02_live_visualisation.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"cells": [{"cell_type": "markdown", "id": "6044e4fe-966e-4008-9545-c33b9727f10d", "metadata": {}, "source": ["# Live visualisation\n", "**Learning how to use the ```PlotClient``` to look at the reconstruction while it is still running.**\n", "\n", "There many use cases where it can be useful to communicate between a remote process running the reconstruction and a local client process that wants to receive live information about the status of the reconstruction. In PtyPy, this is possible via ZMQ socket communication."]}, {"cell_type": "markdown", "id": "196b8869-ac86-48c3-a867-ca92585f9f48", "metadata": {}, "source": ["## Running the reconstruction in Python script\n", "\n", "First, we copy a YAML config file [./config/dls_i08_nanogold_spiral.yaml](./config/dls_i08_nanogold_spiral.yaml) from one of the previous examples making sure that we turn on the interaction server ```p.io.interaction.server``` \n", "\n", "```python\n", "p.io = u.Param()\n", "p.io.home = \"./\"\n", "p.io.rfile = \"recons/%(run)s_%(engine)s_%(iterations)04d.ptyr\"\n", "p.io.autosave = u.Param(active=False)\n", "p.io.autoplot = u.Param(active=False)\n", "p.io.interaction = u.Param(active=True)\n", "p.io.interaction.server = u.Param()\n", "p.io.interaction.server.port = 5580\n", "p.io.interaction.server.address = \"tcp://127.0.0.1\"\n", "```\n", "\n", "sending updates on localhost (127.0.0.1) at port 9001. We then create a Python run script reading from this config file\n", "\n", "```python\n", "with open(\"./ptypy_run_dls_i08_nanogold.py\", \"w\") as f:\n", " f.write(\"\"\"\\\n", "import ptypy\n", "ptypy.load_ptyscan_module(\"hdf5_loader\")\n", "ptypy.load_gpu_engines(\"cupy\") \n", "p = ptypy.utils.param_from_yaml(\"config/dls_i08_nanogold_spiral.yaml\")\n", "P = ptypy.core.Ptycho(p,level=5)\n", "\"\"\")\n", "```\n", "\n", "and execute the run script in a terminal\n", "\n", "```bash\n", "srun -n 4 -c 2 --gpus-per-task=1 --gpu-bin=None python ptypy_run_dls_i08_nanogold.py\n", "\n", "```"]}, {"cell_type": "markdown", "id": "169dd282-8217-4f22-a0c9-1c374e7fd3b8", "metadata": {}, "source": ["---"]}, {"cell_type": "code", "execution_count": null, "id": "b81d242c-deda-4b5d-a577-b55b42e46ac9", "metadata": {}, "outputs": [], "source": ["with open(\"./ptypy_run_dls_i08_nanogold.py\", \"w\") as f:\n", " f.write(\"\"\"\\\n", "import ptypy\n", "ptypy.load_ptyscan_module(\"hdf5_loader\")\n", "ptypy.load_gpu_engines(\"cupy\") \n", "p = ptypy.utils.param_from_yaml(\"config/dls_i08_nanogold_spiral.yaml\")\n", "P = ptypy.core.Ptycho(p,level=5)\n", "\"\"\")"]}, {"cell_type": "markdown", "id": "6a288a19-ea65-41f6-9bb3-0337a00dde6a", "metadata": {}, "source": ["## Running the plot client in this notebook\n", "\n", "While the processing script is running in a separate process, we just need to connect our client to the same address and port\n", "\n", "```python\n", "import ptypy\n", "\n", "client = ptypy.utils.Param()\n", "client.port = 5580\n", "client.address = \"tcp://127.0.0.1\"\n", "```\n", "\n", "and start an instance of the ```PlotClient```\n", "\n", "```python\n", "pc = ptypy.utils.PlotClient(client)\n", "pc.start()\n", "```\n", "\n", "and use its ```get_data()``` function to get updates\n", "\n", "```python\n", "plotter.pr, plotter.ob, runtime = pc.get_data()\n", "```\n", "\n", "on probe, object and runtime information. We can also use the ```MPLplotter``` create \n", "a plot that is updated by repeatedly executing a cell with this code\n", "\n", "```python\n", "from IPython import display\n", "plotter = ptypy.utils.MPLplotter()\n", "initialised = False\n", "if (pc.status == pc.DATA):\n", " plotter.pr, plotter.ob, runtime = pc.get_data()\n", " plotter.runtime.update(runtime)\n", " if not initialised:\n", " plotter.update_plot_layout()\n", " plotter.plot_all()\n", " plotter.draw()\n", " display.clear_output(wait=True)\n", " display.display(plotter.plot_fig)\n", "```"]}, {"cell_type": "markdown", "id": "deaa9e0c-8af9-4af8-b318-5f29f3c289a4", "metadata": {}, "source": ["---"]}, {"cell_type": "code", "execution_count": null, "id": "ca168d91-e5b8-4d41-8b5d-1c37035f906a", "metadata": {}, "outputs": [], "source": ["import ptypy\n", "\n", "# Client parameters\n", "client = ptypy.utils.Param()\n", "client.port = 5580\n", "client.address = \"tcp://127.0.0.1\"\n", "\n", "# Create instance of plotclient\n", "pc = ptypy.utils.PlotClient(client)\n", "\n", "# start listening\n", "pc.start()"]}, {"cell_type": "code", "execution_count": null, "id": "06fe8608-449e-4b66-a512-0f339ea7afe8", "metadata": {}, "outputs": [], "source": ["# Refresh this cell multiple time \n", "# to see updates on the reconstruction\n", "# while the script is running in a separate process\n", "layout = ptypy.utils.plot_client.TEMPLATES[\"jupyter\"]\n", "plotter = ptypy.utils.MPLplotter(pars=layout)\n", "initialised = False\n", "if (pc.status == pc.DATA):\n", " plotter.pr, plotter.ob, runtime = pc.get_data()\n", " plotter.runtime.update(runtime)\n", " if not initialised:\n", " plotter.update_plot_layout()\n", " plotter.plot_all()\n", " plotter.draw()\n", " plotter.plot_fig"]}], "metadata": {"kernelspec": {"display_name": "PtyPy", "language": "python", "name": "ptypy_pycuda"}, "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.15"}}, "nbformat": 4, "nbformat_minor": 5} | ||
{"cells": [{"cell_type": "markdown", "id": "6044e4fe-966e-4008-9545-c33b9727f10d", "metadata": {}, "source": ["# Live visualisation\n", "**Learning how to use the ```PlotClient``` to look at the reconstruction while it is still running.**\n", "\n", "There many use cases where it can be useful to communicate between a remote process running the reconstruction and a local client process that wants to receive live information about the status of the reconstruction. In PtyPy, this is possible via ZMQ socket communication."]}, {"cell_type": "markdown", "id": "196b8869-ac86-48c3-a867-ca92585f9f48", "metadata": {}, "source": ["## Running the reconstruction in Python script\n", "\n", "First, we copy a YAML config file [./config/dls_i08_nanogold_spiral.yaml](./config/dls_i08_nanogold_spiral.yaml) from one of the previous examples making sure that we turn on the interaction server ```p.io.interaction.server``` \n", "\n", "```python\n", "p.io = u.Param()\n", "p.io.home = \"./\"\n", "p.io.rfile = \"recons/%(run)s_%(engine)s_%(iterations)04d.ptyr\"\n", "p.io.autosave = u.Param(active=False)\n", "p.io.autoplot = u.Param(active=False)\n", "p.io.interaction = u.Param(active=True)\n", "p.io.interaction.server = u.Param()\n", "p.io.interaction.server.port = 5580\n", "p.io.interaction.server.address = \"tcp://127.0.0.1\"\n", "```\n", "\n", "sending updates on localhost (127.0.0.1) at port 9001. We then create a Python run script reading from this config file\n", "\n", "```python\n", "with open(\"./ptypy_run_dls_i08_nanogold.py\", \"w\") as f:\n", " f.write(\"\"\"\\\n", "import ptypy\n", "ptypy.load_ptyscan_module(\"hdf5_loader\")\n", "ptypy.load_gpu_engines(\"cupy\") \n", "p = ptypy.utils.param_from_yaml(\"config/dls_i08_nanogold_spiral.yaml\")\n", "P = ptypy.core.Ptycho(p,level=5)\n", "\"\"\")\n", "```\n", "\n", "and execute the run script in a terminal\n", "\n", "```bash\n", "srun -n 4 -c 2 --gpus-per-task=1 --gpu-bin=None python ptypy_run_dls_i08_nanogold.py\n", "\n", "```"]}, {"cell_type": "markdown", "id": "169dd282-8217-4f22-a0c9-1c374e7fd3b8", "metadata": {}, "source": ["---"]}, {"cell_type": "code", "execution_count": null, "id": "b81d242c-deda-4b5d-a577-b55b42e46ac9", "metadata": {"tags": []}, "outputs": [], "source": ["with open(\"./ptypy_run_dls_i08_nanogold.py\", \"w\") as f:\n", " f.write(\"\"\"\\\n", "import ptypy\n", "ptypy.load_ptyscan_module(\"hdf5_loader\")\n", "ptypy.load_gpu_engines(\"cupy\") \n", "p = ptypy.utils.param_from_yaml(\"config/dls_i08_nanogold_spiral.yaml\")\n", "P = ptypy.core.Ptycho(p,level=5)\n", "\"\"\")"]}, {"cell_type": "raw", "id": "75d00b06-5dc5-46da-93a8-5b160285845b", "metadata": {"tags": []}, "source": ["# commands to copy into terminal\n", "cd $HOME/tutorials/notebooks/supplementary_examples\n", "srun -n 4 -c 2 --gpus-per-task=1 --gpu-bin=None python ptypy_run_dls_i08_nanogold.py"]}, {"cell_type": "markdown", "id": "6a288a19-ea65-41f6-9bb3-0337a00dde6a", "metadata": {}, "source": ["## Running the plot client in this notebook\n", "\n", "While the processing script is running in a separate process, we just need to connect our client to the same address and port\n", "\n", "```python\n", "import ptypy\n", "\n", "client = ptypy.utils.Param()\n", "client.port = 5580\n", "client.address = \"tcp://127.0.0.1\"\n", "```\n", "\n", "and start an instance of the ```PlotClient```\n", "\n", "```python\n", "pc = ptypy.utils.PlotClient(client)\n", "pc.start()\n", "```\n", "\n", "and use its ```get_data()``` function to get updates\n", "\n", "```python\n", "plotter.pr, plotter.ob, runtime = pc.get_data()\n", "```\n", "\n", "on probe, object and runtime information. We can also use the ```MPLplotter``` create \n", "a plot that is updated by repeatedly executing a cell with this code\n", "\n", "```python\n", "from IPython import display\n", "plotter = ptypy.utils.MPLplotter()\n", "initialised = False\n", "if (pc.status == pc.DATA):\n", " plotter.pr, plotter.ob, runtime = pc.get_data()\n", " plotter.runtime.update(runtime)\n", " if not initialised:\n", " plotter.update_plot_layout()\n", " plotter.plot_all()\n", " plotter.draw()\n", " display.clear_output(wait=True)\n", " display.display(plotter.plot_fig)\n", "```"]}, {"cell_type": "markdown", "id": "deaa9e0c-8af9-4af8-b318-5f29f3c289a4", "metadata": {}, "source": ["---"]}, {"cell_type": "code", "execution_count": null, "id": "ca168d91-e5b8-4d41-8b5d-1c37035f906a", "metadata": {"tags": []}, "outputs": [], "source": ["import ptypy\n", "\n", "# Client parameters\n", "client = ptypy.utils.Param()\n", "client.port = 5580\n", "client.address = \"tcp://127.0.0.1\"\n", "\n", "# Create instance of plotclient\n", "pc = ptypy.utils.PlotClient(client)\n", "\n", "# start listening\n", "pc.start()"]}, {"cell_type": "code", "execution_count": null, "id": "06fe8608-449e-4b66-a512-0f339ea7afe8", "metadata": {"tags": []}, "outputs": [], "source": ["# Refresh this cell multiple time \n", "# to see updates on the reconstruction\n", "# while the script is running in a separate process\n", "layout = ptypy.utils.plot_client.TEMPLATES[\"jupyter\"]\n", "plotter = ptypy.utils.MPLplotter(pars=layout)\n", "initialised = False\n", "if (pc.status == pc.DATA):\n", " plotter.pr, plotter.ob, runtime = pc.get_data()\n", " plotter.runtime.update(runtime)\n", " if not initialised:\n", " plotter.update_plot_layout()\n", " plotter.plot_all()\n", " plotter.draw()\n", " plotter.plot_fig"]}], "metadata": {"kernelspec": {"display_name": "PtyPy (cupy)", "language": "python", "name": "ptypy_cupy"}, "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.11.8"}}, "nbformat": 4, "nbformat_minor": 5} |
Oops, something went wrong.