Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

PyParticles3

PyParticles3 is an independent modernization and continuation of Simone Riva's original PyParticles project.

The goal is to preserve the original project's unusually clear, educational architecture while updating it for modern Python, NumPy, SciPy, PyOpenGL and PyOpenCL environments. PyParticles3 is also a practical study project for GPU particle simulation, OpenCL acceleration and OpenCL/OpenGL interoperability.

PyParticles3 is not presented as an official release endorsed by Simone Riva. Original copyright notices and the GPL-3.0-or-later license are preserved.

Highlights

  • simple ParticlesSet -> Force -> Solver -> Animation/Renderer architecture;
  • Euler, Leapfrog, Runge-Kutta, Midpoint and Stormer-Verlet style integrators;
  • gravity, springs, constant force, drag, damping, Lennard-Jones, electrostatic and electromagnetic models;
  • constrained particles and constrained force interactions;
  • OpenGL interactive visualization;
  • optional PyOpenCL acceleration;
  • persistent OpenCL buffers to avoid unnecessary PCIe transfers;
  • fused OpenCL integration paths;
  • OpenCL/OpenGL shared VBO rendering;
  • double-buffered CL/GL synchronization with GL fences;
  • asynchronous OpenGL GPU timer queries;
  • an optimized fountain example used as a GPU performance case study.

Installation

The current release candidate is PyParticles3 0.4.0rc2.

python -m pip install PyParticles3

For OpenCL compute support:

python -m pip install 'PyParticles3[opencl]'

The OpenCL runtime/ICD and an OpenGL/FreeGLUT implementation are system-level dependencies and are not installed by pip.

OpenCL/OpenGL interoperability requires a GL-enabled PyOpenCL build

PyParticles3[opencl] installs PyOpenCL and is sufficient for OpenCL compute. It does not guarantee that the installed PyOpenCL binary was compiled with OpenGL interoperability enabled.

Check the installed build with:

python - <<'PY'
import pyopencl as cl
print("PyOpenCL:", cl.VERSION_TEXT)
print("have_gl :", cl.have_gl())
PY

For the fast OpenCL/OpenGL shared-buffer path used by the fountain demo, the required result is:

have_gl : True

If a PyPI wheel reports have_gl : False, OpenCL compute still works, but PyParticles3 cannot create GLBuffer objects and high-particle-count rendering must fall back to host synchronization. That fallback can be dramatically slower.

PyOpenCL's source-build documentation requires PYOPENCL_ENABLE_GL=ON to enable GL interoperability. A typical pip rebuild is:

python -m pip uninstall -y pyopencl

PYOPENCL_ENABLE_GL=ON \
python -m pip install \
    --no-binary=pyopencl \
    --no-cache-dir \
    -v \
    'pyopencl>=2026.1'

Then verify again:

python - <<'PY'
import pyopencl as cl
assert cl.have_gl(), "PyOpenCL was built without OpenGL interoperability"
print("PyOpenCL GL interoperability: enabled")
PY

Building PyOpenCL from source also requires a C++17 compiler, Python/build dependencies, OpenCL headers and loader libraries, and OpenGL development headers appropriate to the operating system.

Selecting an OpenCL device

PyParticles3 follows PyOpenCL's PYOPENCL_CTX selection for compute contexts. For example, on a system where platform 0 is an NVIDIA GPU and platform 1 is an Intel CPU:

PYOPENCL_CTX=0:0 pyparticles3 --demo fountain
PYOPENCL_CTX=1:0 pyparticles3 --demo fountain

As of 0.4.0rc2, an explicit PYOPENCL_CTX selection is also honored when PyParticles3 attempts to create a CL/GL sharing context. PyParticles3 will not silently move the simulation to another OpenCL device just because that other device supports cl_khr_gl_sharing.

This matters on mixed systems. An Intel Xeon CPU OpenCL device can execute the simulation kernels but may not advertise or support cl_khr_gl_sharing with the active NVIDIA OpenGL context. In that case PyParticles3 keeps the selected Intel compute device and falls back to host-synchronized rendering instead of silently switching compute to the NVIDIA GPU.

Current import namespace

The initial PyParticles3 packaging release intentionally keeps the historical Python import namespace:

import pyparticles

This avoids mixing a package-wide namespace migration with the packaging release. A future release may introduce a dedicated pyparticles3 namespace after a controlled compatibility migration.

Command line

The modern package exposes:

pyparticles3 --help
pyparticles3 --version

The historical command is also kept as a compatibility entry point:

pyparticles_app --help

Examples:

pyparticles3 --demo springs
pyparticles3 --demo solar_system
pyparticles3 --demo bubble
pyparticles3 --demo gas_lj
pyparticles3 --demo elmag_field
pyparticles3 --demo galaxy
pyparticles3 --demo fountain

Architecture

ParticlesSet
    |
    +--> Force / MultipleForce
    |        |
    |        v
    +----> ODE Solver
             |
             v
        Animation
             |
             v
          Renderer

The accelerated paths preserve these conceptual roles rather than replacing the whole program with an opaque GPU pipeline.

OpenCL/OpenGL fountain path

The modern fountain demo can keep simulation state resident on the GPU and render from shared OpenGL buffers. The optimized fused path writes both the canonical OpenCL position buffer and the shared render VBO from the integration kernel, eliminating a separate device-to-device position copy.

Profiling can be enabled with:

PYPARTICLES_PROFILE_CLGL=1 \
PYPARTICLES_PROFILE_FRAMES=1000 \
PYPARTICLES_PROFILE_WARMUP=200 \
pyparticles3 --demo fountain

The experimental fused render mirror is currently selected with:

PYPARTICLES_CLGL_FUSED_MIRROR=1 \
pyparticles3 --demo fountain

Development

git clone https://github.com/jamaj69/pyparticles.git
cd pyparticles
git switch package/pyparticles3

python -m venv .venv
source .venv/bin/activate
python -m pip install -U pip
python -m pip install -e '.[dev]'

python -m compileall -q pyparticles tests
python -W default -m unittest discover -v -s tests

Build the PyPI artifacts with:

python -m build
python -m twine check dist/*

Project links

When releases are published through PyPI Trusted Publishing from this GitHub repository, PyPI can verify the GitHub project links carried in the distribution metadata.

Origin and attribution

PyParticles was created by Simone Riva in 2012. PyParticles3 is an independent modernization built from that GPL-licensed codebase. The modernization focuses on Python 3 compatibility, modern scientific Python libraries, testing, GPU acceleration, CL/GL interoperability and documentation while preserving the original educational structure.

License

GPL-3.0-or-later. See LICENSE-gpl-3.0.txt.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyparticles3-0.4.0rc2.tar.gz (714.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyparticles3-0.4.0rc2-py3-none-any.whl (166.4 kB view details)

Uploaded Python 3

File details

Details for the file pyparticles3-0.4.0rc2.tar.gz.

File metadata

  • Download URL: pyparticles3-0.4.0rc2.tar.gz
  • Upload date:
  • Size: 714.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pyparticles3-0.4.0rc2.tar.gz
Algorithm Hash digest
SHA256 cec6e946e256743c874b7deb4a45263be772d849884d2656a210de454cee6675
MD5 eb3c459b77600a90b3af2064973b1e5f
BLAKE2b-256 8a81d05764b9abc2f0e668df03afe0b663cffa0022d21fc1c4b89f53ed9eff0f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyparticles3-0.4.0rc2.tar.gz:

Publisher: release.yml on jamaj69/pyparticles

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyparticles3-0.4.0rc2-py3-none-any.whl.

File metadata

  • Download URL: pyparticles3-0.4.0rc2-py3-none-any.whl
  • Upload date:
  • Size: 166.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pyparticles3-0.4.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 1e1b35f64274cb507ddb40656c585f5dc334d72a0461d2a84b7b3c4636c6e87b
MD5 63e9da7f797712befa9761fbc52e720e
BLAKE2b-256 341049039f673cba61c4bd4f3a56ae3bc5a4f582afc5501b2e79011b59f87d6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyparticles3-0.4.0rc2-py3-none-any.whl:

Publisher: release.yml on jamaj69/pyparticles

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.4.0

2 files

This release

0.4.0rc2 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page