Metadata-Version: 2.4
Name: pass-sim
Version: 0.6.3
Summary: Particle Accelerator Simulation Studio
Author-email: Mingxuan Chang <changmx@impcas.ac.cn>, Jie Liu <liujie115@impcas.ac.cn>, Lei Wang <wangl@impcas.ac.cn>
Project-URL: Homepage, https://github.com/changmx/PASS
Project-URL: Repository, https://github.com/changmx/PASS
Project-URL: Documentation, https://changmx.github.io/PASS/
Project-URL: Issues, https://github.com/changmx/PASS/issues
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS
Classifier: Topic :: Scientific/Engineering :: Physics
Classifier: Intended Audience :: Science/Research
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=2.3.2
Requires-Dist: matplotlib
Requires-Dist: scipy
Requires-Dist: pandas
Requires-Dist: tfs-pandas
Requires-Dist: cpymad>=1.19.0
Requires-Dist: h5py
Requires-Dist: pydantic>=2.0
Requires-Dist: PySide6>=6.6
Requires-Dist: sdds>=0.4.3
Requires-Dist: turn-by-turn>=1.4
Provides-Extra: cpu
Provides-Extra: dev
Requires-Dist: yapf==0.43.0; extra == "dev"
Provides-Extra: docs
Requires-Dist: sphinx>=7.3; extra == "docs"
Requires-Dist: sphinx-rtd-theme>=2.0; extra == "docs"
Provides-Extra: gpu
Requires-Dist: cuda-bindings>=13.0.1; extra == "gpu"
Requires-Dist: cuda-core>=1.0.0; extra == "gpu"
Requires-Dist: cupy-cuda13x>=14.0.0; extra == "gpu"
Requires-Dist: cuda-cccl[cu13]>=1.0.0; extra == "gpu"
Requires-Dist: nvmath-python[cu13]>=1.0.0; extra == "gpu"
Requires-Dist: nvidia-mathdx>=25.6.0; extra == "gpu"
Dynamic: license-file

# PASS

[English](README.md) | [中文](README-zh.md)

PASS (Particle Accelerator Simulation Studio) is a Python program for six-dimensional particle tracking and beam-dynamics analysis. It supports element-based and Twiss-map transport, injection, RF systems, space charge, wakefields, and beam diagnostics, with CPU and optional NVIDIA GPU execution.

[User manual](https://changmx.github.io/PASS/en/index.html) · [Examples](example) · [Releases](https://github.com/changmx/PASS/releases) · [Issues](https://github.com/changmx/PASS/issues)

## Install

Use Python **3.11 or newer**. The default installation includes CPU computation and the GUI.
The `cpu` extra explicitly selects the same dependencies; the `gpu` extra adds NVIDIA GPU support while retaining CPU and GUI functionality.
All configurations install the GUI dependencies, including Qt. Command-line CPU execution does not load Qt or require a graphical display or CUDA.

### Install from PyPI

**Default installation (CPU + GUI):**

```bash
python -m pip install pass-sim
```

**Explicit CPU installation (also includes the GUI):**

```bash
python -m pip install "pass-sim[cpu]"
```

**GPU installation (CPU + GPU + GUI):**

```bash
python -m pip install "pass-sim[gpu]"
```

`python -m pip install "pass-sim[cpu,gpu]"` is equivalent to the GPU installation.
The former `gui`, `cuda`, and `conversion` extras are no longer provided; use the commands above.

After installation, run `pass-run --version` to display the installed PASS version, or `pass-gui` to launch the interface.

### Install from GitHub

First clone the source and enter the repository:

```bash
git clone https://github.com/changmx/PASS.git
cd PASS
```

Alternatively, open the [GitHub repository](https://github.com/changmx/PASS), select **Code → Download ZIP**, and extract it. Enter the directory containing `pyproject.toml`.
From that directory, select one of the following configurations:

**Default installation (CPU + GUI):**

```bash
python -m pip install --editable .
```

**Explicit CPU installation (also includes the GUI):**

```bash
python -m pip install --editable ".[cpu]"
```

**GPU installation (CPU + GPU + GUI):**

```bash
python -m pip install --editable ".[gpu]"
```

`python -m pip install --editable ".[cpu,gpu]"` is equivalent to the GPU installation.
An editable installation uses the code in this source directory directly; Python source edits take effect in subsequent runs.
After installation, use `pass-run --version` to display the installed PASS version, or `pass-gui` to launch the interface.

Both installation methods also support `python -m PASS --version`. Run `pass-run --help` or `pass-run -h` to see input modes, options, path rules, and examples.

### GPU requirements and backend selection

Installing GPU dependencies does not select the simulation backend. Choose `cpu` or `gpu` using `backend (gpu/cpu)` in the input configuration.
GPU execution requires a compatible NVIDIA GPU, driver, and CUDA environment; the current GPU dependencies target CUDA 13.x.
The GPU extra does not install an NVIDIA driver or guarantee a complete CUDA Toolkit installation.
On a supported platform, GPU packages may install without a GPU, but installation success does not establish GPU availability.
CPU computation and the GUI can still be used without CUDA. Explicit GPU execution fails with a diagnostic if CuPy, device discovery, or device initialization is unavailable; PASS does not silently fall back to CPU.
CUDA library or kernel-compilation errors can also occur later when a particular GPU feature is first used.

## Run a simulation

### Example project

The examples below assume that `/home/myprojpath` contains a valid PASS input `beam0.json` and this project description:

```text
/home/myprojpath/
├── myproject.passproj
├── beam0.json
├── quadrupole_ramp.tfs    # optional: include it if beam0.json references it
└── output/               # created when a simulation runs
```

`myproject.passproj` is an ordinary JSON text file. For a single-beam project, its contents can be:

```json
{
  "format": "pass-project",
  "format_version": 3,
  "name": "My simulation",
  "configs": ["beam0.json"],
  "active_config": "beam0.json",
  "run": {
    "beam0": "beam0.json",
    "beam1": null,
    "output_directory": "output"
  }
}
```

Project-description paths are relative to `/home/myprojpath`. File references inside `beam0.json` are relative to that JSON's directory; for example, `"Ramping file": "quadrupole_ramp.tfs"` refers to `/home/myprojpath/quadrupole_ramp.tfs`. There is no required `configs/` directory. Replace `/home/myprojpath` with your actual project path.

### Command-line execution

There are **three input modes**: one JSON for a single beam, two JSON files for two beams, and a project selecting its saved beam inputs. A project can be specified by its `.passproj` file or by its directory. Command-line execution does not require the GUI or Qt.

With the example directory above, each of the following commands can be run from **any working directory**:

```bash
# Run beam0.json directly, using the settings in that JSON.
pass-run /home/myprojpath/beam0.json

# Run the beam selection and output settings saved in myproject.passproj.
pass-run /home/myprojpath/myproject.passproj

# Open the project description in this directory, then run its saved selection.
pass-run /home/myprojpath
```

For a directory argument, PASS first uses `project.passproj` if it exists. Otherwise, it uses the only `.passproj` file directly in that directory, so the example above selects `myproject.passproj`. If there are several `.passproj` files and no `project.passproj`, specify the intended project file explicitly. PASS does not search subdirectories.

After entering the project directory, the equivalent relative-path commands are:

```bash
cd /home/myprojpath
pass-run beam0.json
pass-run myproject.passproj
pass-run .
```

These are alternative commands; choose one to launch a run. Projects use `run.beam0` and optional `run.beam1`, falling back to `active_config` when Beam 0 is unset. They do not run every configuration in `configs`. Tracking validates and archives the selected inputs and their dependencies before execution.

Named input options provide another spelling of the same commands:

```bash
pass-run --beam0 /home/myprojpath/beam0.json
pass-run --passproj /home/myprojpath/myproject.passproj
pass-run --passproj /home/myprojpath
```

For **two-beam execution**, first provide a second valid input `/home/myprojpath/beam1.json`. Then use either of these equivalent commands:

```bash
pass-run /home/myprojpath/beam0.json /home/myprojpath/beam1.json
pass-run --beam0 /home/myprojpath/beam0.json --beam1 /home/myprojpath/beam1.json
```

To run both through the project instead, add `"beam1.json"` to its `configs` list and set `run.beam1` to `"beam1.json"`, then run `pass-run /home/myprojpath/myproject.passproj`. A project supplies its own beam selection and cannot be combined with a second input argument. Choose positional arguments or named input options for each command; do not mix them. `--beam1` requires `--beam0`, and `--passproj` cannot be combined with either beam option.

`pass-run` and `python -m PASS` are **two launchers for the same execution logic**, with the same arguments. Use the module form to select a particular Python environment:

```bash
python -m PASS /home/myprojpath/beam0.json
python -m PASS /home/myprojpath/myproject.passproj
python -m PASS /home/myprojpath
```

Relative command-line paths use the terminal's working directory. Quote paths containing spaces. Run `pass-run --help` or `python -m PASS --help` for all options.

### Override JSON parameters for one run

```bash
pass-run beam0.json --backend=gpu --device-id=1 --task-name=test
pass-run beam0.json --number-of-turns=100 --timing.log-interval=20
pass-run beam0.json '--sequence[QF1_s1.000].length=0.5'
```

Use JSON key names with spaces replaced by hyphens and parentheses (including units) removed. Values retain the JSON units and types. Dots separate nested fields; `[exact name]` preserves element names containing dots. A single device ID may be an integer (`--device-id=1`) or an array (`--device-id="[1]"`); execution snapshots always store an array. Unqualified overrides target Beam 0; use `--beam1.<path>` for Beam 1. Shared simulation settings must still agree between beams. Task names and output directories apply to the whole run; `--output-directory` is equivalent to `--output`.

Overrides are validated before execution and saved in the execution input snapshots; source files remain unchanged. Command-line file paths are relative to the caller's working directory. Duplicate or overlapping overrides, unknown fields and invalid values are rejected. For exact paths, objects, arrays and supported scope, see the [command-line input guide](https://changmx.github.io/PASS/en/input_generation.html).

The RF injection key is now `RF S Position Refer to Injection Point (m)`; older inputs using the abbreviated spelling must be regenerated or renamed.

### Outputs and editing

For the project description above, results go under `/home/myprojpath/output/<YYYY_MM_DD_HH_MM>/` by default, regardless of the directory from which you launch it. Running `beam0.json` directly uses its own `Output directory` setting; if it is omitted or set to `default` (case-insensitive), the output root is also `/home/myprojpath/output`.

| Launch mode | Output root | Default results beneath that root |
| --- | --- | --- |
| JSON through `pass-run`, `python -m PASS`, or the Python API | The first JSON's `Output directory`, relative to that JSON's directory; if omitted or set to `default` (case-insensitive), use `output` beside that JSON | `<YYYY_MM_DD_HH_MM>/` |
| Project file or directory through the command line | The project's `run.output_directory`, or `output` if unset; relative paths are resolved beside the project description | `<YYYY_MM_DD_HH_MM>/` |
| GUI | The **Run** page's **Output root directory**, initially `output`; relative paths use the JSON/project directory (the working directory for an unsaved project) | `<YYYY_MM_DD_HH_MM>/` |

`--output DIR` overrides the output root for any input mode, only for that run. An absolute path works from any working directory:

```bash
pass-run /home/myprojpath/myproject.passproj --output /home/myprojpath/results
```

The result root is `/home/myprojpath/results`. A relative override uses the terminal's working directory, as this example makes explicit:

```bash
cd /home/myprojpath
pass-run myproject.passproj --output "results/test run"
```

This writes beneath `/home/myprojpath/results/test run/<YYYY_MM_DD_HH_MM>/` when no custom output name is set. `--output` takes precedence over the JSON/project settings without changing their files. `python -m PASS` supports the same option.

To use a task name for the run folder instead of an automatic timestamp, set `"Task name": "capture_sc"` in Beam 0's JSON (`MainConfig(task_name="capture_sc")`), set the project's `run.task_name`, or edit **Task name** on **Run**. This field initially displays the actual value `default`; saved custom names are preserved. `Output directory` / `output_dir` continues to select the parent output root. The command-line override is:

```bash
pass-run myproject.passproj --output results --task-name capture_sc
```

Results then go into `results/capture_sc/`, preserving internal subdirectories and the existing `HHMM_SS` time labels in result filenames. Omitted, null, blank or `default` task names use a single folder at minute precision, for example `output/2026_10_30_18_39/`. Both automatic and custom names use unpadded collision suffixes `_1`, `_2`, `_3`, and so on, such as `2026_10_30_18_39_1` or `capture_sc_1`; `default` is case-insensitive after trimming whitespace, so `" DEFAULT "` has the same effect. There is no automatic Beam 0 filename default. `run.task_name`, when present, overrides the Beam 0 field; `--task-name` overrides both. Use a single folder name, not a path. The Python API accepts `main(..., task_name="capture_sc")`; an explicit empty or `default` override restores the single-level timestamp layout even when the saved name is custom, for example `--task-name default` or `main(..., task_name="default")`.

Each normal run saves an input snapshot in its result directory's `input/` subdirectory. It contains original configuration values, execution JSON, copied dependencies, and the `run.json` record. JSON, project, and GUI runs share these layout rules. Existing result trees are unchanged; rerunning old inputs or snapshots creates a fresh directory using the new single-level layout. See the [input guide](https://changmx.github.io/PASS/en/input_generation.html) and [project guide](https://changmx.github.io/PASS/en/project_files.html) for details.

Edit `myproject.passproj`, `beam0.json`, and text dependencies with a text editor. In the GUI, use **File → Reload project** after external edits and before saving or running; external-change checks protect against overwriting or running stale inputs. Move or share the directory with all referenced files, because the `.passproj` description alone is not a complete project. **Export runnable input bundle** can package the selected inputs and dependencies for sharing.

### Automatic plotting

Set `"Is plot figure": true` in the beam input to generate figures after successful tracking. Each StatMonitor history produces a nine-panel figure, each distribution snapshot a six-panel figure, and each ParticleMonitor file a twelve-panel figure using all recorded particles and valid samples. Figures are saved in the run's `plot/` directory.

You can also plot an existing result directory without repeating the simulation:

```bash
python -m PASS.plot output/2026_10_30_18_39
python -m PASS.plot output/2026_10_30_18_39 --format png pdf
```

The default is 300 dpi PNG. Repeated plotting preserves existing figures by choosing unused filenames. See [automatic plotting](https://changmx.github.io/PASS/en/monitor/plotting.html) for layouts, units, options, and the plotting manifest.

### Graphical interface

Install the `gui` extra, then launch with either `pass-gui` or `python -m PASS.gui`. For the example above, select **File → Open project** and choose `/home/myprojpath/myproject.passproj`, or **File → Open project folder** and choose `/home/myprojpath`. To work with just the beam input, use **File → Open JSON** and choose `/home/myprojpath/beam0.json`.

Apply parameter changes, select **Validate**, and start the simulation from **Run**. Use **Plot** to inspect results. See the [GUI workflow](https://changmx.github.io/PASS/en/gui.html) and [project guide](https://changmx.github.io/PASS/en/project_files.html).

### Python workflow

The [input guide](https://changmx.github.io/PASS/en/input_generation.html) covers input generation, validation, execution, and output. Example scripts are provided in the source repository. If you installed from PyPI, first download or clone the repository to obtain the examples. Then run the distribution example from the repository root:

```bash
cd example/01_generate_distribution
python generate_input.py --case longi-gaussian
pass-run --beam0 beam0_longi_gaussian.json
python analyze_results.py --case longi-gaussian
```

The generator writes the case input; `pass-run` saves results under the example's `output/` directory; the analyzer uses the latest run for that case. The distribution and RF examples also provide `run_simulation.py --case all` helpers for running their predefined cases serially through the same CLI. See the [example README](example/01_generate_distribution/README.md) for parameters, other cases, and output files.

An existing input can also be checked before execution:

```bash
python -m PASS.validation /home/myprojpath/beam0.json --report /home/myprojpath/validation-report.json
```

## Reference

- [Coordinates and injection](https://changmx.github.io/PASS/en/injection.html)
- [Elements](https://changmx.github.io/PASS/en/element/index.html) and [Twiss maps](https://changmx.github.io/PASS/en/twiss.html)
- [Space charge](https://changmx.github.io/PASS/en/space_charge.html), [wakefields](https://changmx.github.io/PASS/en/wake_field.html) and [electron clouds: frozen kicks and prescribed-beam build-up](https://changmx.github.io/PASS/en/electron_cloud.html)
- [Intrabeam scattering](https://changmx.github.io/PASS/en/ibs.html): Gaussian growth rates, kinetic kicks and local binary collisions on CPU/GPU
- [Monitors and output formats](https://changmx.github.io/PASS/en/monitor/index.html)
- [Spectral analysis and FMA](https://changmx.github.io/PASS/en/spectral_analysis.html): standalone NumPy functions and the GUI **Analysis** workspace; CSV/TSV/TXT/DAT, TFS, HDF5, NPY and NPZ inputs.

WakeField file models accept canonical wake TFS only. Convert CSV/TXT/HEADTAIL data with `python -m PASS.tool.wake_conversion` or **Import wake…** in the GUI conversion tool; the [wakefield guide](https://changmx.github.io/PASS/en/wake_field.html#wake-tfs-en) explains units, physical conventions and examples.

With the `docs` extra installed, run this command from the repository root to build both languages:

```bash
python -m sphinx -b html -W --keep-going docs/source docs/build/html
```

Open `docs/build/html/index.html` after a successful build.

## Contributing

Follow [AGENTS.md](AGENTS.md) for physics, documentation, and formatting conventions. Install `.[dev]` and use YAPF 0.43.0 with `pyproject.toml`; embedded CUDA is checked with `python PASS/tool/format_cuda.py --check` from the source checkout. The `tests/` directory is maintained locally and excluded from Git, so a fresh clone does not contain the test suite.

PASS is distributed under the [Apache License 2.0](LICENSE).
