API Reference
This page documents the public modules, classes, and functions of the Carcará package.
Algorithms & Drivers
Basis Sets
Integral Engine
Fermionic Operators & Mappings
Quantum Circuits & Ansätze
Classical Optimizers
Hamiltonian Serialization
The on-disk qubit-Hamiltonian cache (Apache Parquet or JSON) that lets a run skip the integrals and the fermion-to-qubit mapping entirely. See Caching the Hamiltonian (Parquet / JSON).
Backends: Devices & Circuit Providers
Device Registry
Which machine a run executes on – the ideal simulator, or an Amazon Braket simulator or QPU. See Running on Amazon Braket (and real QPUs).
Execution devices for the variational loop.
Carcará computes energies on an exact state-vector backend today; this module
is the small registry that lets the user name the device an
ADAPTVQE should run on, so the same driver can later
dispatch to a shot-based simulator or real quantum hardware without changing its
public API.
Supported names
"AER_simulator"The default: an ideal (noiseless) simulator. In the current build this is the exact state-vector backend; it is the device used by the tests and examples.
"ibm-quantum"Real IBM Quantum hardware (via Qiskit Runtime). Reserved – the dispatch is not implemented yet; naming it is accepted so code can be written against the final API, but running raises
NotImplementedError."braket-local"Amazon Braket’s local state-vector simulator, driven by
BraketProvider."braket-sv1"/"braket-dm1"/"braket-tn1"Amazon Braket’s managed on-demand simulators, run through the AWS service. Runnable, billed to your AWS account.
"braket-ionq-aria"/"braket-ionq-forte"/"braket-iqm-garnet"/"braket-rigetti-ankaa"Real QPUs on Amazon Braket. Runnable via
BraketProviderwithshots > 0– seedevice_arn()andcarcara.backends.measurement.
Any string starting with arn:aws:braket is also accepted verbatim, so a
device that post-dates this release can still be named.
- carcara.backends.hardware.AWS_ARN_PREFIX = 'arn:aws:braket'
Prefix identifying an Amazon Braket device ARN.
- class carcara.backends.hardware.Device(name: str, simulator: bool, runnable: bool, provider: str | None, arn: str | None = None, description: str = '')[source]
Bases:
objectOne entry of the device registry.
- arn: str | None = None
- description: str = ''
- property is_aws: bool
- name: str
- provider: str | None
- runnable: bool
- simulator: bool
- carcara.backends.hardware.available_devices() list[str][source]
Canonical device names understood by
normalize_device().
- carcara.backends.hardware.describe_devices() list[Device][source]
The full registry, for listing what a build can target.
- carcara.backends.hardware.device_arn(name: str) str | None[source]
The Amazon Braket ARN of
name, orNoneif it is not an AWS device.
- carcara.backends.hardware.device_provider(name: str) str | None[source]
The circuit provider that drives
name(None= the internal one).
- carcara.backends.hardware.get_device(name: str) Device[source]
The
Devicerecord forname(synthesized for unknown ARNs).
- carcara.backends.hardware.is_aws_device(name: str) bool[source]
True when the device runs through the Amazon Braket service.
- carcara.backends.hardware.is_simulator(name: str) bool[source]
True when the (normalized) device is a classically simulable simulator.
- carcara.backends.hardware.normalize_device(name: str) str[source]
Resolve a device name/alias to its canonical form.
A raw Amazon Braket ARN is returned unchanged (mapped to its registered name when it is one this build knows), so devices added by AWS after this release can still be named.
- Raises:
ValueError – If
nameis not a known device.
Circuit Providers
Which SDK builds and executes the ansatz circuits – Qiskit, Amazon Braket or Cirq. See Backend Providers: Qiskit, Braket and Cirq.
Shot-Based Measurement
Estimating \(\langle H \rangle\) from measurement shots via qubit-wise commuting Pauli groups – the protocol a real QPU requires.
Utilities & Profiling
Utilities (structured logging, …).
- class carcara.utils.AdaptOutputLogger(path: str = 'output.txt')[source]
Bases:
objectAppend-only writer for the ADAPT-VQE
output.txtprotocol.- Parameters:
path (str) – Destination file (overwritten at construction;
"output.txt"by convention).
- write_iteration(iteration: int, pool_operators: Sequence, gradients: Iterable[float], selected_index: int, expressivity: float | None, energy: float, num_parameters: int, energy_unit: str = 'eV', metrics: Any = None) None[source]
Append one ADAPT iteration’s tracked metrics, in order.
The selected operator is reported in its own block, clearly separate from the full operator pool listing that follows it.
- Parameters:
iteration (int) – 1-based macro-iteration index.
pool_operators (sequence of PoolOperator) – The full operator pool at this step.
gradients (iterable of float) – Screening gradient of each pool operator (same order as
pool_operators); their magnitudes are logged.selected_index (int) – Index (into
pool_operators) of the operator chosen for the ansatz.expressivity (float or None) – Expressivity score \(E\) of the parameterized ansatz at this iteration (
Noneif not computed).energy (float) – Energy after the inner re-optimization, in
energy_unit.num_parameters (int) – Number of parameters (operators) in the ansatz after this step.
energy_unit (str) – Unit label for
energy(default"eV").metrics (optional) – Object exposing
cnot_count/depth/total_gates(logged if present).
- write_metadata(symbols: Sequence[str] | None = None, positions=None, cell=None, units: str = 'Angstrom', title: str = 'ADAPT-VQE run', extra: dict | None = None) None[source]
Write the initial geometry and the explicit unit-cell parameters.
- Parameters:
symbols (sequence of str, optional) – Chemical symbols, one per atom.
positions ((N, 3) array_like, optional) – Cartesian coordinates in
units.cell ((3, 3) array_like, optional) – Lattice/cell tensor (rows are lattice vectors) in
units.None(or an all-zero matrix) means a non-periodic molecule.units (str) – Length unit label for the geometry and cell.
title (str) – Header title.
extra (dict, optional) – Additional
KEY: valuemetadata lines.
- write_optimizer_setup(optimizer_method: str, reference_energy: float, energy_unit: str = 'eV', gradient_tol: float | None = None, max_iterations: int | None = None, extra: dict | None = None) None[source]
Write the classical optimizer and the pre-loop (reference) results.
The final classical ansatz optimization result leading into the VQE runtime is, before the first operator is added, the Hartree-Fock reference energy of the empty ansatz – logged here as the loop’s starting point.
- write_summary(converged: bool, optimal_energy: float, num_operators: int, energy_unit: str = 'eV', reference_energy: float | None = None, correlation_energy: float | None = None, num_parameters: int | None = None, final_max_gradient: float | None = None, expressivity: float | None = None, num_evaluations: int | None = None, metrics: Any = None, optimizer: str | None = None, operator_sequence: Sequence[str] | None = None, extra: dict | None = None) None[source]
Write the closing summary block: the final parameterization in full.
Records the converged energy, the final ansatz size (operators / parameters), its expressivity, and the compiled-circuit cost (CNOTs, single-qubit gates, total gates, depth), plus the classical-optimizer effort – everything describing the final variational state.
- class carcara.utils.Timings(n_cores: int | None = None, backend: str | None = None)[source]
Bases:
objectOrdered accumulator of named stage wall-times, with memory/core context.
Use
time()as a context manager to time a stage (accumulating across repeated calls), oradd()to fold in an externally measured duration.peak_memory_mbandn_corescapture the resource context for the summary.- add(name: str, seconds: float) None[source]
Fold
secondsinto stagenameand refresh the memory peak.
- format_report(indent: str = ' ', width: int = 30) str[source]
Multi-line report of stage times, cores and peak memory.
- merge(other: Timings, prefix: str = '') None[source]
Merge another
Timings’ stages (optionally name-prefixed).
- property peak_memory_mb: float
- property total: float
- carcara.utils.backend_cores() int | None[source]
OpenMP thread count of the C integral backend, or
None(NumPy path).
- carcara.utils.parse_output(path: str) dict[source]
Reference parser for an ADAPT
output.txt(used by the tests).Scans the file line by line and returns a dict with the metadata, the optimization setup, and a list of per-iteration records – demonstrating that the protocol is machine-parseable as it is written.