Skip to content

Commit bfedfb4

Browse files
babbushdamiansteiger
authored andcommitted
Minor modifications to docs (#3)
* Minor modifications to docs
1 parent 3a1b174 commit bfedfb4

File tree

3 files changed

+50
-53
lines changed

3 files changed

+50
-53
lines changed

docs/examples.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
Examples
44
========
55

6-
All of these example codes (and many more!) can be found on `GitHub <https://github.com/ProjectQ-Framework/FermiLib/tree/master/examples/>`_.
6+
All of these examples (and more!) are explained in detail in the ipython notebook
7+
fermilib_demo.ipynb located at `GitHub <https://github.com/ProjectQ-Framework/FermiLib/tree/master/examples/>`_.
78

89
.. toctree::
910
:maxdepth: 2
@@ -60,7 +61,14 @@ FermionOperator supports a wide range of builtins including str(), repr(), =, ,
6061
Qubit Operators
6162
---------------
6263

63-
The QubitOperator data structure is another essential part of FermiLib. While the QubitOperator was originally developed for FermiLib, it is now part of the core ProjectQ library so that it can be interpreted by the ProjectQ compiler using the TimeEvolution gate. As the name suggests, QubitOperator is used to store qubit operators in almost exactly the same way that FermionOperator is used to store fermion operators. For instance :math:`X_0 Z_3 Y_4` is a QubitOperator. The internal representation of this as a terms tuple would be :math:`((0,"X"),(3,"Z"),(4,"Y"))((0,"X"),(3,"Z"),(4,"Y"))`. Note that one important difference between QubitOperator and FermionOperator is that the terms in QubitOperator are always sorted in order of tensor factor. In some cases, this enables faster manipulation. We initialize some QubitOperators below.
64+
The QubitOperator data structure is another essential part of FermiLib. While
65+
the QubitOperator was originally developed for FermiLib, it is now part of the
66+
core ProjectQ library so that it can be interpreted by the ProjectQ compiler
67+
using the TimeEvolution gate. As the name suggests, QubitOperator is used to
68+
store qubit operators in almost exactly the same way that FermionOperator is
69+
used to store fermion operators. For instance :math:`X_0 Z_3 Y_4` is a
70+
QubitOperator. The internal representation of this as a terms tuple would be
71+
:math:`((0, X),(3, Z),(4, Y))`. Note that one important difference between QubitOperator and FermionOperator is that the terms in QubitOperator are always sorted in order of tensor factor. In some cases, this enables faster manipulation. We initialize some QubitOperators below.
6472

6573
.. code-block:: python
6674
@@ -72,7 +80,6 @@ The QubitOperator data structure is another essential part of FermiLib. While th
7280
7381
operator_2 = QubitOperator('X3 Z4', 3.17)
7482
operator_2 -= 77. * my_first_qubit_operator
75-
print('')
7683
print(operator_2)
7784
7885
Transformations
@@ -93,16 +100,14 @@ FermiLib also provides functions for mapping FermionOperators to QubitOperators,
93100
94101
# Transform to qubits under the Jordan-Wigner transformation and print its spectrum.
95102
jw_operator = jordan_wigner(fermion_operator)
96-
print('')
97-
print(jw_operator)
98103
jw_spectrum = eigenspectrum(jw_operator)
104+
print(jw_operator)
99105
print(jw_spectrum)
100106
101107
# Transform to qubits under the Bravyi-Kitaev transformation and print its spectrum.
102108
bk_operator = bravyi_kitaev(fermion_operator)
103-
print('')
104-
print(bk_operator)
105109
bk_spectrum = eigenspectrum(bk_operator)
110+
print(bk_operator)
106111
print(bk_spectrum)
107112
108113
We see that despite the different representation, these operators are iso-spectral. We can also apply the Jordan-Wigner transform in reverse to map arbitrary QubitOperators to FermionOperators. Note that we also demonstrate the .compress() method (a method on both FermionOperators and QubitOperators) which removes zero entries.
@@ -119,13 +124,11 @@ We see that despite the different representation, these operators are iso-spectr
119124
120125
# Map QubitOperator to a FermionOperator.
121126
mapped_operator = reverse_jordan_wigner(my_operator)
122-
print('')
123127
print(mapped_operator)
124128
125129
# Map the operator back to qubits and make sure it is the same.
126130
back_to_normal = jordan_wigner(mapped_operator)
127131
back_to_normal.compress()
128-
print('')
129132
print(back_to_normal)
130133
131134
Sparse matrices and the Hubbard model
@@ -157,12 +160,10 @@ Often, one would like to obtain a sparse matrix representation of an operator wh
157160
# Get qubit operator under Jordan-Wigner.
158161
jw_hamiltonian = jordan_wigner(hubbard_model)
159162
jw_hamiltonian.compress()
160-
print('')
161163
print(jw_hamiltonian)
162164
163165
# Get scipy.sparse.csc representation.
164166
sparse_operator = get_sparse_operator(hubbard_model)
165-
print('')
166167
print(sparse_operator)
167168
print('\nEnergy of the model is {} in units of T and J.'.format(
168169
get_ground_state(sparse_operator)[0]))

docs/intro.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,14 @@ To see a basic example with both fermionic and qubit operators as well as whethe
4343
4444
# Transform to qubits under the Jordan-Wigner transformation and print its spectrum.
4545
jw_operator = jordan_wigner(fermion_operator)
46-
print('')
47-
print(jw_operator)
4846
jw_spectrum = eigenspectrum(jw_operator)
47+
print(jw_operator)
4948
print(jw_spectrum)
5049
5150
# Transform to qubits under the Bravyi-Kitaev transformation and print its spectrum.
5251
bk_operator = bravyi_kitaev(fermion_operator)
53-
print('')
54-
print(bk_operator)
5552
bk_spectrum = eigenspectrum(bk_operator)
53+
print(bk_operator)
5654
print(bk_spectrum)
5755
5856

0 commit comments

Comments
 (0)