PyEncode: An Open-Source Library for Structured Quantum State Preparation
Abstract
Quantum algorithms require encoding classical vectors as quantum states, a step known as amplitude encoding. General-purpose routines produce circuits with gates for vectors of length . However, vectors arising in scientific and engineering applications often exhibit mathematical structure that admits far more efficient encoding. Theoretical work over the last decade has established efficient circuits for several structured vector classes, but without open-source implementations. We present \textbf{PyEncode}, an open-source Python library that implements this body of theory in a unified framework. It covers ten exact pattern families: \emph{sparse, step, square, Walsh, Fourier, geometric, Hamming, staircase, Dicke}, and \emph{polynomial}. A function \texttt{encode} maps each pattern to a verified Qiskit circuit, with no vector materialization and no approximation; for example, \texttt{encode(SPARSE([(19, 1.0)]), N=64)} encodes the vector of length . Sparse, step, Walsh, Hamming, and staircase patterns require gates; square and Fourier patterns require ; Dicke states require ; degree- polynomials require . A companion \texttt{predict\_gates} function estimates transpiled gate counts without synthesis. Three composition primitives are supported: \texttt{SUM} for weighted superpositions, \texttt{PARTITION} for ancilla-free composition of disjoint-support patterns, and \texttt{TENSOR} for separable states over disjoint subregisters. For amplitude vectors outside these exact families, PyEncode also provides a matrix product state (MPS) loader, \texttt{encode\_mps}. The library is available at https://github.com/UW-ERSL/PyEncode.
Keywords
Cite
@article{arxiv.2603.28259,
title = {PyEncode: An Open-Source Library for Structured Quantum State Preparation},
author = {Krishnan Suresh and Sanjay Suresh},
journal= {arXiv preprint arXiv:2603.28259},
year = {2026}
}