{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Perfomance" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0.7.56'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import kenv as kv\n", "import numpy as np\n", "import pandas as pd\n", "import glob\n", "\n", "import redpic as rp\n", "\n", "rp.__version__" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def simulation():\n", " acc = rp.accelerator.Accelerator(z_start=0.7, z_stop=1.7, dz=0.01)\n", " acc.add_accel('Acc. 1', 4.096, -1.1, 'Ez.dat')\n", " acc.add_accel('Acc. 2', 5.944, -1.1, 'Ez.dat')\n", " acc.add_solenoid('Sol. 1', 0.450, -0.0580, 'Bz.dat')\n", " acc.add_solenoid('Sol. 2', 0.957, 0.0390, 'Bz.dat')\n", " acc.add_solenoid('Sol. 3', 2.107, 0.0250, 'Bz.dat')\n", " acc.add_solenoid('Sol. 4', 2.907, 0.0440, 'Bz.dat')\n", " acc.add_solenoid('Sol. 5', 3.670, 0.0400, 'Bz.dat')\n", " acc.add_solenoid('Sol. 6', 4.570, 0.0595, 'Bz.dat')\n", " acc.add_solenoid('Sol. 7', 5.470, 0.0590, 'Bz.dat')\n", " acc.compile()\n", " beam = rp.beam.UniformBeam(\n", " type=rp.constants.electron, \n", " energy = 1.32, # MeV\n", " current = 0.5e3, # A\n", " radius_x = 48e-3, # initial r (m)\n", " radius_y = 48e-3, # initial r (m)\n", " radius_z = 3.5,\n", " radius_xp = 2*35.0e-3, # initial r' (rad)\n", " radius_yp = 2*35.0e-3, # initial r' (rad)\n", " x = 0.0e-3, # horizontal centroid position (m)\n", " xp = 0.0e-3, # horizontal centroid angle (rad)\n", " y = 0, # vertical centroid position (m)\n", " normalized_emittance = 200e-6) # m*rad\n", " beam.generate(n=1_000)\n", " beam.df\n", " sim = rp.solver.Simulation(beam, acc)\n", " sim.track()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:48:10,201 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:48:16,199 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.68 m (98.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:48:21,271 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:48:26,363 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:48:31,194 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.64 m (94.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:48:34,907 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:48:40,510 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:48:44,858 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:48:51,429 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:48:59,170 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:49:03,724 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:49:08,643 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:49:15,642 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:49:20,485 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.68 m (98.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:49:24,141 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:49:29,462 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:49:33,707 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:49:37,057 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:49:41,692 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:49:48,170 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:49:51,789 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.68 m (98.0 %) 5.03 s ± 662 ms per loop (mean ± std. dev. of 7 runs, 3 loops each)\n" ] } ], "source": [ "rp.core.config.DISABLE_JIT = True\n", "%timeit -n 3 simulation()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:49:55,743 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.56 m (86.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:49:57,341 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.58 m (88.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:49:58,676 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.62 m (92.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:49:59,940 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.60 m (90.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:50:01,475 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.62 m (92.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:50:02,755 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.60 m (90.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:50:04,061 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.56 m (86.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:50:05,403 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:50:06,766 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.60 m (90.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:50:08,150 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.62 m (92.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:50:09,642 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.60 m (90.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:50:11,920 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:50:13,776 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.58 m (88.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:50:15,395 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.58 m (88.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:50:17,119 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.58 m (88.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:50:18,894 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.58 m (88.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:50:20,707 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.64 m (94.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:50:22,649 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.60 m (90.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:50:24,600 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.56 m (86.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:50:26,249 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.66 m (96.0 %) " ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023-08-31 17:50:27,895 - redpic.beam.uniform - INFO - Generate a uniform beam with 1000 particles\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "z = 1.68 m (98.0 %) 1.61 s ± 217 ms per loop (mean ± std. dev. of 7 runs, 3 loops each)\n" ] } ], "source": [ "rp.core.config.DISABLE_JIT = False\n", "%timeit -n 3 simulation()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz\n" ] } ], "source": [ "! sysctl -n machdep.cpu.brand_string" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.11.0" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }