Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.12'
- '1.11'
- 'lts'
os:
Expand Down
55 changes: 55 additions & 0 deletions LINUX.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# SciBmad Linux Installation

1. **Install JupyterLab**

We recommend using SciBmad through [Jupyter lab](https://jupyterlab.readthedocs.io/en/latest/), which is a widely-used computational notebook authoring and editing environment. If you don't have it set up already, installation instructions can be found [here](https://jupyterlab.readthedocs.io/en/stable/getting_started/installation.html).

After installing Jupyter lab, make sure you can open it in your browser. This may be done in the terminal with the command `jupyter lab`.

2. **Install Julia**

While SciBmad can be used from either Python or Julia, Julia must be installed because SciBmad is written in Julia. To install and configure the long-term support (LTS) version of Julia on your computer, in a terminal run the following command:

```
curl -fsSL https://install.julialang.org | sh -s -- --default-channel lts
```


3. **Language-Specific Installation**

Depending on whether you plan to use SciBmad in Python or Julia, follow your language-specific setup instructions below.

## Python

In Python, SciBmad is currently called through the [`juliacall` package](https://juliapy.github.io/PythonCall.jl/stable/juliacall/). We'll first install this package, and modify some of its configuration files to ensure the long-term support (LTS) version of Julia is used:

```
pip install juliacall
find "$HOME" -type f -path "*/juliacall/juliapkg.json" -exec sed -i -E 's/^\s*"julia":.*$/ "julia": "~1.10.3",/' {} +
```

Finally, we'll install SciBmad using the following command:

```
python -c 'from juliacall import Main as jl; jl.seval("import Pkg;"); jl.Pkg.add("SciBmad")'
```

This may take several minutes to install. After it's complete, you're ready to go! Download the [python.ipynb](https://github.com/bmad-sim/SciBmad.jl/blob/main/examples/python.ipynb) SciBmad Jupyter notebook as a simple first example to run.

### Julia

In a terminal, run the command to install the Julia Jupyter kernel:

```
julia -e 'import Pkg; Pkg.add("IJulia");'
```

To customize your Julia Jupyter kernel install, see the [IJulia documentation](https://julialang.github.io/IJulia.jl/stable/manual/installation/).

Finally, SciBmad can be installed with:

```
julia -e 'import Pkg; Pkg.add("SciBmad");'
```

This may take several minutes to install. After it's complete, you're ready to go! Download the [julia.ipynb](https://github.com/bmad-sim/SciBmad.jl/blob/main/examples/julia.ipynb) SciBmad Jupyter notebook as a simple first example to run.
55 changes: 55 additions & 0 deletions MAC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# SciBmad Linux Installation

1. **Install JupyterLab**

We recommend using SciBmad through [Jupyter lab](https://jupyterlab.readthedocs.io/en/latest/), which is a widely-used computational notebook authoring and editing environment. If you don't have it set up already, installation instructions can be found [here](https://jupyterlab.readthedocs.io/en/stable/getting_started/installation.html).

After installing Jupyter lab, make sure you can open it in your browser. This may be done in the terminal with the command `jupyter lab`.

2. **Install Julia**

While SciBmad can be used from either Python or Julia, Julia must be installed because SciBmad is written in Julia. To install and configure the long-term support (LTS) version of Julia on your computer, in a terminal run the following command:

```
curl -fsSL https://install.julialang.org | sh -s -- --default-channel lts
```


3. **Language-Specific Installation**

Depending on whether you plan to use SciBmad in Python or Julia, follow your language-specific setup instructions below.

## Python

In Python, SciBmad is currently called through the [`juliacall` package](https://juliapy.github.io/PythonCall.jl/stable/juliacall/). We'll first install this package, and modify some of its configuration files to ensure the long-term support (LTS) version of Julia is used:

```
pip install juliacall
find "$HOME" -type f -path "*/juliacall/juliapkg.json" -exec sed -i '' -E 's/^[[:space:]]*"julia":.*$/ "julia": "~1.10.3",/' {} +
```

Finally, we'll install SciBmad using the following command:

```
python -c 'from juliacall import Main as jl; jl.seval("import Pkg;"); jl.Pkg.add("SciBmad")'
```

This may take several minutes to install. After it's complete, you're ready to go! Download the [python.ipynb](https://github.com/bmad-sim/SciBmad.jl/blob/main/examples/python.ipynb) SciBmad Jupyter notebook as a simple first example to run.

### Julia

In a terminal, run the command to install the Julia Jupyter kernel:

```
julia -e 'import Pkg; Pkg.add("IJulia");'
```

To customize your Julia Jupyter kernel install, see the [IJulia documentation](https://julialang.github.io/IJulia.jl/stable/manual/installation/).

Finally, SciBmad can be installed with:

```
julia -e 'import Pkg; Pkg.add("SciBmad");'
```

This may take several minutes to install. After it's complete, you're ready to go! Download the [julia.ipynb](https://github.com/bmad-sim/SciBmad.jl/blob/main/examples/julia.ipynb) SciBmad Jupyter notebook as a simple first example to run.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"

[compat]
AtomicAndPhysicalConstants = "0.8.0"
BeamTracking = "0.3.3"
BeamTracking = "0.3.6"
Beamlines = "0.6.5"
DifferentiationInterface = "0.7.4"
ForwardDiff = "0.10,1"
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
[![Coverage](https://codecov.io/gh/bmad-sim/SciBmad.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/bmad-sim/SciBmad.jl)
!-->

SciBmad is a new open source, high-performance, polymorphic, and forwards-/backwards-/Taylor-differentiable accelerator physics simulation ecosystem, consisting of a set of modular packages:
SciBmad is a new open source, high-performance, CPU/GPU compatible, polymorphic, and forwards-/backwards-/Taylor-differentiable accelerator physics simulation ecosystem, usable within either Python and Julia.

SciBmad consists of a set of modular packages:

- **[`BeamTracking.jl`](https://github.com/bmad-sim/BeamTracking.jl):** Universally polymorphic, differentiable, portable, and parallelized integrators for simulating charged particle beams on the CPU and various GPUs including NVIDIA CUDA, Apple Metal, Intel oneAPI, and AMD ROCm
- **[`GTPSA.jl`](https://github.com/bmad-sim/GTPSA.jl):** Fast high-order (Taylor mode) automatic differentiation using the Generalised Truncated Power Series Algebra (GTPSA) library
- **[`Beamlines.jl`](https://github.com/bmad-sim/Beamlines.jl):** Defines accelerator lattices in a fast, flexible, fully-polymorphic, and differentiable way, providing both eagerly- and lazily-evaluated deferred expressions for interdependent parameters
- **[`NonlinearNormalForm.jl`](https://github.com/bmad-sim/NonlinearNormalForm.jl):** Map-based perturbation theory of differential-algebraic maps, which may include spin and large damping, using Lie algebraic methods
- **[`AtomicAndPhysicalConstants.jl`](https://github.com/bmad-sim/AtomicAndPhysicalConstants.jl):** Library providing physical constants and properties for any atomic or subatomic particle, in units chosen by the user, for use in simulations
- **[`AtomicAndPhysicalConstants.jl`](https://github.com/bmad-sim/AtomicAndPhysicalConstants.jl):** Library providing physical constants and properties for any atomic or subatomic particle for use in simulations

## Installation instructions

SciBmad is compatible with [Windows](https://github.com/bmad-sim/SciBmad.jl/blob/main/WINDOWS.md), [Mac](https://github.com/bmad-sim/SciBmad.jl/blob/main/MAC.md), or [Linux](https://github.com/bmad-sim/SciBmad.jl/blob/main/LINUX). Click on your corresponding system to be linked to detailed installation instructions.

## Examples

Expand Down
57 changes: 57 additions & 0 deletions WINDOWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# SciBmad Windows Installation

1. **Install JupyterLab**

We recommend using SciBmad through [Jupyter lab](https://jupyterlab.readthedocs.io/en/latest/), which is a widely-used computational notebook authoring and editing environment. If you don't have it set up already, installation instructions can be found [here](https://jupyterlab.readthedocs.io/en/stable/getting_started/installation.html).

After installing Jupyter lab, make sure you can open it in your browser.

2. **Install Julia**

While SciBmad can be used from either Python or Julia, Julia must be installed because SciBmad is written in Julia. To install and configure the long-term support (LTS) version of Julia on your computer, in a terminal run the following commands in Powershell:

```
winget install --name Julia --id 9NJNWW8PVKMN -e -s msstore
juliaup add lts
juliaup default lts
```

3. **Language-Specific Installation**

Depending on whether you plan to use SciBmad in Python or Julia, follow your language-specific setup instructions below.

## Python

In Python, SciBmad is currently called through the [`juliacall` package](https://juliapy.github.io/PythonCall.jl/stable/juliacall/). We'll first install this package, and set an environment variable to ensure that the long-term suppport (LTS) version of Julia is used. In a (Anaconda) Powershell:

```
pip install juliacall
setx PYTHON_JULIAPKG_EXE julia
set PYTHON_JULIAPKG_EXE=julia
```

Finally, we'll install SciBmad using the following command:

```
python -c "from juliacall import Main as jl; jl.seval('import Pkg;'); jl.Pkg.add('SciBmad')"
```

This may take several minutes to install. After it's complete, you're ready to go! Download the [`python.ipynb'](https://github.com/bmad-sim/SciBmad.jl/blob/main/examples/python.ipynb) SciBmad Jupyter notebook as a simple first example to run.

### Julia

In a Powershell, run the command to install the Julia Jupyter kernel:

```
julia -e 'import Pkg; Pkg.add("IJulia");'
```

To customize your Julia Jupyter kernel install, see the [IJulia documentation](https://julialang.github.io/IJulia.jl/stable/manual/installation/).

Finally, SciBmad can be installed with:

```
julia -e 'import Pkg; Pkg.add("SciBmad");'
```

This may take several minutes to install. After it's complete, you're ready to go! Download the [julia.ipynb](https://github.com/bmad-sim/SciBmad.jl/blob/main/examples/julia.ipynb) SciBmad Jupyter notebook as a simple first example to run.
177 changes: 130 additions & 47 deletions examples/julia.ipynb

Large diffs are not rendered by default.

473 changes: 229 additions & 244 deletions examples/python.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/SciBmad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ end

const BTBL = Base.get_extension(BeamTracking, :BeamTrackingBeamlinesExt)

export twiss, find_closed_orbit, track!
export twiss, find_closed_orbit, track!, track

function fast_coast_check(bl; use_KA=false, use_explicit_SIMD=false)
# Just check if dpz/dz == 0
Expand Down Expand Up @@ -294,8 +294,8 @@ include("newton.jl")
# Bend too, but that is not implemented yet.
qf = Quadrupole(Kn1=0.36, L=0.5); # Matrix kick, 1 multipole
sf = Sextupole(Kn2=0.1, L=0.2); # Drift kick, 1 multipole
d1 = Drift(L=0.3, Kn3=1e-4, Kn4=1e-5); # Drift kick, 2 multipoles
d2 = Drift(L=0.3, Ksol=1e-6); # Solenoid kick, 1 multipole
d1 = Drift(L=0.3, Kn3=1e-4, Kn4=1e-5); # Drift kick, 2 multipoles
d2 = Drift(L=0.3, Ksol=1e-6); # Solenoid kick, 1 multipole
b = SBend(L=6.0, angle=pi/132); # Bend
qd = Quadrupole(Kn1=-0.36, Ks20=1e-3,L=0.5); # matrix kick, 2 multipoles
sd = Sextupole(Kn2=-0.1, Ksol=1e-6, L=0.2); # solenoid-kick, 2 multipoles
Expand Down
11 changes: 7 additions & 4 deletions src/track.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function track(
v0::Union{AbstractMatrix,AbstractVector},
bl::Beamline;
N_turns=1,
n_turns=1,
save_every_n_turns=1,
)
if v0 isa AbstractVector
length(v0) == 6 || error("Track accepts a N x 6 matrix of N particle coordinates,
Expand All @@ -12,11 +13,13 @@ function track(
N_particles = size(v0, 1)
b0 = Bunch(v0)
BTBL.check_bl_bunch!(bl, b0, false) # Do not notify
res = Array{eltype(v0),3}(undef, N_particles, N_turns+1, 6)
res = similar(v0, N_particles, save_every_n_turns+1, 6)
res[:,1,:] .= b0.coords.v
for i in 1:N_turns
for i in 1:n_turns
track!(b0, bl)
res[:,i+1,:] .= b0.coords.v
if mod(i, save_every_n_turns) == 0
res[:,Int(i/save_every_n_turns)+1,:] .= b0.coords.v
end
end
return res
end
Loading