Skip to main content

A parallel control system simulation and control library based on PyTorch.

Project description

torchcontrol

Introduction

torchcontrol is a parallel control system simulation and control library based on PyTorch. It supports batch simulation, classical and modern control, nonlinear systems, GPU acceleration, and visualization. The library is modular and extensible, suitable for both research and teaching.

Features

  • Batch simulation: Simulate multiple environments in parallel (vectorized, GPU-friendly)
  • Classical & modern control: Built-in PID controller, state-space, transfer function, and nonlinear system support
  • Custom plants: Easily define linear or nonlinear plants (systems) with custom dynamics
  • GPU acceleration: All computations support CUDA (if available)
  • Visualization: Example scripts for step response, PID control, and nonlinear systems with matplotlib output
  • Extensible: Modular design for adding new controllers, observers, or plants

Installation

From the project root, run:

pip install .

Or for development mode (auto-reload on code change):

pip install -e .

Directory Structure

  • torchcontrol/ # Main package (controllers, plants, system, observers)
  • examples/ # Example scripts (PID, nonlinear, batch, visualization)
    • results/ # Output results (figures, logs, etc.)
  • README.md
  • setup.py
  • pyproject.toml

How to Run Examples

After installation, run example scripts from the project root:

python3 examples/pid_with_internal_plant.py
python3 examples/pid_with_external_plant.py
python3 examples/second_order_plant_step_response.py
python3 examples/nonlinear_plant_step_response.py
  • All import paths use package-level imports (e.g., from torchcontrol.controllers import PID).
  • Output files will be automatically saved in examples/results/.
  • All examples support both CPU and GPU (CUDA) if available.

Example: Batch PID Control of Second-Order System

from torchcontrol.controllers import PID, PIDCfg
from torchcontrol.plants import InputOutputSystem, InputOutputSystemCfg
import torch

# System: G(s) = 1/(s^2 + 2s + 1)
dt = 0.01
num_envs = 16
num = [1.0]
den = [1.0, 2.0, 1.0]
initial_states = torch.rand(num_envs, 1) * 2
plant_cfg = InputOutputSystemCfg(numerator=num, denominator=den, dt=dt, num_envs=num_envs, initial_state=initial_states)
plant = InputOutputSystem(plant_cfg)
pid_cfg = PIDCfg(Kp=120.0, Ki=600.0, Kd=30.0, dt=dt, num_envs=num_envs, state_dim=1, action_dim=1, plant=plant)
pid = PID(pid_cfg)
# ...simulate and visualize...

Dependencies

  • Python 3.8+
  • torch
  • torchdiffeq
  • scipy
  • numpy
  • matplotlib

For GPU support, please ensure you have installed the CUDA version of PyTorch.

Customization & Extension

  • To add new controllers, inherit from ControllerBase and register a config.
  • To add new plants, inherit from PlantBase or use InputOutputSystem/NonlinearSystem.
  • See examples/ for advanced usage and batch simulation.

For batch simulation, RL interface, or custom controllers/systems, please refer to the code structure in the torchcontrol/ directory.

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

torchcontrol-0.1.0.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

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

torchcontrol-0.1.0-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file torchcontrol-0.1.0.tar.gz.

File metadata

  • Download URL: torchcontrol-0.1.0.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for torchcontrol-0.1.0.tar.gz
Algorithm Hash digest
SHA256 80528a93239cf39f5924d05bf756b76c9dd1327514593b9edd71d30a24fc6575
MD5 6e83b364f623bf585e15f14812d3e9e3
BLAKE2b-256 66aae95901a6441f01e6dc7e7902c2e249f069ece7afd52bdca66acb1617868c

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchcontrol-0.1.0.tar.gz:

Publisher: python-publish.yml on TangLongbin/torchcontrol

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

File details

Details for the file torchcontrol-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: torchcontrol-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for torchcontrol-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b245bc8d8271c278da52f5c1b9d8c60c7ff8302eff9ca100c52b88523efc9ef4
MD5 c2b2a72a97ecb1c3620136250e573a29
BLAKE2b-256 c2bb2d68cc3bba6222d8998a6dfd37119908330b45ca7c8d5c94be24e3404d1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchcontrol-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on TangLongbin/torchcontrol

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

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