Skip to main content

A framework for fermionic quantum simulation based on variational quantum algorithms.

Project description

Carcará logo

License: MIT PyPI

Carcará

Carcará is a framework for fermionic quantum simulation based on variational quantum algorithms, engineered from the ground up for deployment on real quantum hardware.

Overview

Carcará connects theoretical condensed matter physics with NISQ-era quantum hardware. Engineered around variational workflows, the framework streamlines the pipeline from mapping complex fermionic Hamiltonians onto qubit operators to optimizing ansatz states and executing error-mitigated circuits on real quantum backends.

Key Features

  • Fermion-to-Qubit Mapping: Built-in, optimized transformations including Jordan-Wigner, Bravyi-Kitaev, and parity mappings to translate fermionic creation/annihilation operators into Pauli strings.

  • Hardware-Efficient & Physics-Inspired Ansatzes: Ready-to-use ansatz generation, including Unitary Coupled Cluster (UCCSD) and hardware-efficient templates designed to minimize circuit depth and gate errors on real QPUs.

  • Hybrid Variational Solvers: Robust implementation of the Variational Quantum Eigensolver (VQE) and its time-dependent variants, coupled with state-of-the-art classical optimizers (e.g., SPSA, COBYLA, SLSQP).

  • Real Hardware Deployment: Seamless integration with major quantum cloud providers (IBM Quantum Platform) with native support.

  • Advanced Error Mitigation: Built-in noise-resilient pipelines featuring Zero-Noise Extrapolation (ZNE) and symmetry verification.

Installation

From pip

The easiest way to install Carcará is with pip:

pip install carcara

From github

To install Carcará directly from the GitHub repository, run the following commands:

git clone https://github.com/seixas-research/carcara.git
cd carcara
pip install -e .

Getting started

One- and two-body integrals for H2

The carcara.integrals module computes real-space one- and two-body integrals over any localized basis. The example below builds a minimal basis of one hydrogen 1s orbital on each proton and evaluates the core Hamiltonian and the electron-repulsion tensor. The full script lives in examples/h2_integrals.py.

import numpy as np

from carcara.basis import HydrogenicOrbital
from carcara.integrals import Grid, IntegralEngine

# Geometry (atomic units): two protons at the H2 equilibrium bond length.
Z, R = 1.0, 1.4
nuclei = np.array([[0.0, 0.0, -R / 2], [0.0, 0.0, +R / 2]])

def nuclear_potential(x, y, z):
    v = np.zeros_like(x, dtype=float)
    for Rx, Ry, Rz in nuclei:
        r = np.sqrt((x - Rx) ** 2 + (y - Ry) ** 2 + (z - Rz) ** 2)
        v -= Z / np.maximum(r, 1e-12)
    return v

grid = Grid(center=[0.0, 0.0, 0.0], box_size=10.0, points=64)
basis = [HydrogenicOrbital(1, 0, 0, Z=Z, center=nuclei[0]),
         HydrogenicOrbital(1, 0, 0, Z=Z, center=nuclei[1])]

engine = IntegralEngine(basis, grid)

# One-body: kinetic T and nuclear attraction V -> core Hamiltonian.
T, V = engine.one_body(nuclear_potential)
h_core = T + V

# Two-body electron-repulsion tensor (ab|cd) in chemists' notation.
eri = engine.two_body(method="fft")

print("Core Hamiltonian h = T + V (Ha):")
print(h_core.real)
print(f"(00|00) on-site repulsion = {eri[0, 0, 0, 0].real:.4f} Ha")

Running it prints the 2 x 2 core Hamiltonian and the on-site repulsion (00|00) ~ 0.62 Ha, in agreement with the exact hydrogen 1s value of 5/8 Ha.

A heteronuclear molecule: LiH

The same machinery scales to multi-orbital, heteronuclear systems. The example examples/lih_integrals.py builds a small minimal basis for LiH -- the Li 1s, 2s and 2p_z orbitals plus the H 1s -- using the true nuclear charges (Z_Li = 3, Z_H = 1) in the potential and effective (Slater) charges for the hydrogenic basis orbitals:

labels = ["Li 1s", "Li 2s", "Li 2pz", "H 1s"]
basis = [HydrogenicOrbital(1, 0, 0, Z=2.69, center=li_pos),   # Li 1s core
         HydrogenicOrbital(2, 0, 0, Z=1.28, center=li_pos),   # Li 2s valence
         HydrogenicOrbital(2, 1, 0, Z=1.28, center=li_pos),   # Li 2pz valence
         HydrogenicOrbital(1, 0, 0, Z=1.00, center=h_pos)]    # H 1s

engine = IntegralEngine(basis, grid)
T, V = engine.one_body(nuclear_potential)
eri = engine.two_body(method="fft")

This yields the 4 x 4 one-body matrices and the 4 x 4 x 4 x 4 electron-repulsion tensor. The H 1s on-site integral (33|33) ~ 0.62 Ha again recovers the exact 5/8 Ha.

License

This is an open source code under MIT License.

Acknowledgements

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

carcara-26.7.3.tar.gz (2.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

carcara-26.7.3-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

File details

Details for the file carcara-26.7.3.tar.gz.

File metadata

  • Download URL: carcara-26.7.3.tar.gz
  • Upload date:
  • Size: 2.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for carcara-26.7.3.tar.gz
Algorithm Hash digest
SHA256 dc21b03f3e0d320e4a795caefcdf3211a29b7c5e7b2c5d6de521df9498f969a5
MD5 e0d317d549ca6faf3d233eb303a6c760
BLAKE2b-256 5a248c2770ea4d3e01db9cb5e52ae7df78d81030e2106d1d86cbe0c9b6c2364d

See more details on using hashes here.

File details

Details for the file carcara-26.7.3-py3-none-any.whl.

File metadata

  • Download URL: carcara-26.7.3-py3-none-any.whl
  • Upload date:
  • Size: 28.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for carcara-26.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 34d61bb7e091d8807f09291df1d0962dc521a59c02ba906e4b8ab1ffa088d5b3
MD5 715842e6f3d0784a7761626723ce3368
BLAKE2b-256 3e7f389136cb49cc990474be273c987afedfad9c07d911d44326e30db52a732e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page