Skip to main content

Optical Tweezers Force Engine — Python port of the OTS toolbox (Phase 1: Mie sphere, non-paraxial focused-beam force)

Project description

fatcuda

fatcuda is an intent-first optical tweezers force and field engine. It starts from physical declarations - beam intent, optical system, particle or task, and device policy - then lowers them into auditable intermediate representations and verified CPU/CUDA/Metal execution paths.

The current production package lives in fatcuda/. The historical direct-port implementation is archived in fatcuda_old/ and is kept only as an oracle, comparison source, and history bundle.

Status

This project is still early. The current verified path focuses on homogeneous Mie spheres, non-paraxial Debye-Wolf focusing, multipole coefficients, field slices, force maps, and CPU/Metal/CUDA interface parity. APIs may still move while the package is prepared for a first public PyPI release.

Installation

After publication:

python -m pip install fatcuda
python -m pip install "fatcuda[metal]"   # Apple Silicon / MLX path
python -m pip install "fatcuda[cuda12]"  # CUDA 12 / CuPy path

For local development from this checkout:

python -m pip install -e ".[test,demo]"
python -m pip install -e ".[test,demo,metal]"
python -m pip install -e ".[test,demo,cuda12]"

The default portable execution path is CPU-only and depends on NumPy and SciPy.

Minimal Example

import numpy as np

from fatcuda import (
    ForceAtPositions,
    GaussianBeam,
    OpticalSystem,
    PupilGrid,
    Sphere,
    solve,
)

system = OpticalSystem(grid=PupilGrid(Nphi=32, Nr=16), power=1.0e-3)
beam = GaussianBeam(Ex0=1.0, Ey0=0.0)
sphere = Sphere(radius=0.2e-6, n_p=1.59, L=8)
task = ForceAtPositions(
    positions=np.array(
        [
            [0.0, 0.0, 0.0],
            [0.1e-6, 0.0, 0.0],
        ]
    ),
    particle=sphere,
)

result = solve(
    beam=beam,
    system=system,
    task=task,
    strategy="auto",
    device="cpu",
)

print(result.force)
print(result.torque)
print(result.audit.operator_plan)

Progress Callbacks

Execution progress is opt-in and reported as immutable structured events. The callback runs synchronously on the caller thread; use "stage" for stage-only events or the default "detailed" mode for bounded force/field advances.

def on_progress(event):
    print(event.stage, event.state, event.completed, event.total, event.unit)

result = solve(
    beam=beam,
    system=system,
    task=task,
    device="cuda",
    progress_callback=on_progress,
    progress_granularity="detailed",
)

Callbacks do not become part of the task, IR, audit, or result. CUDA detailed events are emitted only after their selected stream events complete.

Public API Shape

The recommended user flow is:

beam intent + optical system + particle/task + device/strategy -> auditable IR -> kernels

Common public declarations include:

Concept Examples
Beams GaussianBeam, LaguerreGaussBeam, HermiteGaussBeam, AiryBeam, VortexBeam, SLMPhaseBeam
System OpticalSystem, PupilGrid
Particles Sphere
Tasks ForceAtPositions, FieldSlice
Execution solve, compile_problem, DevicePolicy, OperatorStrategy, PrecisionPolicy

Verification

The repository uses MATLAB OTS fixtures, the current CPU NumPy path, and closed-form physics sanity checks as oracles. Typical local verification:

python -m pytest -q -p no:cacheprovider

CUDA numerical validation requires a CUDA machine. On macOS without CUDA, CUDA tests are limited to import, collection, skip behavior, and shared-interface non-breakage. Metal validation requires Apple Silicon with the metal extra installed and MLX reporting Metal availability.

Documentation

The detailed code-layer notes live under doc/obsidian/fatcuda/代码层/.

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

fatcuda-0.1.2.tar.gz (146.5 kB view details)

Uploaded Source

Built Distribution

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

fatcuda-0.1.2-py3-none-any.whl (159.6 kB view details)

Uploaded Python 3

File details

Details for the file fatcuda-0.1.2.tar.gz.

File metadata

  • Download URL: fatcuda-0.1.2.tar.gz
  • Upload date:
  • Size: 146.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for fatcuda-0.1.2.tar.gz
Algorithm Hash digest
SHA256 94178c1efa58ec6e9941941e024d51a487fce917a941f306e53f36b99ac308b1
MD5 daf129beee23c14595fce88fe669f17d
BLAKE2b-256 54865f4ac831a5f4870e10d2c077bf1974f95948dde5ddbfee679fdfe0daf71f

See more details on using hashes here.

File details

Details for the file fatcuda-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: fatcuda-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 159.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for fatcuda-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4c308112eed982701054c2c5e8ac97b8a3433a86b2bb5590ed1e1d4056040df5
MD5 868b15e10e344a7d854059fd6c0731fc
BLAKE2b-256 ffedd4e7070d136a3e3996305d65d1a2f45cd0fd0b6ff57b54653ba4d9d436c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page