JAX-in-Cell: Particle-in-Cell code in JAX
Project description
❯ jaxincell: 1D particle-in-cell code in JAX to perform simulation of plasmas
Table of Contents
- Overview
- Features
- Project Structure
- Getting Started
- Project Roadmap
- Contributing
- License
- Acknowledgments
Overview
JAX-in-Cell is an open-source project in Python that uses JAX to speedup simulations, leading to a simple to use, fast and concise code. It can be imported in a Python script using the jaxincell package, or run directly in the command line as jaxincell. To install it, use
pip install jaxincell
Alternatively, you can install the Python dependencies jax, jax_tqdm and matplotlib, and run the example script in the repository after downloading it as
git clone https://github.com/uwplasma/JAX-in-Cell
python example_script.py
This allows JAX-in-Cell to be run without any installation.
The project can be downloaded in its GitHub repository
Features
JAX-in-Cell can run in CPUs, GPUs and TPUs, has autodifferentiation and just-in-time compilation capabilities, is based on rigorous testing, uses CI/CD via GitHub actions and has detailed documentation.
Currently, it evolves particles using the non-relativisic Lorentz force $\mathbf F = q (\mathbf E + \mathbf v \times \mathbf B)$, and evolves the electric $\mathbf E$ and magnetic $\mathbf B$ field using Maxwell's equations.
Plenty of examples are provided in the examples folder, and the documentation can be found in Read the Docs.
Project Structure
└── JAX-in-Cell/
├── LICENSE
├── docs
├── examples
│ ├── Landau_damping.py
│ ├── Langmuir_wave.py
│ ├── ion-acoustic_wave.py
│ ├── two-stream_instability.py
│ ├── auto-differentiability.py
│ ├── scaling_energy_time.py
│ └── optimize_two_stream_saturation.py
├── jaxincell
│ ├── boundary_conditions.py
│ ├── constants.py
│ ├── diagnostics.py
│ ├── fields.py
│ ├── particles.py
│ ├── plot.py
│ ├── simulation.py
│ └── sources.py
├── main.py
└── tests
└── test_simulation.py
Getting Started
Prerequisites
- Programming Language: Python
Besides Python, JAX-in-Cell has minimum requirements. These are stated in requirements.txt, and consist of the Python libraries jax, jax_tqdm and matplotlib. These can be installed using
pip install jax jax_tqdm matplotlib
Installation
Install JAX-in-Cell using one of the following methods:
Using PyPi:
- Install JAX-in-Cell from anywhere in the terminal:
pip install jaxincell
Build from source:
- Clone the JAX-in-Cell repository:
git clone https://github.com/uwplasma/JAX-in-Cell
- Navigate to the project directory:
cd JAX-in-Cell
- Install the project dependencies:
pip install -r /path/to/requirements.txt
- Install JAX-in-Cell:
pip install -e .
Usage
To run a simple case of JAX-in-Cell, you can simply call jaxincell from the terminal
jaxincell
This runs JAX-in-Cell using standard input parameters of Landau damping. To change input parameters, use a TOML file similar to the example input present in the repository as
jaxincell example_input.toml
Additionally, it can be run inside a script, as shown in the example script file
python example_script.py
There, you can find most of the input parameters needed to run many test cases, as well as resolution parameters.
The jaxincell package has a single function simulation() that takes as arguments a dictionary input_parameters, the number of grid points, number of pseudoelectrons, total number of time steps, and the field solver to use.
In the example script file we write as inline comments the meaning of each input parameter.
Testing
Run the test suite using the following command:
pytest .
Project Roadmap
-
Task 1: Run PIC simulation using several field solvers. -
Task 2: Finalize example scripts and their documentation. -
Task 3: Implement a relativistic equation of motion. -
Task 4: Implement collisions to allow the plasma to relax to a Maxwellian. -
Task 5: Implement guiding-center equations of motion. -
Task 6: Implement an implicit time-stepping algorithm.
Contributing
- 💬 Join the Discussions: Share your insights, provide feedback, or ask questions.
- 🐛 Report Issues: Submit bugs found or log feature requests for the
JAX-in-Cellproject. - 💡 Submit Pull Requests: Review open PRs, and submit your own PRs.
Contributing Guidelines
- Fork the Repository: Start by forking the project repository to your github account.
- Clone Locally: Clone the forked repository to your local machine using a git client.
git clone https://github.com/uwplasma/JAX-in-Cell
- Create a New Branch: Always work on a new branch, giving it a descriptive name.
git checkout -b new-feature-x
- Make Your Changes: Develop and test your changes locally.
- Commit Your Changes: Commit with a clear message describing your updates.
git commit -m 'Implemented new feature x.'
- Push to github: Push the changes to your forked repository.
git push origin new-feature-x
- Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.
- Review: Once your PR is reviewed and approved, it will be merged into the main branch. Congratulations on your contribution!
License
This project is protected under the MIT License. For more details, refer to the LICENSE file.
Acknowledgments
- This code was inspired by a previous implementation of a PIC code in JAX by Sean Lim here.
- We acknowledge the help of the whole UWPlasma plasma group.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jaxincell-0.0.3.tar.gz.
File metadata
- Download URL: jaxincell-0.0.3.tar.gz
- Upload date:
- Size: 79.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1feadde58c30cec2281b16a630e2f0df3e0342a3c12abdc367b64816cc083ea3
|
|
| MD5 |
ec4c07f542056b88c356be8389ac7829
|
|
| BLAKE2b-256 |
ee5c7c40b8f6351bc08e0e50b7b38390304d034d2194048b6fc1ebe866250e19
|
Provenance
The following attestation bundles were made for jaxincell-0.0.3.tar.gz:
Publisher:
pypi_publish.yml on uwplasma/JAX-in-Cell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jaxincell-0.0.3.tar.gz -
Subject digest:
1feadde58c30cec2281b16a630e2f0df3e0342a3c12abdc367b64816cc083ea3 - Sigstore transparency entry: 171565726
- Sigstore integration time:
-
Permalink:
uwplasma/JAX-in-Cell@244b1265212c1829352d13252c0457101b3b77e2 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/uwplasma
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_publish.yml@244b1265212c1829352d13252c0457101b3b77e2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file jaxincell-0.0.3-py3-none-any.whl.
File metadata
- Download URL: jaxincell-0.0.3-py3-none-any.whl
- Upload date:
- Size: 23.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b261bb620c3174fb797d99f8d09b1e7e406506e3c77867362b75faead43c00a4
|
|
| MD5 |
9094a6be5858db8fe9387f2f6c408d97
|
|
| BLAKE2b-256 |
82dce3db3a5a26688afaf4789cdbb48ae95cc4402048bb79c2be74e9146dde40
|
Provenance
The following attestation bundles were made for jaxincell-0.0.3-py3-none-any.whl:
Publisher:
pypi_publish.yml on uwplasma/JAX-in-Cell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jaxincell-0.0.3-py3-none-any.whl -
Subject digest:
b261bb620c3174fb797d99f8d09b1e7e406506e3c77867362b75faead43c00a4 - Sigstore transparency entry: 171565727
- Sigstore integration time:
-
Permalink:
uwplasma/JAX-in-Cell@244b1265212c1829352d13252c0457101b3b77e2 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/uwplasma
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_publish.yml@244b1265212c1829352d13252c0457101b3b77e2 -
Trigger Event:
release
-
Statement type: