pyscibmad 0.9.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.5
2
+ Name: pyscibmad
3
+ Version: 0.9.0
4
+ Summary: SciBmad from Python: charged particle beam dynamics (Twiss, tracking, normal forms, optimization) on CPUs and GPUs
5
+ Project-URL: Homepage, https://github.com/bmad-sim/SciBmad/tree/main/python
6
+ Project-URL: Documentation, https://bmad-sim.github.io/SciBmad
7
+ Project-URL: Repository, https://github.com/bmad-sim/SciBmad
8
+ Project-URL: Issues, https://github.com/bmad-sim/SciBmad/issues
9
+ Author: The SciBmad developers
10
+ License: GPL-3.0-or-later
11
+ License-File: LICENSE
12
+ Keywords: accelerator,beam dynamics,bmad,physics,scibmad,tracking,twiss
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Topic :: Scientific/Engineering :: Physics
19
+ Requires-Python: >=3.10
20
+ Requires-Dist: backports-zstd>=1.0; python_version < '3.14'
21
+ Requires-Dist: juliacall>=0.9.24
22
+ Requires-Dist: numpy>=1.21
23
+ Provides-Extra: plot
24
+ Requires-Dist: matplotlib; extra == 'plot'
25
+ Provides-Extra: test
26
+ Requires-Dist: matplotlib; extra == 'test'
27
+ Requires-Dist: pytest>=7; extra == 'test'
28
+ Requires-Dist: scipy; extra == 'test'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # PySciBmad
32
+
33
+ SciBmad for Python: simulation of charged particle beams in accelerators, with optics, tracking
34
+ on CPUs and GPUs, and optimization with exact derivatives. The package is installed as
35
+ `pyscibmad` and imported as `scibmad`. SciBmad is written in Julia, and `scibmad` runs it for you:
36
+ the results are Python objects (NumPy arrays where they are numbers).
37
+
38
+ ```python
39
+ import numpy as np
40
+ import matplotlib.pyplot as plt
41
+ import scibmad as sb
42
+
43
+ with sb.elements(): # names the elements after their variables
44
+ qf = sb.Quadrupole(Kn1=0.36, L=0.5)
45
+ d = sb.Drift(L=1.0)
46
+ qd = sb.Quadrupole(Kn1=-0.36, L=0.5)
47
+ fodo = sb.Beamline([qf, d, qd, d], species_ref=sb.Species("electron"), pc_ref=18e9)
48
+
49
+ tw = sb.twiss(fodo)
50
+ tw.q1, tw.beta1[qd] # a summary value, a column at an element
51
+ plt.plot(tw.s, tw.beta1)
52
+
53
+ te = sb.lazy_twiss(fodo) # match the tunes, with exact derivatives
54
+ sb.optimize(vary=[sb.Knob(qf, "Kn1"), sb.Knob(qd, "Kn1")],
55
+ targets=[te.q1 == 0.2, te.q2 == 0.2])
56
+
57
+ res = sb.track(fodo, v0=np.random.rand(1000, 6) * 1e-4, n_turns=100)
58
+ res.x(turn=100) # x of every particle after turn 100
59
+ ```
60
+
61
+ The [SciBmad documentation](https://bmad-sim.github.io/SciBmad/python/) describes all of it,
62
+ with every example in Python. How this package relates to the Julia package is described for
63
+ developers on the page
64
+ [For Developers](https://bmad-sim.github.io/SciBmad/developers.html#developers-python).
65
+
66
+ ## Installation
67
+
68
+ Install it with conda or with pip, not both (they install the same package):
69
+
70
+ ```bash
71
+ conda install -c scibmad-forge -c conda-forge pyscibmad # with conda (recommended), or
72
+ pip install pyscibmad # with pip
73
+ ```
74
+
75
+ There is nothing else to install: Julia runs inside the Python process. Which Julia runs SciBmad
76
+ is decided at `import scibmad`, in this order:
77
+
78
+ 1. `sb.init(julia=..., project=..., threads=...)` before the first use of SciBmad;
79
+ 2. the environment variables `SCIBMAD_JULIA` (a Julia executable) and `SCIBMAD_PROJECT` (a
80
+ Julia project with SciBmad and PythonCall), and `SCIBMAD_THREADS`;
81
+ 3. the configuration of the user, set with `python -m scibmad config --julia ... --project ...`
82
+ (`--reset` goes back to the default; `python -m scibmad info` shows what runs);
83
+ 4. juliacall's own `PYTHON_JULIACALL_EXE` and `PYTHON_JULIACALL_PROJECT`, if set;
84
+ 5. the SciBmad distribution of the current conda environment (`conda install -c scibmad-forge
85
+ scibmad`, a Julia with SciBmad and the packages it uses precompiled);
86
+ 6. otherwise the same distribution, downloaded from the GitHub release of this SciBmad version
87
+ on first use (up to about 1 GB, once per user) into `~/.local/share/scibmad-dist` (Windows:
88
+ `%LOCALAPPDATA%\scibmad-dist`; `python -m scibmad config --distributions DIR` to change it,
89
+ `--download no` or `SCIBMAD_DOWNLOAD=no` to turn it off);
90
+ 7. where there is no distribution for the platform, or downloads are off,
91
+ [juliapkg](https://github.com/JuliaPy/pyjuliapkg) installs Julia and the SciBmad.jl version
92
+ of this release (`src/scibmad/juliapkg.json`) into the Python environment, once (it compiles
93
+ SciBmad: this takes long and needs a lot of memory).
94
+
95
+ Each release of `pyscibmad` is made for one release of SciBmad.jl (`scibmad.SCIBMAD_VERSION`):
96
+ updating the Python package updates SciBmad with it (`pip install -U pyscibmad`, `conda update
97
+ pyscibmad`). Other Julia installations are checked against the supported SciBmad versions (a
98
+ warning if outside).
99
+
100
+ GPUs: `sb.device("cuda")` (or `"metal"`, `"amdgpu"`, `"oneapi"`) installs the Julia package of
101
+ that GPU the first time (also `python -m scibmad gpu cuda`) and gives `asarray`, which copies
102
+ NumPy arrays to it.
103
+
104
+ ## How it works
105
+
106
+ The package is a thin, generic layer on [juliacall](https://github.com/JuliaPy/PythonCall.jl):
107
+ nothing in it lists SciBmad's API, so new functionality of SciBmad.jl is available in Python as
108
+ soon as SciBmad has it.
109
+
110
+ - `src/scibmad/_runtime.py`: which Julia runs SciBmad, and starting it. For the SciBmad
111
+ distribution and for a given Julia project, the `juliacall` Python package that comes with
112
+ their PythonCall is used, so that the two versions always match (juliacall requires it).
113
+ Julia's signal handlers are on (Julia's garbage collector needs them as soon as it has more
114
+ than one thread, e.g. those of GPU packages), with Python's own handler for Ctrl-C.
115
+ - `src/scibmad/_core.py`: the proxies of Julia values (attributes, indexing, calls, operators,
116
+ display, NumPy and Matplotlib) and the conversions between Python and Julia values.
117
+ - `src/scibmad/_glue.jl`: the Julia side (a module `PySciBmad` in `Main`): categories of values,
118
+ indexing rules, calls with strings for Symbols, display for Python, errors.
119
+ - `src/scibmad/_extras.py`: what Python writes differently: `elements`, `withvalues`,
120
+ `DefExpr` (traced into Julia expressions), `julia` (the Julia session: modules, packages,
121
+ `include` of Julia lattice files).
122
+ - `src/scibmad/_gpu.py`: `device`.
123
+ - `src/scibmad/__init__.py`: the names of SciBmad as attributes of the module (`f!` is `f_`;
124
+ `optimize`, `undo`, `setknobs`, `phase_trombone`, `scalarize` also without the underscore).
125
+
126
+ ## Development
127
+
128
+ From this directory, with a Julia environment that develops `julia/` of this checkout (and the
129
+ other SciBmad packages, if you change them too):
130
+
131
+ ```bash
132
+ julia --project=myenv -e 'using Pkg; Pkg.develop(path="../julia"); Pkg.add("PythonCall")'
133
+ pip install -e ".[test]"
134
+ SCIBMAD_JULIA=$(which julia) SCIBMAD_PROJECT=myenv pytest
135
+ ```
136
+
137
+ The tests compare each feature with the same computation done in Julia
138
+ (`.github/workflows/Python.yml` runs them on the checkout). The examples of the SciBmad
139
+ documentation are the larger test: every Python cell of its pages runs (see
140
+ `docs/_ext/dual_language.py`).
141
+
142
+ ## License
143
+
144
+ GPL-3.0-or-later.
@@ -0,0 +1,14 @@
1
+ scibmad/__init__.py,sha256=xl8jwcd98-hyGX3FaXBmTqx195igYbMCqIiRkGFzRBc,5292
2
+ scibmad/__main__.py,sha256=CUwX3kILZxht9oUmisDK6spyDzarc3mI2OkP0fqKb48,2196
3
+ scibmad/_core.py,sha256=4hWZP4clXrxM2GtdEVyCAdXBBxr4URmfeOTdeZWbIME,28769
4
+ scibmad/_extras.py,sha256=C5xrnMledngJD8g0KtfBKSRZNh4jRvFzS0HR_MGLI-w,10147
5
+ scibmad/_gpu.py,sha256=SzTA6fbojkWf8nOZrSRbpj_T1Bb1SWZNz579YJgCWYQ,3498
6
+ scibmad/_runtime.py,sha256=C_5TqCHR1IidzfXdnNauPOKBmkyYPl0rdnengSeggPI,27599
7
+ scibmad/_version.py,sha256=H9NWRZb7NbeRRPLP_V1fARmLNXranorVM-OOY-8_2ug,22
8
+ scibmad/_glue.jl,sha256=jjrrdp_4-fSPpSHJQa0VL6tAhvamAB-OzD1O4BhXRSI,13911
9
+ scibmad/juliapkg.json,sha256=hqY9KuenNh08WYJX2BR8H__EgMGN_0weUCXM26BViEs,173
10
+ pyscibmad-0.9.0.dist-info/METADATA,sha256=XViXwNs4x-kVP_nCZ9h-bty8Z6_P9CzVyMqmK94RQGg,7200
11
+ pyscibmad-0.9.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
12
+ pyscibmad-0.9.0.dist-info/entry_points.txt,sha256=ePwbhocqnyh1gaJxYQ7j6ayEQnUvM8waKLzbyKlDLYk,53
13
+ pyscibmad-0.9.0.dist-info/licenses/LICENSE,sha256=egtwRi6tEBWUFUxfCo0wMQ2Aje0HcwrC0BJhlCeh4X0,33022
14
+ pyscibmad-0.9.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ scibmad-py = scibmad.__main__:main