Skip to main content

Quantum gate and pulse design with optimal control

Project description

ctrl-freeq

Ctrl-freeq is a numerical framework for the design of quantum gates and pulses via optimal control theory, implemented in Python with PyTorch. The control pulse optimization problem is formulated and solved using automatic differentiation, and the resulting software provides both a programmatic API and a graphical user interface for the configuration and execution of optimization workflows.

  • PyPI package: ctrl-freeq
  • Import path: ctrl_freeq
  • Minimum Python: 3.13
  • CLI entry point: freeq-gui

Features

The framework supports the definition and solution of gate optimization problems through JSON configuration files. A high-level Python API is provided for loading configurations, executing the optimizer, and post-processing results, while a Tkinter-based GUI (launched via freeq-gui) offers an interactive alternative for users who prefer a graphical workflow. Optimization results may be visualized through interactive Plotly dashboards exported as standalone HTML files. CPU thread management is handled automatically, and optional GPU acceleration is available via CUDA.

Installation

Ctrl-freeq depends on NumPy, PyTorch, Qiskit, pytorch-minimize, Plotly, and other scientific packages.

# Install from source
uv sync

# Or with all development tools
uv sync --all-groups

Note: Dependency groups (dev, docs, tools) use PEP 735 and require uv — they are not pip extras.

For pip users:

pip install .

A detailed treatment of all installation methods is provided in the Installation documentation.

Quick Start

Launch the GUI

freeq-gui

Execution of this command launches the Tkinter-based graphical interface defined in ctrl_freeq/cli.py.

Use the API

from ctrl_freeq.api import CtrlFreeQAPI, run_from_config, load_single_qubit_config

# Load a built-in example configuration
config = load_single_qubit_config()

# Option A: one-shot helper
result = run_from_config(config)

# Option B: create an API instance to inspect and edit parameters
api = CtrlFreeQAPI(config)
print(api.get_config_summary())
api.update_parameter("optimization.max_iter", 500)
result = api.run_optimization()
print(f"Final fidelity: {api.parameters.final_fidelity:.6f}")

Project Structure

src/ctrl_freeq/       Core package
  api.py              High-level API
  cli.py              CLI entry point (freeq-gui)
  setup/              GUI and configuration setup
  run/                Optimization engine
  utils/              Plotting, dashboards, helpers
examples/             Example configs and notebooks
tests/                Test suite
pyproject.toml        Build and packaging configuration

Development

Development tools are organized into dependency groups: dev (pytest, jupyter), docs (mkdocs), and tools (ruff, pre-commit).

# Install dev dependencies
uv sync --all-groups

# Run tests
uv run pytest -q

# Lint
uv run ruff format .
uv run ruff check --fix .

Compute Resource Selection (CPU/GPU)

Ctrl-freeq supports execution on both CPU and GPU (CUDA) hardware:

  • cpu (default) — PyTorch threads are limited to max(1, os.cpu_count() - 1). This default may be overridden with the cpu_cores field.
  • gpu — CUDA is used if available; the framework falls back to CPU with a warning if CUDA is not present.

API Configuration

config = {
    "compute_resource": "gpu",   # or "cpu" (default)
    "cpu_cores": 8,              # optional, CPU only
    ...
}

GUI

The compute resource may be selected from the Compute Resource dropdown in the Optimization Parameters section of the graphical interface.

Note: Only CUDA is supported for GPU acceleration. MPS is not currently supported.

A demonstration notebook is provided at examples/api_gpu_cpu_demo.ipynb, illustrating CPU vs CUDA selection and comparative timing.

License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

Citation

If this software is used in academic work, please cite it using the metadata provided in CITATION.cff.

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

ctrl_freeq-0.1.0b4.tar.gz (80.2 kB view details)

Uploaded Source

Built Distribution

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

ctrl_freeq-0.1.0b4-py3-none-any.whl (73.8 kB view details)

Uploaded Python 3

File details

Details for the file ctrl_freeq-0.1.0b4.tar.gz.

File metadata

  • Download URL: ctrl_freeq-0.1.0b4.tar.gz
  • Upload date:
  • Size: 80.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ctrl_freeq-0.1.0b4.tar.gz
Algorithm Hash digest
SHA256 54e0ef2f6999a25ecfba90d85bd4acd3d985826e17b1d3bcda568f5bbd6e1f7c
MD5 0be5640d40f3f589ee7aced714399d40
BLAKE2b-256 c5c82191bb9cee6569b2418c4439194195380bb688c49a3298542a5acc288194

See more details on using hashes here.

File details

Details for the file ctrl_freeq-0.1.0b4-py3-none-any.whl.

File metadata

  • Download URL: ctrl_freeq-0.1.0b4-py3-none-any.whl
  • Upload date:
  • Size: 73.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ctrl_freeq-0.1.0b4-py3-none-any.whl
Algorithm Hash digest
SHA256 bdc1a1ff4daab652598a17b80b5a5239bf998b0206af918df235f730c8d057e2
MD5 4c341b9e5f627eef65db11edc70ab1b1
BLAKE2b-256 be6fa1480a82cc0f29d37035a7508de0e110b9b19887f6283a03954120f33b71

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