Skip to main content

Crate polypus

Crate polypus 

Source
Expand description

§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.

§Installation — same project, three names

pip install polypus-quantum · import polypus · cargo add polypus.

The name polypus on PyPI is taken by an unrelated project, so the Python distribution is published as polypus-quantum; the Python import name and this Rust crate both stay polypus.

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, Quantum Natural Gradient, CMA-ES, Adam, SPSA or Rotosolve, or an external ask/tell optimizer (Optuna, Nevergrad, pycma or your own) through polypus.External.
  • 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 with the same shape whatever n_qpus is: result.counts is always a list[dict], one dict per QPU (so result.counts[0] works for any n_qpus), and result.merged_counts is their total as one dict over all shots. result.id / result.seed / result.backend / result.infrastructure carry the manifest 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"
)

# CMA-ES, with up to 2 IPOP restarts that double the population
result = polypus.train(
    qc, polypus.CMAES(generations=100, restarts=2),
    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.

Re-exports§

pub use polypus_evaluation as evaluation;
pub use polypus_infrastructure as infrastructure;
pub use polypus_orchestration as orchestration;
pub use polypus_logger as logger;
pub use polypus_circuit as circuit;
pub use polypus_optimizers as optimizers;
pub use crate::algorithms::*;

Modules§

algorithms
exceptions
Custom Python exception hierarchy raised across the FFI boundary. Custom Python exception hierarchy for the Polypus bindings.