polypus 0.7.0

Rust-core quantum variational optimization framework with a Python (PyO3) interface: circuit simulation, VQC/QML training and population-based optimizers (DE, PSO, QNG).
Documentation

Polypus

Polypus is a distributed quantum computing library designed to optimize the execution of quantum algorithms by distributing computation across available hardware resources. The core is written in Rust; Python bindings are provided via PyO3.

Polypus is agnostic to the underlying hardware infrastructure. Currently three infrastructure values are supported:

  • local: Runs on local infrastructure. Defaults to Qiskit AerSimulator (backend="aer"); pass backend="polypus" to run instead on the noiseless statevector simulator implemented natively in Rust (no Qiskit, no GIL).
  • cunqa: Distributed QPU platform developed by CESGA (https://github.com/CESGA-Quantum-Spain/cunqa).
  • qmio: CESGA's real QPU, reached directly over its ZeroMQ wire protocol (--features qmio).

Features

  • Run a quantum circuit on one or multiple QPUs.
  • Train variational quantum circuits using Differential Evolution, PSO or Quantum Natural Gradient.
  • Unified train() API — swap optimizers by changing a single argument.

Running a circuit

import polypus

# Single QPU
result = polypus.run_quantum_circuit(qc, shots=1000, infrastructure="local")

# Distribute shots across multiple QPUs
result = polypus.run_quantum_circuit(qc, shots=1000, infrastructure="local", n_qpus=10)

Both calls return a RunResult: result.counts holds the payload (a list[dict] for a single QPU, a merged dict for n_qpus > 1), plus result.id / result.seed / result.backend / result.infrastructure for logging and replay. Pass seed=... for reproducible shot noise on every simulated backend (native, Aer, CUNQA); result.seed reports the effective seed (None only for the "qmio" infrastructure, real hardware that cannot be seeded).

Training a variational circuit

Pass a method object as the second argument to train(). The optimizer-specific parameters are encapsulated in the method object; execution parameters are shared.

# Differential Evolution
result = polypus.train(
    qc, polypus.DE(generations=100, population_size=50, tolerance=0.01),
    shots=N_SHOTS, n_qpus=N_QPUS, dimensions=2*layers,
    expectation_function=bitstring_to_obj,
    infrastructure="local", nodes=1, cores_per_qpu=2, id="run1"
)

# Particle Swarm Optimization
result = polypus.train(
    qc, polypus.PSO(generations=100, population_size=50, bounds=(0.0, 3.14)),
    shots=N_SHOTS, n_qpus=N_QPUS, dimensions=2*layers,
    expectation_function=bitstring_to_obj,
    infrastructure="local", nodes=1, cores_per_qpu=2, id="run1"
)

# Quantum Natural Gradient
result = polypus.train(
    qc, polypus.QNG(variance_fn, max_iters=100, learning_rate=0.1),
    shots=N_SHOTS, n_qpus=N_QPUS, dimensions=2*layers,
    expectation_function=bitstring_to_obj,
    infrastructure="local", nodes=1, cores_per_qpu=2, id="run1"
)

train() returns a TrainResult exposing result.best_params (list[float]) plus result.best_fitness, result.iterations_run, result.converged, and the effective result.seed — the full optimization outcome, not just the parameters. Pass seed=... (or set it on the optimizer, e.g. polypus.DE(..., seed=42)) to reproduce a run.

Authors

Diego Beltrán Fernández Prada (diego.fernandez@bahiasoftware.es), Víctor Sóñora Pombo, Sergio Figueiras Gómez, Miguel Boubeta Martínez, Galicia Supercomputing Center (CESGA)

License

European Union Public Licence (EUPL), version 1.2 or – as soon as they will be approved by the European Commission – subsequent versions of the EUPL.