Skip to content

Getting started

Install

pip install polypus-quantum

The package imports as polypus. Wheels are published for CPython 3.10 to 3.13 on Linux (x86_64 and aarch64), macOS on Apple Silicon and Windows (x86_64). On other platforms, Intel Macs included, pip builds the source distribution, which needs a Rust toolchain (1.85 or newer).

To use Install
Local simulators (Aer and native) pip install polypus-quantum
A native QML model as a PyTorch layer (polypus.torch) pip install "polypus-quantum[torch]"
Optuna, Nevergrad or pycma through polypus.External pip install "polypus-quantum[optuna]" ([nevergrad], [cma])
CUNQA Polypus, plus CUNQA >=2.4,<4 on the cluster. CUNQA 2.3 is not supported (it names the qraise argument cores, not cores_per_qpu)
QMIO Polypus built from source with the qmio feature: bash install.sh --qmio
The Rust crates cargo add polypus-circuit, or any crate in the workspace; all but three are pure Rust

A first circuit

import polypus

bell = polypus.Circuit(2).h(0).cx(0, 1).measure_all()
result = polypus.run_quantum_circuit(
    bell, shots=1000, infrastructure="local", backend="polypus", n_qpus=4
)

result.counts  # one counts dict per QPU
result.merged_counts  # e.g. {'00': 487, '11': 513}

backend="polypus" is the native Rust simulator, which does not load Qiskit Aer. Aer is the default backend.

A first training run

import polypus

edges = [(0, 1), (1, 2), (2, 3), (3, 0)]
gamma, beta = polypus.Param(0), polypus.Param(1)

qaoa = polypus.Circuit(4)
for q in range(4):
    qaoa.h(q)
for i, j in edges:
    qaoa.rzz(i, j, gamma)
for q in range(4):
    qaoa.rx(q, beta)
qaoa.measure_all()

# Cut size as a QUBO, evaluated natively. Optimizers maximise.
cut = polypus.Qubo(
    4,
    linear=[(q, 2.0) for q in range(4)],
    quadratic=[(i, j, -2.0) for i, j in edges],
)

result = polypus.train(
    qaoa,
    polypus.DE(generations=100, population_size=50, seed=42),
    shots=1024,
    n_qpus=1,
    dimensions=2,
    expectation_function=cut,
    infrastructure="local",
    backend="polypus",
    nodes=1,
    cores_per_qpu=1,
    id="maxcut",
)
result.best_params, result.best_fitness

Where next