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.1.tar.gz (15.2 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.1-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: torchcontrol-0.1.1.tar.gz
  • Upload date:
  • Size: 15.2 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.1.tar.gz
Algorithm Hash digest
SHA256 6414aa7f25e05277daa58fa0e9bcb029cffa2b07a0d5d711c7e9a789d2adaa11
MD5 cbc27f6db6f0ca0bd86bec3b36e6e2a4
BLAKE2b-256 abaf22d79edc8c5d1838b69465960a9aa06e45aad30c089f24a31cd7b5f7362b

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchcontrol-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: torchcontrol-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ec0da1d74fe2dc0646692e3e8eb00e1729583e27ca6d338947722e2610715f89
MD5 c12c6bdfcbb7c81ce283cb4c08f9f685
BLAKE2b-256 d292f723b3fa3cd8d9d761ccd9c27abe161cbf382eeb3e0d30cda9b6dad6fdb2

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchcontrol-0.1.1-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