Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 24c8857

Browse files
authored
Models module (#51)
* creating hamiltonian module * before testing * tests passing * all tests passing * fixed docs * docker readme, version number * addressed Jarrod's comments * minor change to readme * changed ops init
1 parent d5f0d00 commit 24c8857

41 files changed

Lines changed: 569 additions & 542 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ as well as our detailed `code documentation <http://openfermion.readthedocs.io/e
3434
Developer install
3535
-----------------
3636

37-
To install the latest version of OpenFermion in development mode:
37+
To install the latest version of OpenFermion (in development mode):
3838

3939
.. code-block:: bash
4040

docker/README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ necessary applications needed for running these programs. To run the image, use
105105
and the terminal enters a new environment which emulates a Ubuntu OS with
106106
OpenFermion and accessories installed, regardless of what the host OS is. This
107107
new environment is a running process called a Docker container. To check info
108-
on the container, one can open another terminal, configure it using
108+
on the container, one can open another terminal, configure it using
109109
`docker-machine env` as mentioned before, and run
110110

111111
```
@@ -135,12 +135,11 @@ container, run in a separate terminal from the one running the container
135135
where container name can be gleaned according to the step above.
136136

137137
An alternative way of loading files onto the Docker container is through
138-
remote repos such as Github or BitBucket. git is installed in the Docker image.
138+
remote repos such as Github or BitBucket. git is installed in the Docker image.
139139
After `docker run`, one could run "git clone ..." etc to pull files
140-
remotely into the Docker container.
141-
142-
There are occasions where one might want to open up multiple terminals to
143-
run the same Docker container. In that case, one could run in any terminal
140+
remotely into the Docker container. There are occasions where one might want
141+
to open up multiple terminals to run the same Docker container.
142+
In that case, one could run in any terminal
144143

145144
```
146145
docker exec -it [container name] bash
@@ -160,7 +159,7 @@ backend, first check the ip address of the virtual machine by running
160159
where "default" can be replaced by the name of whichever virtual machine whose
161160
ip address you want to check.
162161

163-
Assuming the Docker image for OpenFermion is already built and is called
162+
Assuming the Docker image for OpenFermion is already built and is called
164163
openfermion_docker, run the container with an additional -p flag:
165164

166165

@@ -179,7 +178,7 @@ When the terminal enters the Docker container, run Jupyter notebook by
179178
```
180179

181180
where 8888 is the port number used previously for setting up the container.
182-
The message returned to the terminal should end with a statement that says
181+
The message returned to the terminal should end with a statement that says
183182
something like:
184183
```
185184
Copy/paste this URL into your browser when you connect for the first time,
@@ -188,7 +187,7 @@ to login with a token:
188187
```
189188

190189
Note the token string 8f70c035fb9b0dbbf160d996f7f341fecf94c9aedc7cfaf7.
191-
Open a browser window and type in the address line
190+
Open a browser and type in the address line
192191

193192
```
194193
[virtual machine ip]:8888
@@ -197,5 +196,5 @@ Open a browser window and type in the address line
197196
where [virtual machine ip] is extracted from `docker-machine ip` and 8888 is the port
198197
number (or any other port number that one specifies previously). A webpage
199198
asking for token string should appear. Use the token string obtained from before to
200-
enter Jupyter Notebook. If logged in successfully, you should be able to freely
199+
enter Jupyter Notebook. If logged in successfully, you should be able to freely
201200
navigate through the entire Docker image and launch any Jupyter notebook in the image.

docs/examples.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,13 @@ We see that despite the different representation, these operators are iso-spectr
135135
Sparse matrices and the Hubbard model
136136
-------------------------------------
137137

138-
Often, one would like to obtain a sparse matrix representation of an operator which can be analyzed numerically. There is code in both openfermion.transforms and openfermion.utils which facilitates this. The function get_sparse_operator converts either a FermionOperator, a QubitOperator or other more advanced classes such as InteractionOperator to a scipy.sparse.csc matrix. There are numerous functions in openfermion.utils which one can call on the sparse operators such as "get_gap", "get_hartree_fock_state", "get_ground_state", ect. We show this off by computing the ground state energy of the Hubbard model. To do that, we use code from the openfermion.utils module which constructs lattice models of fermions such as Hubbard models.
138+
Often, one would like to obtain a sparse matrix representation of an operator which can be analyzed numerically. There is code in both openfermion.transforms and openfermion.utils which facilitates this. The function get_sparse_operator converts either a FermionOperator, a QubitOperator or other more advanced classes such as InteractionOperator to a scipy.sparse.csc matrix. There are numerous functions in openfermion.utils which one can call on the sparse operators such as "get_gap", "get_hartree_fock_state", "get_ground_state", ect. We show this off by computing the ground state energy of the Hubbard model. To do that, we use code from the openfermion.hamiltonians module which constructs lattice models of fermions such as Hubbard models.
139139

140140
.. code-block:: python
141141
142+
from openfermion.hamiltonians import fermi_hubbard
142143
from openfermion.transforms import get_sparse_operator, jordan_wigner
143-
from openfermion.utils import fermi_hubbard, get_ground_state
144+
from openfermion.utils import get_ground_state
144145
145146
# Set model.
146147
x_dimension = 2
@@ -183,7 +184,7 @@ Basis functions are provided to initialization using a string such as "6-31g". G
183184

184185
.. code-block:: python
185186
186-
from openfermion.utils import MolecularData
187+
from openfermion.hamiltonians import MolecularData
187188
188189
# Set parameters to make a simple molecule.
189190
diatomic_bond_length = .7414
@@ -260,8 +261,9 @@ Below, we load MolecularData from a saved calculation of LiH. We then obtain an
260261

261262
.. code-block:: python
262263
264+
from openfermion.hamiltonians import MolecularData
263265
from openfermion.transforms import get_fermion_operator, get_sparse_operator, jordan_wigner
264-
from openfermion.utils import get_ground_state, MolecularData
266+
from openfermion.utils import get_ground_state
265267
import numpy
266268
import scipy
267269
import scipy.linalg

docs/index.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ Welcome to the docs
44
===================
55

66
Contents
7-
* :ref:`intro`: Introduction & Installation
8-
* :ref:`examples`: Code examples
9-
* :ref:`codedoc`: The code documentation of openfermion.
7+
* :ref:`intro`: Introduction & Installation
8+
* :ref:`examples`: Code examples
9+
* :ref:`codedoc`: The code documentation of openfermion.
1010

1111
.. toctree::
12-
:maxdepth: 2
13-
:hidden:
12+
:maxdepth: 2
13+
:hidden:
1414

15-
intro
16-
examples
17-
openfermion
15+
intro
16+
examples
17+
openfermion
1818

docs/openfermion.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
Code Documentation
44
==================
55

6+
openfermion.hamiltonians
7+
--------------
8+
.. automodule:: openfermion.hamiltonians
9+
:members:
10+
:special-members: __init__
11+
:imported-members:
12+
613
openfermion.measurements
714
--------------
815

examples/givens_rotations.ipynb

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
"name": "stdout",
5555
"output_type": "stream",
5656
"text": [
57-
"[[-0.311+0.062j -0.403-0.276j 0.097-0.412j 0.237-0.295j 0.091-0.504j 0.236-0.145j]\n",
58-
" [-0.289-0.156j -0.113+0.033j 0.262+0.525j -0.207+0.253j -0.212-0.122j 0.365-0.484j]\n",
59-
" [-0.330-0.72j -0.018-0.099j -0.236-0.182j -0.185+0.005j -0.015+0.025j -0.460-0.164j]]\n"
57+
"[[-0.134+0.446j 0.018+0.271j 0.703+0.294j 0.025-0.198j -0.074+0.061j 0.267-0.091j]\n",
58+
" [ 0.336+0.267j -0.441-0.245j -0.077-0.02j 0.343+0.422j 0.083+0.215j 0.434-0.131j]\n",
59+
" [-0.395-0.103j 0.001-0.253j -0.215-0.216j -0.058-0.47j -0.138+0.258j 0.462-0.392j]]\n"
6060
]
6161
}
6262
],
@@ -92,11 +92,11 @@
9292
"name": "stdout",
9393
"output_type": "stream",
9494
"text": [
95-
"[[ 0.240-0.126j -0.439-0.47j -0.689+0.195j]\n",
96-
" [ 0.900+0.065j -0.208+0.072j 0.357-0.101j]\n",
97-
" [ 0.335+0.j 0.683+0.268j -0.371+0.461j]]\n",
98-
"\n",
99-
"[ 0.457+0.889j -0.916-0.4j 0.970-0.242j]\n"
95+
"[[ 0.912+0.068j -0.077+0.112j -0.297-0.239j]\n",
96+
" [ 0.181-0.096j -0.806-0.128j 0.420+0.339j]\n",
97+
" [ 0.349+0.j 0.561-0.019j 0.698+0.276j]]\n",
98+
"()\n",
99+
"[-0.209+0.978j -0.714-0.7j -0.645+0.764j]\n"
100100
]
101101
}
102102
],
@@ -124,11 +124,11 @@
124124
"name": "stdout",
125125
"output_type": "stream",
126126
"text": [
127-
"('2, 3, 0.671, -2.644',)\n",
128-
"('1, 2, 1.421, 0.281', '3, 4, 1.401, -1.617')\n",
129-
"('0, 1, 0.683, -2.284', '2, 3, 0.704, 2.724', '4, 5, 1.204, 2.049')\n",
130-
"('1, 2, 0.800, -2.721', '3, 4, 1.412, -2.494')\n",
131-
"('2, 3, 1.112, -3.003',)\n"
127+
"('2, 3, 0.172, -0.438',)\n",
128+
"('1, 2, 1.212, 2.149', '3, 4, 0.313, 1.750')\n",
129+
"('0, 1, 0.986, 2.937', '2, 3, 1.062, 1.518', '4, 5, 1.106, 2.647')\n",
130+
"('1, 2, 0.945, -0.406', '3, 4, 1.190, -0.769')\n",
131+
"('2, 3, 1.339, -1.335',)\n"
132132
]
133133
}
134134
],
@@ -170,9 +170,9 @@
170170
"name": "stdout",
171171
"output_type": "stream",
172172
"text": [
173-
"[[ 0.355+0.69j -0.035+0.087j 0.301-0.385j 0.356-0.154j 0.000+0.j 0.000+0.j ]\n",
174-
" [-0.403-0.176j -0.340-0.323j -0.081-0.496j 0.192-0.297j 0.165-0.427j 0.000-0.j ]\n",
175-
" [ 0.194-0.048j -0.169-0.072j 0.242+0.25j -0.064-0.069j -0.088-0.325j 0.704-0.432j]]\n"
173+
"[[-0.115+0.54j -0.002+0.292j 0.642+0.425j -0.132-0.02j -0.000+0.j 0.000-0.j ]\n",
174+
" [-0.349-0.342j 0.440+0.195j 0.198-0.152j -0.102-0.64j -0.192-0.104j 0.000+0.j ]\n",
175+
" [-0.100+0.118j -0.176-0.211j 0.111-0.117j 0.298-0.182j -0.142+0.282j 0.765-0.26j ]]\n"
176176
]
177177
}
178178
],
@@ -201,30 +201,30 @@
201201
"output_type": "stream",
202202
"text": [
203203
"Number of rotations to perform in parallel: 1\n",
204-
"[[ 0.355+0.69j -0.035+0.087j 0.384-0.491j 0.000-0.j 0.000+0.j 0.000+0.j ]\n",
205-
" [-0.403-0.176j -0.340-0.323j -0.047-0.607j -0.072-0.032j 0.165-0.427j 0.000-0.j ]\n",
206-
" [ 0.194-0.048j -0.169-0.072j 0.134+0.177j 0.220+0.179j -0.088-0.325j 0.704-0.432j]]\n",
207-
"\n",
204+
"[[-0.115+0.54j -0.002+0.292j 0.651+0.431j 0.000+0.j -0.000+0.j 0.000-0.j ]\n",
205+
" [-0.349-0.342j 0.440+0.195j 0.164-0.043j 0.210-0.64j -0.192-0.104j 0.000+0.j ]\n",
206+
" [-0.100+0.118j -0.176-0.211j 0.050-0.108j 0.361-0.058j -0.142+0.282j 0.765-0.26j ]]\n",
207+
"()\n",
208208
"Number of rotations to perform in parallel: 2\n",
209-
"[[ 0.355+0.69j -0.236+0.585j 0.000-0.j 0.000-0.j 0.000-0.j 0.000+0.j ]\n",
210-
" [-0.403-0.176j 0.160+0.516j -0.368-0.405j -0.425-0.187j 0.000+0.j 0.000-0.j ]\n",
211-
" [ 0.194-0.048j -0.201-0.142j -0.140-0.051j -0.287+0.102j 0.272+0.164j 0.704-0.432j]]\n",
212-
"\n",
209+
"[[-0.115+0.54j -0.005+0.834j -0.000+0.j 0.000-0.j 0.000+0.j 0.000-0.j ]\n",
210+
" [-0.349-0.342j 0.272+0.175j 0.368+0.143j 0.221-0.672j 0.000+0.j 0.000+0.j ]\n",
211+
" [-0.100+0.118j 0.049-0.09j -0.206-0.192j 0.250-0.083j 0.400+0.068j 0.765-0.26j ]]\n",
212+
"()\n",
213213
"Number of rotations to perform in parallel: 3\n",
214-
"[[ 0.457+0.889j -0.000+0.j 0.000-0.j 0.000-0.j 0.000+0.j 0.000-0.j ]\n",
215-
" [-0.000-0.j -0.638-0.279j -0.483-0.531j -0.000-0.j 0.000-0.j 0.000+0.j ]\n",
216-
" [ 0.000+0.j 0.308-0.077j -0.303-0.054j 0.141-0.015j 0.759+0.457j 0.000+0.j ]]\n",
217-
"\n",
214+
"[[-0.209+0.978j -0.000+0.j -0.000+0.j -0.000-0.j 0.000+0.j 0.000-0.j ]\n",
215+
" [ 0.000-0.j -0.418-0.41j 0.756+0.293j 0.000-0.j 0.000+0.j 0.000+0.j ]\n",
216+
" [ 0.000-0.j -0.120+0.142j -0.039+0.129j -0.214-0.291j 0.891+0.151j -0.000+0.j ]]\n",
217+
"()\n",
218218
"Number of rotations to perform in parallel: 2\n",
219-
"[[ 0.457+0.889j -0.000-0.j -0.000+0.j 0.000+0.j -0.000-0.j 0.000-0.j ]\n",
220-
" [-0.000-0.j -0.916-0.4j 0.000+0.j 0.000-0.j -0.000-0.j 0.000+0.j ]\n",
221-
" [ 0.000+0.j -0.000-0.j 0.429-0.107j 0.892-0.095j 0.000-0.j 0.000+0.j ]]\n",
222-
"\n",
219+
"[[-0.209+0.978j 0.000-0.j -0.000+0.j -0.000-0.j -0.000-0.j 0.000-0.j ]\n",
220+
" [ 0.000-0.j -0.714-0.7j -0.000+0.j 0.000-0.j 0.000-0.j 0.000+0.j ]\n",
221+
" [ 0.000-0.j -0.000-0.j -0.148+0.175j -0.576-0.784j -0.000-0.j -0.000+0.j ]]\n",
222+
"()\n",
223223
"Number of rotations to perform in parallel: 1\n",
224-
"[[ 0.457+0.889j -0.000-0.j -0.000+0.j -0.000+0.j -0.000-0.j 0.000-0.j ]\n",
225-
" [-0.000-0.j -0.916-0.4j 0.000-0.j 0.000+0.j -0.000-0.j 0.000+0.j ]\n",
226-
" [ 0.000+0.j -0.000-0.j 0.970-0.242j -0.000-0.j 0.000-0.j 0.000+0.j ]]\n",
227-
"\n"
224+
"[[-0.209+0.978j 0.000-0.j -0.000+0.j -0.000+0.j -0.000-0.j 0.000-0.j ]\n",
225+
" [ 0.000-0.j -0.714-0.7j -0.000+0.j -0.000+0.j 0.000-0.j 0.000+0.j ]\n",
226+
" [ 0.000-0.j -0.000-0.j -0.645+0.764j 0.000+0.j -0.000-0.j -0.000+0.j ]]\n",
227+
"()\n"
228228
]
229229
}
230230
],
@@ -287,21 +287,21 @@
287287
],
288288
"metadata": {
289289
"kernelspec": {
290-
"display_name": "Python 3",
290+
"display_name": "Python 2",
291291
"language": "python",
292-
"name": "python3"
292+
"name": "python2"
293293
},
294294
"language_info": {
295295
"codemirror_mode": {
296296
"name": "ipython",
297-
"version": 3
297+
"version": 2
298298
},
299299
"file_extension": ".py",
300300
"mimetype": "text/x-python",
301301
"name": "python",
302302
"nbconvert_exporter": "python",
303-
"pygments_lexer": "ipython3",
304-
"version": "3.6.2"
303+
"pygments_lexer": "ipython2",
304+
"version": "2.7.13"
305305
}
306306
},
307307
"nbformat": 4,

examples/openfermion_demo.ipynb

Lines changed: 15 additions & 12 deletions
Large diffs are not rendered by default.

examples/performance_benchmarks.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import numpy
1515
import time
1616

17-
from openfermion.ops import FermionOperator, InteractionOperator, normal_ordered
17+
from openfermion.ops import (FermionOperator,
18+
InteractionOperator,
19+
normal_ordered)
1820
from openfermion.transforms import get_fermion_operator, jordan_wigner
1921
from openfermion.utils import jordan_wigner_sparse
2022

@@ -188,7 +190,7 @@ def benchmark_jordan_wigner_sparse(n_qubits):
188190
print('Starting test on InteractionOperator.jordan_wigner_transform()')
189191
runtime = benchmark_molecular_operator_jordan_wigner(n_qubits)
190192
print('InteractionOperator.jordan_wigner_transform() ' +
191-
'takes {} seconds on {} qubits.'.format(runtime, n_qubits))
193+
'takes {} seconds on {} qubits.\n'.format(runtime, n_qubits))
192194

193195
# Run benchmark on FermionOperator math and normal-ordering.
194196
n_qubits = 20
@@ -197,7 +199,7 @@ def benchmark_jordan_wigner_sparse(n_qubits):
197199
print('Starting test on FermionOperator math and normal ordering.')
198200
runtime_math, runtime_normal = benchmark_fermion_math_and_normal_order(
199201
n_qubits, term_length, power)
200-
print('Math took {} seconds. Normal ordering took {} seconds.'.format(
202+
print('Math took {} seconds. Normal ordering took {} seconds.\n'.format(
201203
runtime_math, runtime_normal))
202204

203205
# Run FermionOperator.jordan_wigner_sparse() benchmark.

src/openfermion/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
# limitations under the License.
1212

1313
"""Define version number here and read it from setup.py automatically"""
14-
__version__ = "0.1a1"
14+
__version__ = "0.1a2"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
from ._chemical_series import (make_atomic_ring,
14+
make_atomic_lattice,
15+
make_atom)
16+
17+
from ._hubbard import fermi_hubbard
18+
19+
from ._jellium import (dual_basis_kinetic,
20+
dual_basis_potential,
21+
dual_basis_jellium_model,
22+
jellium_model,
23+
jordan_wigner_dual_basis_jellium,
24+
plane_wave_kinetic,
25+
plane_wave_potential)
26+
27+
from ._mean_field_dwave import mean_field_dwave
28+
29+
from ._molecular_data import MolecularData, periodic_table
30+
31+
from ._plane_wave_hamiltonian import (dual_basis_external_potential,
32+
plane_wave_external_potential,
33+
plane_wave_hamiltonian,
34+
jordan_wigner_dual_basis_hamiltonian,
35+
wigner_seitz_length_scale)

0 commit comments

Comments
 (0)