Skip to main content

Mandacaru logo

License: MIT Python 3.14 PyPI version Documentation Status

Mandacaru

Mandacaru is a Python framework for fermionic quantum simulation with variational quantum algorithms. From an ASE geometry it builds a real-space Hamiltonian, maps it to qubits, and solves it with VQE or ADAPT-VQE on a state-vector simulator or on quantum hardware (IBM Quantum, Amazon Braket).

Installation

pip install mandacaru

No pseudopotential data ships with the package. NCPP, ONCVPSP, PAW-LCAO and UPAW-LCAO each live in their own repository, and an environment variable names the checkout Mandacaru reads from:

basis variable repository
NCPP MANDACARU_NCPP_PATH mandacaru-ncpp
ONCVPSP MANDACARU_ONCVPSP_PATH mandacaru-oncvpsp
PAW-LCAO MANDACARU_PAW_PATH mandacaru-paw
UPAW-LCAO MANDACARU_UPAW_PATH mandacaru-upaw
git clone https://github.com/seixas-research/mandacaru-paw.git
mandacaru --set-paw mandacaru-paw     # writes ~/.zshrc or ~/.bashrc, asking before replacing
mandacaru --pseudo-status             # each variable, where it points, and how many datasets it serves

Datasets sit one directory per exchange-correlation functional inside each checkout (<checkout>/lda/<Symbol>.parquet today). The all-electron bases (HAO, NAO, NAO-AE, the Gaussian families) need none of this. See the pseudopotentials guide for the full setup and the installation guide for the numerical backend and the optional dependencies.

LiH with ASE

from ase import Atoms
from mandacaru import Mandacaru

atoms = Atoms("LiH",
              positions=[[0.0, 0.0, 0.0],           # Li
                         [0.0, 0.0, 1.6]],          # H
              cell=[10.0, 10.0, 10.0])

atoms.calc = Mandacaru(method="adapt-vqe",                   # "vqe" | "adapt-vqe" | "subspace-vqe" | "subspace-adapt-vqe"
                       basis="HAO",                          # Basis set
                       h=0.10,                               # real-space grid spacing (Å)
                       pool="fermionic",                     # "fermionic" | "qubit" | "qeb" | "ceo" | "ceo-ovp"
                       mapping="jordan_wigner",              # "jordan_wigner" | "parity" | "parity_reduced" | "bravyi_kitaev"
                       optimizer={"method": "SLSQP",         # "SLSQP" | "BFGS" | "L-BFGS" | "NLCG-PR" | "COBYLA" | "Nelder-Mead" | "SPSA"
                                  "maxiter": 2000,
                                  "tol": 1e-12},
                       max_iterations=300,                   # at most 300 operators
                       gradient_tolerance=1e-3,              # stop when every pool gradient is smaller
                       device="AER_simulator",               # or an IBM Quantum / Amazon Braket device
                       txt="output.txt")                     # the run log; without it the same blocks are printed

energy = atoms.get_potential_energy()                        # Energy (eV)
print(f"Energy = {energy:.4f} eV")

Potential energy surface

import numpy as np
import pandas as pd
from ase import Atoms
from mandacaru import Mandacaru

distances = np.arange(1.2, 3.101, 0.1)
energies = []
for d in distances:
    atoms = Atoms("LiH",
                  positions=[[0.0, 0.0, 0.0],
                             [0.0, 0.0, d]],
                  cell=[10.0, 10.0, 10.0],
                  magmoms=[1.0, -1.0])

    atoms.calc = Mandacaru(method="adapt-vqe",
                           basis={"name": "PAW-LCAO",
                                  "size": "DZP",
                                  "energy_shift": 0.1},
                           h=0.10,
                           pool="fermionic",
                           mapping="jordan_wigner",
                           optimizer={"method": "SLSQP",
                                      "maxiter": 2000,
                                      "tol": 1e-12},
                           max_iterations=300,
                           gradient_tolerance=1e-4,
                           txt=f"output_{d:.2f}.txt")
    energies.append(atoms.get_potential_energy())

df = pd.DataFrame({"distance": distances, "energy": energies})
df.to_csv("lih_dissociation.csv", index=False)

Theory

VQE. The variational quantum eigensolver prepares a parameterized state |ψ(θ)⟩ = U(θ)|ΦHF⟩ on a quantum processor, measures the energy ⟨ψ(θ)|H|ψ(θ)⟩, and lets a classical optimizer update θ to minimize it. By the variational principle the minimum is an upper bound to the ground-state energy, reached exactly when the ansatz can represent the ground state. Mandacaru starts from the Hartree–Fock determinant in the molecular-orbital basis; the fixed ansatz of method="vqe" is UCCSD.

ADAPT-VQE. ADAPT-VQE builds the ansatz during the calculation instead of fixing it in advance. At each iteration it evaluates the energy gradient ⟨ψ|[H, Ak]|ψ⟩ of every generator Ak in an operator pool, appends exp(θkAk) for the largest one, and re-optimizes all parameters. It stops when every gradient falls below gradient_tolerance, producing compact circuits tailored to the molecule.

Operator pools. The pool is the set of anti-Hermitian generators ADAPT-VQE chooses from, and it sets the trade-off between circuit depth and the number of iterations. fermionic holds spin-adapted single and double excitations; qubit splits them into individual Pauli strings (the shallowest gates, more iterations); qeb uses qubit excitations — the same occupation moves without the fermionic sign; ceo couples the qubit excitations that act on the same spin-orbitals, and ceo-ovp keeps that coupling to one parameter per step, roughly halving the two-qubit gate count of qeb. Every pool is built in the encoding you ask for (Jordan–Wigner, parity, reduced parity or Bravyi–Kitaev) and reaches the same ground state. The fermionic and qubit-excitation pools conserve the particle number; the individual Pauli strings of qubit do not, by design.

Classical optimization. The parameters are updated by the optimizer in optimizer= — a method name, a dict {"method": ..., "maxiter": ..., "tol": ...}. SLSQP (the default), BFGS, L-BFGS and NLCG-PR use gradients and stop in one to two orders of magnitude fewer steps on exact simulators; Nelder–Mead and COBYLA are gradient-free and more robust on a small, nearly-converged problem; SPSA (two energy evaluations per step, whatever the number of parameters) tolerates the statistical noise of shot-based hardware.

Beyond the ground state

Once a state is prepared — by VQE, ADAPT-VQE or a checkpoint loaded back in — Mandacaru can do more with it than report its energy. time_evolve propagates a Pauli Hamiltonian with a matrix-free Suzuki–Trotter product formula; QuantumEchoes applies a weak dipole kick between forward and backward evolution for a spectroscopy-style response; NestedOTOC evaluates the nested out-of-time-order correlator ⟨[B(t)M]2k⟩ of repeated echoes with Pauli insertions B and M; and QuantumPhaseEstimation reads the energy of a prepared state off a phase-estimation register. See the quantum echoes and checkpoints and QPE guides.

License

Mandacaru is released under the MIT License.

Developer: Leandro Seixas Rocha (leandro.rocha@ilum.cnpem.br).

Documentation: mandacaru.readthedocs.io.

We thank financial support from INCT Materials Informatics (Grant No. 406447/2022-5).

Release files for mandacaru 26.9.49

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mandacaru 26.9.49
File Size Uploaded
mandacaru-26.9.49.tar.gz 5.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for mandacaru 26.9.49
File Interpreter ABI Platform
mandacaru-26.9.49-py3-none-any.whl Python 3 none any Details

Total release size: 6.1 MB

Release files / mandacaru-26.9.49.tar.gz

Download URL mandacaru-26.9.49.tar.gz
Size 5.3 MB
Tags Source
SHA-256 checksum
How to use checksums
c6b7af11ff903262380d4c9d8f51f106628ece456c165729f92c561cc6d5fa67
BLAKE2b-256 checksum
How to use checksums
f7bde0eff7a7d71f26ef8f1b7eb1ba210f9a795443ecc45a404f7cfa49ee4c4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / mandacaru-26.9.49-py3-none-any.whl

Download URL mandacaru-26.9.49-py3-none-any.whl
Size 813.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
600b5092cac320b9bde79fc8b82e67cdf1216ebb97e92072e9ebbd3593f3eaeb
BLAKE2b-256 checksum
How to use checksums
7825225e2ff8e054cd4c43151f40e79d76fbb19d7d48b0b2b8cebe7e85930fc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page