Quick Start Guide

Welcome to Divi! This guide will get you up and running with quantum program execution.

What is Divi?

Divi is a Python library that automates the orchestration around quantum programs: circuit generation, batching, error mitigation, parameter optimisation, and result aggregation. Whether you’re studying molecular systems or solving combinatorial optimisation problems, Divi handles the plumbing so you can focus on the problem.

Core capabilities:

  • Automated execution — run quantum programs with minimal boilerplate.

  • Parallel circuit execution — distribute circuits across available resources automatically.

  • Pluggable backends — swap between local simulators, noisy simulators, and cloud hardware without changing program code.

  • Integrated error mitigation — ZNE and QuEPP plug into the variational loop.

  • Progress tracking — real-time feedback during long-running computations.

Five-Minute Tutorial

Let’s solve a quantum chemistry problem - finding the ground state energy of a hydrogen molecule:

Molecule inputs come from the chem extra. Install it first:

pip install "qoro-divi[chem]"
from pyscf import gto
from divi.qprog.algorithms import VQE, HartreeFockAnsatz
from divi.qprog.optimizers import ScipyMethod, ScipyOptimizer
from divi.qprog.problems import MolecularProblem
from divi.backends import MaestroSimulator

# Step 1: Define your molecule and wrap it in a problem
h2_molecule = gto.M(
   atom="H 0 0 -0.6614; H 0 0 0.6614", basis="sto-3g", unit="Bohr"
)
h2_problem = MolecularProblem.from_molecule(h2_molecule)

# Step 2: Choose your optimizer
optimizer = ScipyOptimizer(method=ScipyMethod.COBYLA)

# Step 3: Set up your quantum program
vqe = VQE(
   h2_problem,
   ansatz=HartreeFockAnsatz(),
   n_layers=2,  # Circuit depth
   optimizer=optimizer,
   max_iterations=10,  # Optimization steps
   backend=MaestroSimulator(shots=1000),  # Local simulator
)

# Step 4: Run and get results!
vqe.run()

# Check your results
print(f"Ground state energy: {vqe.best_loss:.6f} Hartree")
print(f"Circuits executed: {vqe.total_circuit_count}")

That’s it — you just ran a variational quantum algorithm.

Tip

divi-ai answers questions about Divi in your terminal: pip install qoro-divi[ai] && divi-ai

Algorithms

Divi offers specialised algorithms for different problem types:

VQE – Quantum Chemistry

VQE covers molecular ground state calculations, dissociation curves, and electronic structure problems.

from divi.qprog.algorithms import VQE, UCCSDAnsatz
from divi.qprog.optimizers import MonteCarloOptimizer

vqe = VQE(
    h2_problem,
    ansatz=UCCSDAnsatz(),
    n_layers=2,
    optimizer=MonteCarloOptimizer(),
    backend=MaestroSimulator()
)
QAOA – Optimisation Problems

QAOA covers combinatorial optimisation: Max-Cut, Max-Clique, travelling salesman, QUBO/HUBO, and similar NP-hard problems (graphs or binary polynomial formulations).

import networkx as nx
from divi.qprog.algorithms import QAOA
from divi.qprog.problems import MaxCutProblem
from divi.qprog.optimizers import MonteCarloOptimizer

# Create your problem graph
graph = nx.erdos_renyi_graph(10, 0.5, seed=42)

qaoa = QAOA(
    MaxCutProblem(graph),
    n_layers=2,
    max_iterations=10,
    optimizer=MonteCarloOptimizer(),
    backend=MaestroSimulator()
)
qaoa.run()
print(f"Best loss: {qaoa.best_loss:.4f}")
print(f"Solution: {qaoa.solution}")
PCE – QUBO/HUBO with Pauli Correlation Encoding

PCE covers QUBO and higher-order (HUBO) binary optimisation with parity-based encoding. PCE is a VQE variant; see Combinatorial Optimisation with QAOA and PCE for the encoding details.

import numpy as np
from qiskit.circuit.library import CXGate, RYGate, RZGate
from divi.qprog.algorithms import PCE, GenericLayerAnsatz
from divi.qprog.problems import BinaryOptimizationProblem
from divi.backends import MaestroSimulator

from divi.qprog.optimizers import MonteCarloOptimizer

qubo_matrix = np.array([[-1.0, 2.0], [0.0, 1.0]])
pce = PCE(
    problem=BinaryOptimizationProblem(qubo_matrix),
    ansatz=GenericLayerAnsatz(
        gate_sequence=[RYGate, RZGate],
        entangler=CXGate,
        entangling_layout="all-to-all",
    ),
    optimizer=MonteCarloOptimizer(),
    backend=MaestroSimulator(),
)
pce.run()
TimeEvolution – Hamiltonian Dynamics

Use TimeEvolution to simulate real-time quantum dynamics under a Hamiltonian (Trotter-Suzuki or QDrift). Supports probability or observable mode.

import math
from qiskit.quantum_info import SparsePauliOp
from divi.qprog.algorithms import TimeEvolution
from divi.backends import MaestroSimulator

te = TimeEvolution(
    hamiltonian=SparsePauliOp.from_sparse_list(
        [("X", [0], 1.0), ("X", [1], 1.0)], num_qubits=2
    ),
    time=math.pi / 2,
    backend=MaestroSimulator(shots=5000),
)
te.run()
print(te.results)  # basis-state probabilities
QNN – Quantum Machine Learning

Use QNN to train a variational classifier on a classical feature batch: a feature map encodes each sample, a trainable ansatz supplies the weights, and Divi composes and binds the circuit for you. See Quantum Neural Networks. To bring your own PennyLane or Qiskit circuit instead, use CustomVQA (PennyLane & Qiskit Integration).

import numpy as np
from qiskit.circuit.library import CXGate, RYGate, RZGate
from divi.qprog.algorithms import QNN, AngleEmbedding, GenericLayerAnsatz
from divi.qprog.optimizers import ScipyMethod, ScipyOptimizer
from divi.backends import MaestroSimulator

qnn = QNN(
    n_qubits=2,
    feature_map=AngleEmbedding(rotation="Y"),
    ansatz=GenericLayerAnsatz(
        gate_sequence=[RYGate, RZGate],
        entangler=CXGate,
        entangling_layout="linear",
    ),
    feature_batch=np.array([[0.1, 0.2], [2.0, 2.1]]),
    labels=np.array([-1.0, 1.0]),
    loss_fn="squared_error",
    max_iterations=5,
    optimizer=ScipyOptimizer(method=ScipyMethod.COBYLA),
    backend=MaestroSimulator(),
)
qnn.run(perform_final_computation=False)

Check Before You Run

Every program can tell you what it would submit, without executing anything. Rebuilding the H₂ VQE from the top of this page:

from divi.pipeline import format_dry_run

preview_vqe = VQE(
    h2_problem,
    ansatz=HartreeFockAnsatz(),
    n_layers=2,
    optimizer=ScipyOptimizer(method=ScipyMethod.COBYLA),
    backend=MaestroSimulator(shots=1000),
)
format_dry_run(preview_vqe.dry_run())
cost
├── CircuitSpecStage [circuit] → 14
│   ├── n_qubits: 4
│   ├── n_gates: 82
│   └── depth: 47
├── MeasurementStage [obs_group] → ÷14
│   ├── strategy: analytic
│   └── n_pauli_terms: 14
├── Total (per evaluation): 14 ÷ 14 = 1 circuit · 1,000 shots
└── Summary: avg depth 47, width 4, 36 2q-gates total

sample
├── CircuitSpecStage [circuit] → 1
├── MeasurementStage [obs_group] → 1
├── Total (once): 1 circuit · 1,000 shots
└── Summary: avg depth 47, width 4, 36 2q-gates total

One tree per routine the program runs — here cost, which the optimizer re-evaluates, and sample, the single readout VQE performs after training. Abridged above: each stage also reports more metadata rows, and the real trees carry two further stages (PreprocessStage and ParameterBindingStage, both at factor 1 here).

The Total line gives the circuits and shots submitted per evaluation — this program submits 1 circuit per evaluation. Maestro evaluates this expectation value analytically, so the displayed 1,000 shots are configured but not consumed. The rows above show how it got there. The spec stage’s 14 is the starting point (this Hamiltonian has 14 Pauli terms), and each stage below multiplies or divides it: here MaestroSimulator evaluates the whole observable at once, so ÷14 collapses those 14 terms back into a single circuit. A different backend, or error mitigation, changes those factors — and a natural-gradient optimizer drives extra routines of its own, which appear as further trees.

One caveat: Total is per evaluation, not per iteration and not per run. Optimizers evaluate the cost more than once per step — COBYLA, used here, decides how often as it goes — so Total × max_iterations is a floor, not a bill. See Dry Run for the full reading guide, and for what a dry run deliberately does not tell you.

Backend Options

Local development

MaestroSimulator (shown in all examples above) supports hand-written noise models. QiskitSimulator supports Qiskit-native and device-calibrated noise models and requires the aer extra (Optional Extras).

Cloud simulation & hardware

Access scalable cloud simulators (statevector, tensor-network, and more) through QoroService. Sign up at dash.qoroquantum.net to get started with free credits. For real quantum hardware access, contact us:

from divi.backends import QoroService, JobConfig

# Bell pair: H + CNOT, then measure both qubits (OpenQASM 2.0)
qasm = (
    'OPENQASM 2.0;\n'
    'include "qelib1.inc";\n'
    'qreg q[2];\n'
    'creg c[2];\n'
    'h q[0];\n'
    'cx q[0],q[1];\n'
    'measure q[0] -> c[0];\n'
    'measure q[1] -> c[1];\n'
)

service = QoroService()  # Uses QORO_API_KEY from .env file
result = service.submit_circuits(
    {"my_circuit": qasm},
    job_config=JobConfig(simulator_cluster="qoro_maestro"),
)
service.poll_job_status(result, loop_until_complete=True)
completed = service.get_job_results(result)
print(completed.results)