Models & Methods

The models subpackage contains quantum circuit templates (ansätze) and analysis tools.

Ansätze: Quantum Circuit Templates

Ansätze are pre-built quantum circuit patterns used as templates for quantum algorithms.

Circuit templates to simulate: variational patterns and textbook algorithms.

class mpstab.models.ansatze.Ansatz(nqubits: int)[source]

Bases: ABC

Abstract ansatz to generate quantum states.

Every ansatz names the fields that set its two resources, so a sweep knows which knob to turn:

  • magic_parameters: fields that set how far the circuit is from a Clifford circuit, i.e. how many magic gates HSMPO keeps and how large their angles are;

  • entanglement_parameters: fields that set which qubits interact and for how long, i.e. how fast the bond dimension of the state can grow.

A field may appear in both: a generic rotation angle sets the magic and, through the couplings, also the entangling power.

property circuit: Circuit
entanglement_parameters: ClassVar[Tuple[str, ...]] = ()
magic_parameters: ClassVar[Tuple[str, ...]] = ()
property nparams
nqubits: int
partitionate_circuit(replacement_probability: float = 0.0, replacement_method: str = 'closest', rng: Random | None = None)[source]

Split the circuit into a Clifford part and the magic gates left over.

Each non-Clifford gate is replaced by the nearest Clifford one with probability replacement_probability, and kept as a magic gate otherwise. Every magic gate is recorded with the number of Clifford gates preceding it, which is where it has to be reinserted later.

Parameters:
  • replacement_probability – chance of replacing each non-Clifford gate. The default 0 keeps every non-Clifford gate as magic.

  • replacement_method – "closest" or "random" Clifford angle.

  • rng – source of the replacement draws, such as a seeded random.Random. Defaults to the global random module.

Returns:

((magic_gates, clifford_circuit), full_circuit), where magic_gates is a list of (breakpoint_index, gate) and full_circuit is the sampled circuit including its magic gates.

class mpstab.models.ansatze.CircuitAnsatz(*, qibo_circuit: Circuit)[source]

Bases: Ansatz

A simple wrapper that converts a Qibo Circuit into an Ansatz object.

Parameters:

input_circuit (Circuit) – The Qibo circuit to wrap.

nqubits: int
qibo_circuit: Circuit
class mpstab.models.ansatze.FloquetAnsatz(nqubits: int, nlayers: int = 2, b: float = 1.2566370614359172, theta: float = 1.5707963267948966, target_qubit: int = 1, decompose_rzz: bool = True)[source]

Bases: Ansatz

Floquet echo: U = (FL)^t · Rz(theta) on qubit q · (FL^t)†.

Parameters:
  • nlayers (int) – number of Floquet layers.

  • b (float) – parameter controlling the magic in the circuit;

  • theta (float) – controls the signal;

  • target_qubit (int) – this is the qubit, in the circuit, on which we perform the final local measurement (and the one on which we apply H and RZ).

  • decompose_rzz (bool) – if True, RZZ is decomposed into CNOTs and RZ.

b: float = 1.2566370614359172
decompose_rzz: bool = True
entanglement_parameters: ClassVar[Tuple[str, ...]] = ('nlayers', 'b')
magic_parameters: ClassVar[Tuple[str, ...]] = ('b', 'theta')
nlayers: int = 2
partitionate_circuit(replacement_probability: float = 0.0, replacement_method: str = 'closest', rng: Random | None = None)[source]

Partitionate the full Floquet circuit U = H · half_sandwich · RZ · (half_sandwich)†, but only sweep the half_sandwich for magic gates. Returns ((magic_gates, clifford_only_circuit), full_circuit).

target_qubit: int = 1
theta: float = 1.5707963267948966
class mpstab.models.ansatze.Grover(nqubits: int, *, transpile: bool = True, native_gates: List | None = <factory>, connectivity: Graph | None = None, marked_state: int | None = None, n_iterations: int | None = None)[source]

Bases: _CompiledAnsatz

Grover search: H^n then n_iterations x (oracle + diffuser).

The oracle phase-flips marked_state (default \(|1\dots1\rangle\)) via a multi-controlled-Z; the diffuser is the standard inversion-about-the-mean. See _multi_controlled_z() for the oracle-correctness caveat at nqubits > 3.

Parameters:
  • marked_state – Integer in [0, 2^nqubits). Default 2^nqubits - 1.

  • n_iterations – Grover iterations. Default round(pi/4 * sqrt(2^nqubits)).

entanglement_parameters: ClassVar[Tuple[str, ...]] = ('n_iterations',)
marked_state: int | None = None
n_iterations: int | None = None
class mpstab.models.ansatze.HammingWeightPreserving(nqubits: int, nlayers: int = 1)[source]

Bases: Ansatz

Hamming-weight-preserving ansatz built from decomposed RBS gates.

Each RBS gate rotates within the \(\{|01\rangle, |10\rangle\}\) subspace of a qubit pair, leaving \(|00\rangle\) and \(|11\rangle\) unchanged:

RBS(θ)|01⟩ =  cos(θ)|01⟩ + sin(θ)|10⟩
RBS(θ)|10⟩ = -sin(θ)|01⟩ + cos(θ)|10⟩

RBS is decomposed into gates mpstab supports natively:

CNOT(ctrl=q1, tgt=q0)
RY(q1,  θ)              ← magic gate
CNOT(ctrl=q0, tgt=q1)
RY(q1, -θ)              ← magic gate
CNOT(ctrl=q0, tgt=q1)
CNOT(ctrl=q1, tgt=q0)

The circuit always starts with n//2 X gates to prepare the half-filling state \(|1\dots10\dots0\rangle\), giving a fixed Hamming weight of n//2.

Within each layer the connectivity pattern mirrors hw_preserving from Qibo examples: four connect_qubits passes with jump sizes 1 and 2 and different starting offsets to explore both nearest- and next-nearest- neighbour correlations with circular boundary conditions.

Parameters:
  • nqubits – Number of qubits (must be even).

  • nlayers – Number of RBS layers.

entanglement_parameters: ClassVar[Tuple[str, ...]] = ('nlayers',)
magic_parameters: ClassVar[Tuple[str, ...]] = ('nlayers',)
nlayers: int = 1
class mpstab.models.ansatze.HardwareEfficient(nqubits: int, nlayers: int = 1, entangling: bool = True)[source]

Bases: Ansatz

Layers of random RY rotations, each followed by a ring of CZ gates.

entanglement_parameters: ClassVar[Tuple[str, ...]] = ('nlayers', 'entangling')
entangling: bool = True
magic_parameters: ClassVar[Tuple[str, ...]] = ('nlayers',)
nlayers: int = 1
class mpstab.models.ansatze.HardwareEfficientBrickwork(nqubits: int, nlayers: int = 1)[source]

Bases: Ansatz

Hardware Efficient ansatz with a full brickwork entanglement pattern.

Each layer applies two sublayers of single-qubit RY+RZ rotations interleaved with CZ entanglement:

sublayer 1: RY+RZ on all qubits → CZ on even bonds (0-1, 2-3, …) sublayer 2: RY+RZ on all qubits → CZ on odd bonds (1-2, 3-4, …) + CZ(0, n-1)

A final layer of RY rotations closes the circuit. The ring-closing CZ(0, n-1) in the odd sublayer creates long-range entanglement.

Parameters:
  • nqubits – Number of qubits.

  • nlayers – Number of full brickwork layers.

entanglement_parameters: ClassVar[Tuple[str, ...]] = ('nlayers',)
magic_parameters: ClassVar[Tuple[str, ...]] = ('nlayers',)
nlayers: int = 1
class mpstab.models.ansatze.KickedIsing(nqubits: int, n_steps: int = 1, theta_h: float = 0.8, theta_z: float = 0.0, theta_j: float = -1.5707963267948966)[source]

Bases: _KickedIsingBase

Build a kicked Ising circuit on an open chain.

Each of the n_steps steps applies the kicks \(R_X(\theta_h)\) and then \(R_Z(\theta_z)\) on every qubit, followed by the couplings \(R_{ZZ}(\theta_J)\) on the even bonds and then on the odd bonds. Every coupling is written as CNOT · RZ(theta_j) · CNOT, the form HSMPO splits into Clifford and magic gates, so the circuit needs no transpilation. At the default theta_j = -pi/2 the couplings are Clifford and only the kicks are magic, so the MPS bond dimension grows with the number of steps.

Every angle that is not a multiple of \(\pi/2\) is a magic gate as a whole; ParametricKickedIsing separates the Clifford part of each angle from the magic one.

Parameters:
  • nqubits – number of qubits in the chain.

  • n_steps – number of kick-and-couple steps.

  • theta_h – angle of the transverse kicks \(R_X\).

  • theta_z – angle of the longitudinal kicks \(R_Z\).

  • theta_j – angle of the \(R_{ZZ}\) couplings.

entanglement_parameters: ClassVar[Tuple[str, ...]] = ('n_steps', 'theta_h', 'theta_j')
magic_parameters: ClassVar[Tuple[str, ...]] = ('theta_h', 'theta_z', 'theta_j')
theta_h: float = 0.8
theta_j: float = -1.5707963267948966
theta_z: float = 0.0
class mpstab.models.ansatze.ParametricKickedIsing(nqubits: int, n_steps: int = 1, delta_h: float = 0.1, delta_j: float = 0.0, delta_z: float = 0.0, clifford_h: float = 1.5707963267948966, clifford_j: float = -1.5707963267948966)[source]

Bases: _KickedIsingBase

Build a kicked Ising circuit parametrised by its distance from a Clifford point.

It is the circuit of KickedIsing with the angles

\[\theta_h = \theta_h^C + \delta_h, \qquad \theta_J = \theta_J^C + \delta_J, \qquad \theta_z = \delta_z, \]

where \(\theta_h^C\) and \(\theta_J^C\) are multiples of \(\pi/2\), so that at \(\delta = 0\) the whole circuit is Clifford. The defaults \(\theta_h^C = \pi/2\), \(\theta_J^C = -\pi/2\) are the self-dual point, where the entanglement grows at the maximal speed.

Every rotation is written as its Clifford part followed by the deviation, \(R(\theta^C + \delta) = R(\delta)\,R(\theta^C)\), as two separate gates. HSMPO then puts \(R(\theta^C)\) in the stabilizer part and keeps only the small rotation \(R(\delta)\) as a magic gate, instead of treating the whole \(R(\theta^C + \delta)\) as magic. The two groups of fields therefore tune the two resources separately:

  • the deviations delta_h, delta_j, delta_z set the magic: the number of magic gates (a deviation equal to zero adds no gate) and the size of their angles;

  • the Clifford skeleton clifford_h, clifford_j and n_steps set the entanglement: which Clifford circuit the stabilizer part evolves, hence how fast the entanglement grows. The deviations change it only perturbatively.

Each of the n_steps steps applies the kicks \(R_X\) and then \(R_Z\) on every qubit, followed by the couplings \(R_{ZZ}\) on the even bonds and then on the odd bonds, each coupling written as CNOT · RZ · CNOT.

Parameters:
  • nqubits – number of qubits in the chain.

  • n_steps – number of kick-and-couple steps.

  • delta_h – deviation of the transverse kicks \(R_X\) from clifford_h.

  • delta_j – deviation of the \(R_{ZZ}\) couplings from clifford_j.

  • delta_z – angle of the longitudinal kicks \(R_Z\) (Clifford point: 0).

  • clifford_h – Clifford angle of the transverse kicks, a multiple of pi/2.

  • clifford_j – Clifford angle of the couplings, a multiple of pi/2.

clifford_h: float = 1.5707963267948966
clifford_j: float = -1.5707963267948966
delta_h: float = 0.1
delta_j: float = 0.0
delta_z: float = 0.0
entanglement_parameters: ClassVar[Tuple[str, ...]] = ('n_steps', 'clifford_h', 'clifford_j')
magic_parameters: ClassVar[Tuple[str, ...]] = ('delta_h', 'delta_j', 'delta_z')
property theta_h: float

Total angle of the transverse kicks.

property theta_j: float

Total angle of the couplings.

class mpstab.models.ansatze.QAE(*, transpile: bool = True, native_gates: List | None = <factory>, connectivity: Graph | None = None, n_counting: int = 3, theta_A: float = 0.4)[source]

Bases: _CompiledAnsatz

Canonical Quantum Amplitude Estimation.

n_counting counting qubits + 1 work qubit. State preparation is A = R_Y(2*theta_A) on the work qubit (amplitude a = sin^2(theta_A)). The controlled Grover powers are modelled by controlled phases (CU1) with binary-scaled angles, closed with an inverse QFT on the counting register. nqubits is n_counting + 1.

Parameters:
  • n_counting – Number of counting qubits.

  • theta_A – Angle controlling the amplitude. Default 0.4 rad.

entanglement_parameters: ClassVar[Tuple[str, ...]] = ('n_counting',)
magic_parameters: ClassVar[Tuple[str, ...]] = ('theta_A',)
n_counting: int = 3
nqubits: int
theta_A: float = 0.4
class mpstab.models.ansatze.QFT(nqubits: int, *, transpile: bool = True, native_gates: List | None = <factory>, connectivity: Graph | None = None)[source]

Bases: _CompiledAnsatz

Quantum Fourier Transform (H, controlled-phase and SWAP).

class mpstab.models.ansatze.QFTPhaseKernel(nqubits: int, *, transpile: bool = True, native_gates: List | None = <factory>, connectivity: Graph | None = None, coeffs: ndarray | None = None)[source]

Bases: _CompiledAnsatz

QFT followed by a diagonal RZ phase kernel (no closing inverse QFT).

The trailing RZ layer’s magic rotations get Clifford-backpropagated through the QFT’s H/CU1/SWAP structure – a stronger HSMPO test than a single trailing CZ chain.

Parameters:

coeffs – Per-qubit RZ angles. Default: binary-weighted 2*pi/2^(j+1).

coeffs: ndarray | None = None
magic_parameters: ClassVar[Tuple[str, ...]] = ('coeffs',)
class mpstab.models.ansatze.QPE(*, transpile: bool = True, native_gates: List | None = <factory>, connectivity: Graph | None = None, n_counting: int = 3, phase: float = 0.375)[source]

Bases: _CompiledAnsatz

Quantum Phase Estimation for U = diag(1, e^{2 pi i phase}).

Layout: n_counting counting qubits + 1 eigenstate qubit (prepared in \(|1\rangle\)). Controlled-U^{2^k} is a controlled phase (CU1); the counting register is closed with an inverse QFT. nqubits is derived as n_counting + 1.

Parameters:
  • n_counting – Number of counting qubits.

  • phase – True phase in [0, 1); accuracy ~ 1/2^n_counting.

entanglement_parameters: ClassVar[Tuple[str, ...]] = ('n_counting',)
magic_parameters: ClassVar[Tuple[str, ...]] = ('phase',)
n_counting: int = 3
nqubits: int
phase: float = 0.375
class mpstab.models.ansatze.RampedKickedIsing(nqubits: int, n_steps: int = 1, delta_h: float = 0.1, delta_j: float = 0.0, delta_z: float = 0.0, clifford_h: float = 1.5707963267948966, clifford_j: float = -1.5707963267948966, delta_h_last: float | None = None, delta_z_last: float | None = None, bond_density: float = 1.0, disorder: float = 0.0, seed: int | None = None)[source]

Bases: ParametricKickedIsing

Build a ParametricKickedIsing circuit whose magic changes from step to step.

The deviation of the transverse kicks goes from delta_h at the first step to delta_h_last at the last one, geometrically when the two have the same sign and linearly otherwise; likewise the longitudinal kicks, from delta_z to delta_z_last. With the magic concentrated in the first steps, a head/tail split leaves the large rotations to the head and only small angles to the tail; delta_h < delta_h_last is the opposite profile, as a control. Without delta_h_last and delta_z_last, at bond_density = 1 and disorder = 0, the circuit is exactly ParametricKickedIsing.

Two optional sources of randomness, drawn from numpy.random.RandomState(seed) (from numpy’s global generator when seed is None), in circuit order:

  • disorder > 0 gives every kick its own deviation, \(\delta_h (1 + \mathrm{disorder} \cdot u)\) with \(u\) uniform in \([-1, 1]\), so different seeds are disorder realisations of the same magic profile;

  • bond_density < 1 keeps each coupling of each step with that probability and drops the others. At \(\delta_J = 0\) the couplings are Clifford, so this lowers the entanglement without changing the magic.

No number is drawn when disorder = 0 and bond_density = 1.

The ramp and the disorder add magic knobs to those of ParametricKickedIsing; bond_density adds an entanglement knob.

Parameters:
  • nqubits – number of qubits.

  • n_steps – number of kick-and-couple steps.

  • delta_h – deviation of the transverse kicks at the first step.

  • delta_h_last – deviation of the transverse kicks at the last step (None: delta_h at every step).

  • delta_j – deviation of the \(R_{ZZ}\) couplings from clifford_j.

  • delta_z – angle of the longitudinal kicks at the first step.

  • delta_z_last – angle of the longitudinal kicks at the last step (None: delta_z at every step).

  • clifford_h – Clifford angle of the transverse kicks, a multiple of pi/2.

  • clifford_j – Clifford angle of the couplings, a multiple of pi/2.

  • bond_density – probability of keeping each coupling, in (0, 1].

  • disorder – relative spread of the transverse deviations across the kicks.

  • seed – seed of the random draws.

bond_density: float = 1.0
delta_h_last: float | None = None
delta_z_last: float | None = None
disorder: float = 0.0
entanglement_parameters: ClassVar[Tuple[str, ...]] = ('n_steps', 'clifford_h', 'clifford_j', 'bond_density')
magic_parameters: ClassVar[Tuple[str, ...]] = ('delta_h', 'delta_j', 'delta_z', 'delta_h_last', 'delta_z_last', 'disorder')
seed: int | None = None
class mpstab.models.ansatze.StarKickedIsing(nqubits: int, n_steps: int = 1, delta_h: float = 0.1, delta_j: float = 0.0, delta_z: float = 0.0, clifford_h: float = 1.5707963267948966, clifford_j: float = -1.5707963267948966, delta_h_last: float | None = None, delta_z_last: float | None = None, bond_density: float = 1.0, disorder: float = 0.0, seed: int | None = None)[source]

Bases: RampedKickedIsing

Build a RampedKickedIsing circuit on a star: a central-spin model.

The kicks are those of RampedKickedIsing; the couplings of each step are \(R_{ZZ}\) between the hub (qubit 0) and every leaf, leaf 1 first, each written as CNOT · RZ · CNOT. The hub is an ordinary logical qubit; the label 0 is a convention. The circuit suits devices with a central element, such as an IQM Star: there the compiler can move the hub’s state into the computational resonator once per step and apply all its CZ gates from it, instead of moving a qubit in and out for nearly every CZ as a chain needs (on a 10-qubit IQM Star, 6 steps: about 20 MOVE gates against about 100 for the chain).

Args: as RampedKickedIsing; bond_density applies to the hub-leaf couplings.

class mpstab.models.ansatze.TranspiledAnsatz(*, native_gates: List | None = <factory>, connectivity: Graph | None = None, original_circuit: Circuit)[source]

Bases: _CompiledAnsatz

Any circuit, transpiled into the native gates of a given quantum device presenting a given connectivity.

Parameters:
  • original_circuit – The circuit to be transpiled.

  • native_gates – Optional[List]: list of native gates of the used device. Default is [gates.GPI2, gates.RZ, gates.Z, gates.CZ].

  • connectivity – Optional[nx.Graph]: graph representing the topology of the used device. Default is None and in this case the transpilation does not take into account any connectivity constraint.

nqubits: int
original_circuit: Circuit
transpile: bool = True
class mpstab.models.ansatze.TrotterIsing(nqubits: int, *, transpile: bool = True, native_gates: List | None = <factory>, connectivity: Graph | None = None, n_steps: int = 4, dt: float = 0.2, J: float = 1.0, h: float = 0.5)[source]

Bases: _CompiledAnsatz

First-order Trotter evolution of the 1D transverse-field Ising model.

H = -J sum_j Z_j Z_{j+1} - h sum_j X_j (open boundaries)

Each step applies ZZ rotations (via RZZ) then transverse-field RX rotations, producing a long structured sequence of magic rotations between Cliffords.

Parameters:
  • n_steps – Number of Trotter steps.

  • dt – Time step.

  • J – Coupling strength.

  • h – Transverse field strength.

J: float = 1.0
dt: float = 0.2
entanglement_parameters: ClassVar[Tuple[str, ...]] = ('n_steps', 'dt', 'J')
h: float = 0.5
magic_parameters: ClassVar[Tuple[str, ...]] = ('dt', 'J', 'h')
n_steps: int = 4

Available Ansätze: see Ansatz Catalogue for the full list, with the physical description of each ansatz and the parameters that tune its magic and its entanglement (also exposed as the magic_parameters and entanglement_parameters class attributes).

The circuit-library ansätze (QFT, QFTPhaseKernel, Grover, QPE, QAE, TrotterIsing) are written with high-level gates (CU1, SWAP, TOFFOLI, RZZ, …) and, by default, transpiled to a native gate set on construction so every non-Clifford gate becomes an rz rotation that HSMPO understands — no manual decomposition needed. Pass transpile=False to keep the raw high-level circuit (e.g. for inspection); HSMPO itself requires the transpiled form.

Key Methods:

  • partitionate_circuit(replacement_probability, replacement_method): Partition circuit

  • nparams: Number of circuit parameters

  • circuit: Access the underlying QiboCircuit

Example Usage:

from mpstab.models.ansatze import HardwareEfficient
from mpstab import HSMPO

# Create ansatz
ansatz = HardwareEfficient(nqubits=5, nlayers=3)

# Use with HSMPO
simulator = HSMPO(ansatz=ansatz, max_bond_dimension=32)
result = simulator.expectation("ZZZZZ")

See Using Ansätze for detailed examples.

Entanglement Metrics & Analysis

Tools for analyzing entanglement and state properties.

State metrics: the stabilizer Renyi entropy, a measure of how much magic a state carries, and the Meyer-Wallach global entanglement.

Only the HSMPO estimators live here. For a dense statevector, Qibo already provides both metrics, qibo.quantum_info.stabilizer_renyi_entropy() and qibo.quantum_info.meyer_wallach_entanglement(), and the estimators follow the same conventions so the two can be compared directly.

mpstab.models.metrics.meyer_wallach_mps(hsmpo: HSMPO) → float[source]

Compute the Meyer-Wallach global entanglement of the state an HSMPO represents.

Evaluates the average single-qubit linear entropy

\[Q(\psi) = 2 \left(1 - \frac{1}{n} \sum_{k=0}^{n-1} \mathrm{Tr}\,\rho_k^2\right), \]

with \(\rho_k\) the reduced state of qubit \(k\). The value is 0 for product states and 1 when every qubit is maximally entangled with the rest. For a dense statevector, use qibo.quantum_info.meyer_wallach_entanglement() instead.

The HSMPO state is \(C|\psi_{\mathrm{MPS}}\rangle\), with \(C\) the cached Clifford circuit, so the single-qubit reduced states cannot be read off the MPS sites. The function rebuilds each purity from the qubit’s Bloch vector,

\[\mathrm{Tr}\,\rho_k^2 = \frac{1}{2} \left(1 + \langle X_k\rangle^2 + \langle Y_k\rangle^2 + \langle Z_k\rangle^2\right), \]

which turns \(Q\) into

\[Q = 1 - \frac{1}{n} \sum_{k=0}^{n-1} \sum_{P \in \{X, Y, Z\}} \langle P_k\rangle^2 . \]

It backpropagates every \(\langle P_k\rangle\) through \(C\) and contracts it against the cached MPS. That costs \(3n\) contractions, and the result is exact up to the MPS truncation.

Parameters:

hsmpo – the hybrid stabilizer MPO, with its MPS cache already evolved.

Returns:

The Meyer-Wallach \(Q\) of the circuit’s output state.

mpstab.models.metrics.stabilizer_renyi_entropy_mps(hsmpo: HSMPO, alpha: int = 2, n_samples: int = 1000, seed: int | None = None) → float[source]

Estimate the stabilizer Rényi entropy of the state an HSMPO represents.

Samples n_samples Pauli strings \(P_k\) uniformly from the \(4^n\) of them and replaces the exact Pauli sum with its Monte Carlo estimate,

\[M_\alpha \approx \frac{1}{1 - \alpha} \log_2\left(\frac{4^n}{K} \sum_{k=1}^{K} \frac{|\langle P_k\rangle|^{2\alpha}}{2^n}\right), \]

with \(K\) the number of samples. The estimate of the sum is unbiased; its logarithm is not, and the bias shrinks as \(K\) grows. The result is the total \(M_\alpha\) in bits, the convention of qibo.quantum_info.stabilizer_renyi_entropy() with base=2, which gives the exact value for a dense statevector; divide by hsmpo.nqubits for the entropy per qubit. Each \(\langle P_k\rangle\) is backpropagated through the cached Clifford circuit and contracted against the cached MPS, so the MPS is never rebuilt.

Parameters:
  • hsmpo – the hybrid stabilizer MPO, with its MPS cache already evolved.

  • alpha – Rényi order \(\alpha\), an integer of at least 2.

  • n_samples – number of Pauli strings to sample. More samples lower the variance, but with uniform sampling most strings have a vanishing expectation value, so the relative variance grows exponentially with the number of qubits.

  • seed – seed of the random generator, for reproducible samples.

Returns:

The estimated stabilizer Rényi entropy \(M_\alpha\), in bits.

Raises:

ValueError – if alpha is below 2, or if the estimated Pauli sum is not positive.

Available Functions:

  • stabilizer_renyi_entropy_mps(hsmpo, alpha, n_samples, seed): sampled stabilizer Renyi entropy of the state an HSMPO represents

  • meyer_wallach_mps(hsmpo): Meyer-Wallach global entanglement of the state an HSMPO represents

For a dense statevector, use Qibo’s qibo.quantum_info.stabilizer_renyi_entropy and qibo.quantum_info.meyer_wallach_entanglement; the HSMPO versions follow the same conventions.

Additional Utilities

Circuit transpilation and Clifford-replacement helpers.

mpstab.models.utils.get_closest_angle(old_angle, candidates)[source]

Return the closest angle to old_angle among some candidates.

mpstab.models.utils.hardware_compatible_circuit(circuit: Circuit, native_gates: List | None = (<class 'qibo.gates.gates.GPI2'>, <class 'qibo.gates.gates.RZ'>, <class 'qibo.gates.gates.Z'>, <class 'qibo.gates.gates.CZ'>), connectivity: Graph | None = None) → Circuit[source]

Unroll circuit into native_gates and, given a connectivity graph, place and route it on that topology too.

mpstab.models.utils.replace_non_clifford_gate(gate, replacement_method, candidates=None, rng=None)[source]

Replace a non-Clifford RX/RY/RZ, RXX/RYY/RZZ or GPI2 gate with a Clifford one.

Parameters:
  • gate – the gate to replace.

  • replacement_method – "closest" Clifford angle, or a "random" one.

  • candidates – the Clifford angles to choose from. Defaults to the multiples of pi/2 legal for the gate.

  • rng – source of the "random" draw, such as a seeded random.Random. Defaults to the global random module.

Quick Reference

Class/Function

Purpose

HardwareEfficient

Standard VQA circuit pattern

CircuitAnsatz

Wrap Qibo circuits as ansätze

TranspiledAnsatz

Wrap + transpile to native gates

QFT

Quantum Fourier Transform

QFTPhaseKernel

QFT + diagonal RZ phase kernel

Grover

Grover search

QPE

Quantum Phase Estimation

QAE

Quantum Amplitude Estimation

TrotterIsing

Trotterized transverse-field Ising evolution

meyer_wallach_mps

Meyer-Wallach entanglement of an HSMPO state

stabilizer_renyi_entropy_mps

Sampled stabilizer Renyi entropy of an HSMPO state