OpenFermion是Google主导的量子计算开源软件包,用于编译和分析量子算法来模拟费米子系统,包括量子化学。在其他功能中,当前版本的特征是数据结构和用于获取和操控费米子和量子位哈密顿算符的表示的工具。OpenFermion是生成和编译物理方程式的工具,能够将化学和物质系统描述成可以由量子计算机解释的表征。

核心OpenFermion库是以一种量子编程框架无关的方式设计的,以确保与社区开发的各种平台之间的兼容性。这使得OpenFermion能够支持外部包,而这些包可以为不同的硬件平台编译量子汇编语言规范。我们希望这一决定能够有助于建立OpenFermion成为将量子化学放置于量子计算机上的一个社区标准。要了解OpenFermion是如何与不同的量子编程框架协同使用的,请参阅OpenFermion-ProjectQ和Forest-OpenFermion-plugins——它们可以将OpenFermion与称为ProjectQ和Forest的外部开发的集成电路模拟和编译平台连接在一起。

01 基本资源

论文链接:https://arxiv.org/abs/1710.07629

gitbub:https://github.com/quantumlib/OpenFermion

PyPi包位置:https://pypi.python.org/pypi/openfermion

入门文档:
openfermion.readthedocs.io
https://github.com/quantumlib/OpenFermion/blob/master/README.rst

Demo:
demo1:https://github.com/quantumlib/OpenFermion/blob/master/examples/performance_benchmarks.py
demo2:https://github.com/quantumlib/OpenFermion/blob/master/examples/openfermion_demo.ipynb
demo3:https://github.com/quantumlib/OpenFermion/blob/master/examples/binary_code_transforms_demo.ipynb

操作系统:
OpenFermion支持在Mac和Linux上进行测试,因为电子结构插件仅与Mac和Linux兼容。也可使用docker(https://github.com/quantumlib/OpenFermion/tree/master/docker),Docker安装系统可以在任何操作系统上运行。

依赖插件:

OpenFermion依赖于模块化插件库,以实现重要的功能。具体来说,插件用于模拟和编译量子电路并执行传统的电子结构计算。
电路编译和仿真插件:
OpenFermion-ProjectQ:(http://github.com/quantumlib/OpenFermion-ProjectQ)支持与ProjectQ(https://projectq.ch/)的集成。
Forest-OpenFermion:(https://github.com/rigetticomputing/forestopenfermion)支持与Forest(https://www.rigetti.com/forest)的集成。
电子结构包插件:
OpenFermion-Psi4:(http://github.com/quantumlib/OpenFermion-Psi4)支持与Psi4(http://psicode.org/)的集成(推荐)。
OpenFermion-PySCF:(http://github.com/quantumlib/OpenFermion-PySCF)支持与PySCF(https://github.com/sunqm/pyscf)的集成。

linux下安装:
python2.7/3.4+支持OpenFermion.

开发环境安装:

git clone https://github.com/quantumlib/OpenFermion
cd OpenFermion
python -m pip install -e .

运行环境安装:

python -m pip install --user openfermion

02 demo运行效果

下面是在Ubuntu Desktop X64 1610版本虚拟机中运行效果。
python使用的是系统自带的Python 3.5.2版本。

# 更新系统到最新
sudo apt-get update
sudo apt-get upgrade
python -m pip install --user openfermion

02.01 performance_benchmarks.py运行结果

https://github.com/quantumlib/OpenFermion/blob/master/examples/performance_benchmarks.py

runfile('/home/soft/OpenFermion/examples/performance_benchmarks.py', wdir='/home/soft/OpenFermion/examples')
/home/soft/.local/lib/python3.5/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Starting test on InteractionOperator.jordan_wigner_transform()
InteractionOperator.jordan_wigner_transform() takes 6.709223508834839 seconds on 18 qubits.

Starting test on FermionOperator math and normal ordering.
Math took 0.5400662422180176 seconds. Normal ordering took 0.35562705993652344 seconds.

Starting test on FermionOperator.jordan_wigner_sparse().
Construction of SparseOperator took 5.74668550491333 seconds.
performance_benchmarks.py运行结果

02.02 openfermion_demo.ipynb的部分运行结果

https://github.com/quantumlib/OpenFermion/blob/master/examples/openfermion_demo.ipynb

from openfermion.ops import FermionOperator
from openfermion.hamiltonians import MolecularData
from openfermion.ops import QubitOperator
from openfermion.ops import normal_ordered
from openfermion.utils import commutator, count_qubits, hermitian_conjugated

# Set molecule parameters.
basis = 'sto-3g'
multiplicity = 1
bond_length_interval = 0.1
n_points = 25

# Generate molecule at different bond lengths.
hf_energies = []
fci_energies = []
bond_lengths = []
for point in range(3, n_points + 1):
    bond_length = bond_length_interval * point
    bond_lengths += [bond_length]
    description = str(round(bond_length,2))
    print(description)
    geometry = [('H', (0., 0., 0.)), ('H', (0., 0., bond_length))]
    molecule = MolecularData(
        geometry, basis, multiplicity, description=description)
    
    # Load data.
    molecule.load()

    # Print out some results of calculation.
    print('\nAt bond length of {} angstrom, molecular hydrogen has:'.format(
        bond_length))
    print('Hartree-Fock energy of {} Hartree.'.format(molecule.hf_energy))
    print('MP2 energy of {} Hartree.'.format(molecule.mp2_energy))
    print('FCI energy of {} Hartree.'.format(molecule.fci_energy))
    print('Nuclear repulsion energy between protons is {} Hartree.'.format(
        molecule.nuclear_repulsion))
    for orbital in range(molecule.n_orbitals):
        print('Spatial orbital {} has energy of {} Hartree.'.format(
            orbital, molecule.orbital_energies[orbital]))
    hf_energies += [molecule.hf_energy]
    fci_energies += [molecule.fci_energy]

# Plot.
import matplotlib.pyplot as plt

plt.figure(0)
plt.plot(bond_lengths, fci_energies, 'x-')
plt.plot(bond_lengths, hf_energies, 'o-')
plt.ylabel('Energy in Hartree')
plt.xlabel('Bond length in angstrom')
plt.show()

结果:

...
Spatial orbital 0 has energy of -0.22348569714218677 Hartree.
Spatial orbital 1 has energy of 0.05894803199690316 Hartree.
2.5

At bond length of 2.5 angstrom, molecular hydrogen has:
Hartree-Fock energy of -0.7029435983728299 Hartree.
MP2 energy of -0.8535394695489013 Hartree.
FCI energy of -0.9360549198442759 Hartree.
Nuclear repulsion energy between protons is 0.21167088343600005 Hartree.
Spatial orbital 0 has energy of -0.2144671917818725 Hartree.
Spatial orbital 1 has energy of 0.04995242289757026 Hartree.
performance_benchmarks.py运行结果

如有错误之处,欢迎批评指正。QQ群:579809480。

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐