A high-performance Python package for pseudo-simulation of Instantaneous Quantum Polynomial (IQP) circuits using Tensor Network, Monte Carlo and BMS sampling.
iqptn is designed for estimating Maximum Mean Discrepancy loss, optimization and large-scale sampling. It leverages quimb for tensor network operations and jax for high-performance, differentiable classical simulations.
iqptn/models.py: CoreIQPTensorNetworkclass and circuit building utilities.iqptn/mmd.py: JAX implementation of MMD loss and Monte Carlo estimators.iqptn/expectation.py: Tools for calculating expectation values via TN contraction and sampling.iqptn/ising_generator.py: Numba-accelerated Ising model sampler for dataset generation.iqptn/euristics.py: Statistical heuristics for kernel parameter selection.
- Python >= 3.10
- JAX
- quimb
- numpy
- numba
git clone https://github.com/your-repo/iqptn.git
cd iqptn
pip install -e .from iqptn.models import IQPTensorNetwork, local_gates
import jax.numpy as jnp
n_qubits = 10
interactions = local_gates(n_qubits, max_weight=2)
params = jnp.zeros(len(interactions))
model = IQPTensorNetwork(n_qubits, interactions)
circuit = model.build_circuit(params)from iqptn.mmd import mmd_mc
import jax
key = jax.random.PRNGKey(42)
ground_truth = jnp.array(...) # Your training data (bitstrings)
loss = mmd_mc(
params=params,
generators=jnp.array(interactions_binary), # Binary matrix of generators
ground_truth=ground_truth,
sigma=1.0,
n_ops=1000, # Number of operators to sample for MMD
n_samples=2048, # Number of MC samples per operator
key=key
)from iqptn.expectation import expvals_sampling
# Estimate Z-type expectations by sampling the TN
ops = jnp.array([[1, 1, 0, ...], [0, 1, 1, ...]]) # Pauli-Z strings
expvals, std_errors = expvals_sampling(circuit, ops, n_samples=1024)The package implements the stochastic approximation levels described in arXiv:2503.02934, specifically:
- Operator Sampling (
n_ops): Approximating the Kernel/Loss space (Eq. 111). - State Sampling (
n_samples): Approximating quantum expectation values via the cosine estimator (Eq. 14).
This project is licensed under the MIT License - see the LICENSE file for details.