Skip to content

Commit

Permalink
simple example
Browse files Browse the repository at this point in the history
  • Loading branch information
JProvazza committed Feb 5, 2024
1 parent f8f0771 commit 0e87cbb
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
16 changes: 2 additions & 14 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# MPS-FQE Examples

- fqe_to_mps.py
- Calculates the expectation value of a sparse operator with FQE and MPS-FQE with bra = ket and bra != ket.
- N2_asp.py
- Performs adiabatic state preparation on N<sub>2</sub> in a minimal basis performed with exact statevector evolution and TD-DMRG under truncated bond dimension.
- N2_imag.py
Expand All @@ -9,20 +11,6 @@
- adapt.py
- Performs an ADAPT-VQE simulation on a 4-member Hydrogen chain under truncated bond dimension using RK4 propagation.


## Collaborators
__QSimulate__:\
Alec F. White, Justin Provazza, Klaas Gunst

__Google__:\
Nicholas C. Rubin

__California Institute of Technology__:\
Huanchen Zhai

## How to cite
When using MPS-FQE for research projects, please cite:

```
@article{mps_fqe_2023,
author = {Justin Provazza, Klaas Gunst, Huanchen Zhai, Garnet K.-L. Chan,
Expand Down
45 changes: 45 additions & 0 deletions examples/fqe_to_mps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import fqe
from openfermion import FermionOperator
from openfermion.utils import hermitian_conjugated
from mps_fqe.wavefunction import MPSWavefunction


if __name__ == '__main__':
# System parameters
nele = 4
sz = 0
norbs = 4
# MPS parameters
mbd = 20
cutoff = 1e-14

# Generate random FQE wavefunction instance
fqe_wfn = fqe.Wavefunction([[nele, sz, norbs]])
fqe_wfn.set_wfn(strategy="random")
# Generate MPS-FQE wavefunction instance from FQE wavefunction
mps_wfn = MPSWavefunction.from_fqe_wavefunction(fqe_wfn,
max_bond_dim=mbd,
cutoff=cutoff)

# Generate Openfermion operator
of_operator = FermionOperator("1^ 3")
of_operator += hermitian_conjugated(of_operator)
# Use it to generate FQE operator
fqe_operator = fqe.sparse_hamiltonian.SparseHamiltonian(of_operator)

# Expectation value
print("<psi|o|psi>:\nFQE:{}\nMPS-FQE:{}".format(
fqe_wfn.expectationValue(fqe_operator),
mps_wfn.expectationValue(fqe_operator))
)

fqe_wfn_evolved = fqe_wfn.time_evolve(1, fqe_operator)
mps_wfn_evolved = mps_wfn.time_evolve(1, fqe_operator)

# Bra state not equal to ket state
print("<psi|o exp(-i o)|psi>:\nFQE:{}\nMPS-FQE:{}".format(
fqe_wfn_evolved.expectationValue(fqe_operator,
brawfn=fqe_wfn),
mps_wfn_evolved.expectationValue(fqe_operator,
brawfn=mps_wfn))
)

0 comments on commit 0e87cbb

Please sign in to comment.