qSWIFT is a Python package that implements a higher-order randomized algorithm for quantum simulation. It is designed to efficiently compute Hamiltonian dynamics with improved error bounds. The algorithm is based on the research presented in the paper: arXiv:2302.14811. Please cite the paper, when you utilize this package.
We test our code using Python 3.8.5. The package can be installed via pip directly from the GitHub repository. It relies on other packages that are part of the project suite, specifically qwrapper and benchmark, which are also available on GitHub.
Follow the steps below to install qSWIFT and its dependencies:
pip install git+ssh://[email protected]/konakaji/qswift.git
You can also directly work in this package. In that case, run the following in the project root.
pip install -r requirements.txt
After installation, you can use qSWIFT to simulate quantum systems as per the paper's algorithm. Here's a simple example to get you started (you can also check the sample code in https://github.com/konakaji/qswift/blob/master/h.py ):
Prepare the Hamiltonian for the time evolution:
from qwrapper.obs import PauliObservable
from qwrapper.hamiltonian import Hamiltonian
hamiltonian = Hamiltonian([0.2, 0.4], PauliObservable("XX"), PauliObservable("YY"))
We can also use the pre-defined Hamiltonian:
from benchmark.molecule import MolecularHamiltonian
hamiltonian = MolecularHamiltonian(8, "6-31g", "hydrogen")
from qwrapper.obs import PauliObservable
from qwrapper.hamiltonian import Hamiltonian
obs = Hamiltonian([1, 1], [PauliObservable("ZIIIIIII"), PauliObservable("ZZIIIIII")], 8)
Define the initializer of the quantum circuit:
from qswift.initializer import XBasisInitializer
initializer = XBasisInitializer() # Initialize all qubits in X-basis (other than ancilla qubit).
from qswift.qswift import QSwift
qswift = QSwift(obs, initializer, t=t, N=N, K=2, nshot=0, n_p=10000, tool="qulacs")
result = qswift.evaluate(hamiltonian)
- t: the evolution time
- N: the number of Pauli time evolution gates.
- K: the order parameter
- nshot: # of samples for each circuit generated. When nshot = 0, we use the state vector simulator.
- n_p: # of samples for each order.
- tool: qiskit or qulacs.
result.sum(i)
returns the i-th order calculation result.
print(result.sum(0), result.sum(1), result.sum(2))
- We plan to extend the code so that the evolution Hamiltonian can be a sum of arbitrary operators.
- We plan to add the feature for tuning the number of samples for each order.