ffsim¶
ffsim is a software library for simulating fermionic quantum circuits that conserve particle number and the Z component of spin. This category includes many quantum circuits used for quantum chemistry simulations. By exploiting the symmetries and using specialized algorithms, ffsim can simulate these circuits much faster than a generic quantum circuit simulator.
Installation¶
We recommend installing ffsim using pip when possible:
pip install ffsim
This method won’t work natively on Windows, however. Refer to the installation instructions for information about using ffsim on Windows, as well as instructions for installing from source and running ffsim in a container.
Code example¶
import numpy as np
import pyscf
import ffsim
# Generate the Hamiltonian for an N2 molecule using PySCF and ffsim's wrapper for it
mol = pyscf.gto.Mole()
mol.build(atom=[["N", (0, 0, 0)], ["N", (1.0, 0, 0)]], basis="6-31g", symmetry="Dooh")
scf = pyscf.scf.RHF(mol).run()
mol_data = ffsim.MolecularData.from_scf(scf, active_space=range(4, mol.nao_nr()))
norb, nelec = mol_data.norb, mol_data.nelec
hamiltonian = mol_data.hamiltonian
# Convert the Hamiltonian to a SciPy LinearOperator
linop = ffsim.linear_operator(hamiltonian, norb=norb, nelec=nelec)
# Generate a random orbital rotation
orbital_rotation = ffsim.random.random_unitary(norb, seed=1234)
# Create the Hartree-Fock state and apply the orbital rotation to it
vec = ffsim.hartree_fock_state(norb, nelec)
vec = ffsim.apply_orbital_rotation(vec, orbital_rotation, norb=norb, nelec=nelec)
# Compute the energy of the state
energy = np.vdot(vec, linop @ vec).real
print(energy) # prints -104.17181289596
Citing ffsim¶
You can cite ffsim using the following BibTeX:
@misc{ffsim,
author = {{The ffsim developers}},
title = {ffsim: Faster simulations of fermionic quantum circuits},
howpublished = {\url{https://github.com/qiskit-community/ffsim}},
}
Contents¶
- Installation
- Tutorials
- Explanations
- How-to guides
- How to simulate the local unitary cluster Jastrow (LUCJ) ansatz
- How to simulate Trotterized time evolution for the molecular Hamiltonian
- How to simulate Trotterized time evolution for the Fermi-Hubbard model
- How to simulate entanglement forging
- How to use the FermionOperator class
- How to build Qiskit circuits for the LUCJ ansatz
- How to build Qiskit circuits for Trotterized Hamiltonian simulation
- How to simulate excitation-preserving Qiskit circuits
- How to merge orbital rotations in Qiskit circuits
- API reference
- GitHub
- Developer guide
- Release notes
- Development branch docs