Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
2cc7cd0
Initial commit
meandmytram Mar 23, 2021
28460aa
Fixing the test file
meandmytram Mar 23, 2021
e867533
Update pyproject.toml
meandmytram Mar 23, 2021
f5e85a7
Replace np.float with np.float64
Mar 24, 2021
45941cd
Fix a call to numpy.random
Mar 24, 2021
95adc80
Use a more functionnal style for some method
Mar 24, 2021
f3b0875
Still figuring things out with git. See previous message.
meandmytram Mar 25, 2021
8365bfd
Rename MPS.py to mps.py
meandmytram Mar 25, 2021
f922c93
Add everyone in the author list
Mar 25, 2021
b6ce064
housekeeping + add experiments module + delete common tensors to make…
meandmytram Apr 14, 2021
b4c3844
mps class update + utils update + tests update
meandmytram Apr 14, 2021
af11810
update pyproject.toml
meandmytram Apr 14, 2021
b8523d0
Rename MPS to ExplicitMPS
Apr 15, 2021
e55de4e
Some cleaning and reorganisation of tests
Apr 15, 2021
76a177f
update to collaborate on the code
meandmytram May 12, 2021
4b43ea8
ExplicitMPS + utils + tests
meandmytram Jun 15, 2021
b237775
Ferro/antiferro initial states fix, not an important commit
meandmytram Jun 15, 2021
c33b350
Update actions.yml
meandmytram Jun 15, 2021
4bb3bfc
contractor+dmrg, work in progress
meandmytram Sep 30, 2021
4be27af
contractor
meandmytram Oct 5, 2021
3878c48
two-site contractor update
meandmytram Oct 6, 2021
d62df5a
update pyproject.toml
meandmytram Oct 6, 2021
784b0ac
docs update
meandmytram Oct 6, 2021
46bb8ef
one-site contractor
meandmytram Oct 7, 2021
e93f2ad
relax absolute tolerance in one of the functions: 1e-13 -> 1e-12
meandmytram Oct 7, 2021
e252d1c
housekeeping
meandmytram Oct 11, 2021
70e587e
update pyproject.toml
meandmytram Oct 11, 2021
c361f78
docstring update
meandmytram Oct 12, 2021
75d9d07
mps class now has a copy method
meandmytram Oct 14, 2021
7da4c09
svd is now simpler, shorter and faster
meandmytram Oct 14, 2021
3a4fb20
housekeeping
meandmytram Oct 14, 2021
e5fa181
mpo index convention change + product state implementation
meandmytram Nov 4, 2021
6ff36f8
removed unused variables
meandmytram Nov 11, 2021
a3711ff
new module containing DMRG and its tests
meandmytram Nov 11, 2021
d7487d8
linting score improved
meandmytram Nov 11, 2021
a7dad7c
script showing full use of DMRG for the Ising model
meandmytram Nov 11, 2021
08de62f
housekeeping + collection error fix
meandmytram Nov 11, 2021
6746b97
numerical tolerance fix
meandmytram Nov 11, 2021
4e4e0f2
dmrg test fix
meandmytram Nov 11, 2021
a9b3f59
slight reorganization of the modules
meandmytram Nov 25, 2021
813d233
ising experiment minor fixes
meandmytram Nov 25, 2021
f24a135
documentation fix
meandmytram Nov 25, 2021
98adef0
comments and some variable renaming in the ising experiment script
meandmytram Dec 17, 2021
a04f9d2
Some explicit mps class minor housekeeping
meandmytram Dec 17, 2021
d134429
dmrg documentation typos fix
meandmytram Dec 17, 2021
0f37d99
TODOs now in a private file
meandmytram Dec 17, 2021
1ef48da
dmrg test now runs faster due to less sites
meandmytram Dec 17, 2021
9a3ed91
first try to connect codecov to the repo
meandmytram Dec 21, 2021
bc226a0
update actions.yml
meandmytram Dec 21, 2021
6dbe586
update actions.yml
meandmytram Dec 21, 2021
2ac2f13
update actions.yml
meandmytram Dec 21, 2021
12d55af
update actions.yml
meandmytram Dec 21, 2021
48554fe
update actions.yml
meandmytram Dec 21, 2021
287e931
update actions.yml
meandmytram Dec 21, 2021
4c54f3f
Update README.md
meandmytram Dec 21, 2021
d1eb57f
update actions.yml
meandmytram Dec 21, 2021
970572f
Merge branch 'Alex_path' of https://github.com/quicophy/MPOpt into Al…
meandmytram Dec 21, 2021
9e7388f
update actions.yml
meandmytram Dec 21, 2021
7439782
Update actions.yml
meandmytram Dec 29, 2021
fc9a7e6
Update actions.yml
meandmytram Dec 29, 2021
bb910bf
Update README.md
meandmytram Dec 29, 2021
42d8a78
further setting up of codecov
meandmytram Dec 30, 2021
42f21b8
Update actions.yml
meandmytram Dec 30, 2021
9e52aea
Update actions.yml
meandmytram Jan 3, 2022
0b001b1
codecov-related stuff
meandmytram Jan 3, 2022
5c86279
Update actions.yml
meandmytram Jan 3, 2022
95fb596
Rename actions.yml to tests.yml
meandmytram Jan 4, 2022
2c512eb
test pass badge
meandmytram Jan 4, 2022
ec5deda
Update README.md
meandmytram Jan 4, 2022
098fe6d
update README
meandmytram Mar 17, 2022
b4b6e0f
update the ising dmrg experiment
meandmytram Mar 17, 2022
102c3cb
update the contractor module
meandmytram Mar 17, 2022
28ae62d
classical decoding experiment
meandmytram Mar 17, 2022
847b80e
explicit MPS update
meandmytram Mar 17, 2022
5356d1f
optimizer module update
meandmytram Mar 17, 2022
f866596
canonical mps module
meandmytram Mar 17, 2022
8819ca1
create utils module
meandmytram Mar 17, 2022
9f81be2
tests update
meandmytram Mar 17, 2022
66f6e36
Merge branch 'main' into alex-branch-1
meandmytram Mar 17, 2022
25b5d30
Merge branch 'main' into alex-branch-1
meandmytram Mar 18, 2022
19054bc
Update actions.yml
meandmytram Mar 18, 2022
4600da2
import problems for codecov + todos
meandmytram Mar 18, 2022
f4d17af
Merge branch 'alex-branch-1' of https://github.com/quicophy/MPOpt int…
meandmytram Mar 18, 2022
0ccaa4a
import fix
meandmytram Mar 18, 2022
a604c44
Merge branch 'main' into alex-branch-1
meandmytram Mar 18, 2022
34cca7e
update __init__.py
meandmytram Mar 18, 2022
4a28ad8
Update README.md
meandmytram Mar 18, 2022
edfa799
Update codecov.yml
meandmytram Mar 18, 2022
784fdaf
Update codecov.yml
meandmytram Mar 18, 2022
40f1e31
Merge branch 'main' into alex-branch-1
meandmytram Mar 18, 2022
96db987
Merge branch 'alex-branch-1' of https://github.com/quicophy/MPOpt int…
meandmytram Mar 18, 2022
8fd1955
housekeeping
meandmytram Mar 18, 2022
ddd2d1a
further fixes implemented
meandmytram Mar 24, 2022
75a2dfb
actions.yml and pyproject.toml updates
meandmytram Apr 6, 2022
daa46e0
todos for the decoding example
meandmytram Apr 6, 2022
a17c7a8
got rid of unused copy statements, dmrg now copies according to a flag
meandmytram Apr 6, 2022
7a39d9f
Merge branch 'main' into origin/main
meandmytram Apr 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions experiments/decoding_classical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
In this experiment, we decode a classical error correction code.
First, we build the codeword MPS and test it against the dense form.
Then, we demostrate simple decoding of a classical LDPC code with DMRG.
The script should be launched from the root of the project directory.
"""

import sys
Expand Down Expand Up @@ -117,7 +118,7 @@ def get_mpo(self):
# Simply speaking, it flips the bit with probability `p` and leaves it
# the same with probability `1-p`.


# TODO this exists in qecstruct (find out if there's a square root)
def binary_symmetric_channel(prob):
"""
This function returns a single-site MPO,
Expand All @@ -135,7 +136,7 @@ def binary_symmetric_channel(prob):
# Below, we define some utility functions to operate with error correction codes from qecstruct.
# Co-authored by Stefanos Kourtis.


# TODO exists in qecstruct
def linear_code_checks(code):
"""
Given a linear code, returns a list of its checks, where each check
Expand All @@ -160,6 +161,7 @@ def linear_code_checks(code):
return checks


# TODO exists in qecstruct
def get_codewords(code):
"""
Return the list of codewords of a linear code. Codewords are returned
Expand Down Expand Up @@ -335,7 +337,8 @@ def get_codewords(code):
print("Retreiving a perturbed codeword: ")

# Building an initial and a perturbed codeword.
# TODO
# TODO start from random codeword
# TODO the error model exists in qecstruct
INITIAL_STRING = "0" * NUM_BITS
PERTURBED_STRING = ""
for i in range(NUM_BITS):
Expand Down Expand Up @@ -378,7 +381,7 @@ def get_codewords(code):
print("DMRG running:")
mps_dmrg_start = create_product_state(len(density_mpo), which="0")
# TODO start with random product state
engine = dmrg(mps_dmrg_start.copy(), density_mpo, chi_max=128, cut=1e-14, mode="LA")
engine = dmrg(mps_dmrg_start, density_mpo, chi_max=128, cut=1e-14, mode="LA")
engine.run(20)
mps_dmrg_final = engine.mps.to_right_canonical()

Expand Down
2 changes: 1 addition & 1 deletion experiments/ising.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def average_chain_x_magnetization(self, mps):
ham_mpo = ising_mpo.hamiltonian_mpo()
ham_exact = ising_exact.hamiltonian_dense()
mps_start = create_product_state(NUMBER_OF_SITES, which="0")
engine = dmrg(mps_start.copy(), ham_mpo, chi_max=64, cut=1e-14, mode="SA")
engine = dmrg(mps_start, ham_mpo, chi_max=64, cut=1e-14, mode="SA")
engine.run(10)
ground_state_mps = engine.mps
ground_state_exact = eigsh(ham_exact, k=6)[1][:, 0]
Expand Down
15 changes: 2 additions & 13 deletions mpopt/mps/canonical.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"""

from functools import reduce
from copy import deepcopy
from opt_einsum import contract
import numpy as np
from mpopt.mps.explicit import ExplicitMPS
Expand All @@ -44,7 +43,6 @@ def find_orth_centre(mps):
Note that the MPS is not given as `ExplicitMPS` instance here.
"""

mps = deepcopy(mps)
mps = _add_ghost_dimensions(mps)

length = len(mps)
Expand Down Expand Up @@ -115,7 +113,6 @@ def move_orth_centre(mps, init_pos, final_pos):
If inital_pos or final_pos does not match the MPS length.
"""

mps = deepcopy(mps)
mps = _add_ghost_dimensions(mps)

length = len(mps)
Expand Down Expand Up @@ -179,7 +176,6 @@ def _move_orth_centre_singular_values(mps, init_pos, final_pos):
If inital_pos or final_pos does not match the MPS length.
"""

mps = deepcopy(mps)
length = len(mps)

mps = _add_ghost_dimensions(mps)
Expand Down Expand Up @@ -224,7 +220,6 @@ def is_canonical(mps):
not the `ExplicitMPS` class instance.
"""

mps = deepcopy(mps)
mps = _add_ghost_dimensions(mps)

# Check if the form is left- or right- canonical
Expand Down Expand Up @@ -264,7 +259,6 @@ def is_canonical(mps):

def _move_orth_centre_to_border(mps, init_orth_centre_index):

mps = deepcopy(mps)
mps = _add_ghost_dimensions(mps)
length = len(mps)

Expand Down Expand Up @@ -293,7 +287,6 @@ def to_explicit(mps):
Minimum singular values to keep.
"""

mps = deepcopy(mps)
length = len(mps)

centres = find_orth_centre(mps)
Expand Down Expand Up @@ -332,7 +325,6 @@ def _add_ghost_dimensions(mps):
This is a helper function.
"""

mps = deepcopy(mps)
for i in [0, -1]:
if len(mps[i].shape) == 2:
mps[i] = np.expand_dims(mps[i], i) # convention, see the MPS class
Expand All @@ -341,13 +333,11 @@ def _add_ghost_dimensions(mps):

def inner_product(mps_1, mps_2):
"""
# TODO docstring
Returns an inner product between 2 Matrix Product States.
Note, that this function takes an MPS as a list of tensors,
not the `ExplicitMPS` class instance.
"""

mps_1 = deepcopy(mps_1)
mps_2 = deepcopy(mps_2)

if len(mps_1) != len(mps_2):
raise ValueError(
f"The number of sites in the first MPS is ({len(mps_1)}), while "
Expand Down Expand Up @@ -390,7 +380,6 @@ def to_dense(mps, flatten=True):
Whether to merge all the physical indices to form a vector.
"""

mps = deepcopy(mps)
dense = reduce(lambda a, b: np.tensordot(a, b, (-1, 0)), mps)

if flatten:
Expand Down
2 changes: 1 addition & 1 deletion mpopt/mps/explicit.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __iter__(self):

def copy(self):
"""
Returns a copy of the current MPS
Returns a copy of the current MPS.
"""
return ExplicitMPS(self.tensors.copy(), self.singular_values.copy())

Expand Down
6 changes: 4 additions & 2 deletions mpopt/optimizer/dmrg.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,16 @@ class DMRG:
.--dL dR--.
"""

def __init__(self, mps, mpo, chi_max, cut, mode):
def __init__(self, mps, mpo, chi_max, cut, mode, copy=True):
if len(mps) != len(mpo):
raise ValueError(
f"The MPS has length ({len(mps)}), "
f"the MPO has length ({len(mpo)}), "
"but the lengths should be equal."
)
self.mps = deepcopy(mps)
self.mps = mps
if copy:
self.mps = deepcopy(mps)
self.left_environments = [None] * len(mps)
self.right_environments = [None] * len(mps)
self.mpo = mpo
Expand Down
9 changes: 2 additions & 7 deletions mpopt/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def svd(mat, cut=1e-14, chi_max=1e5, renormalise=False):
Unitary matrix having right singular vectors as rows.
"""

mat = np.copy(mat)
u_l, singular_values, v_r = np.linalg.svd(mat, full_matrices=False)

max_num = min(chi_max, np.sum(singular_values > cut))
Expand Down Expand Up @@ -73,9 +72,6 @@ def kron_tensors(tensor_1, tensor_2, conjugate_second=False, merge_physicals=Tru
Whether to merge physical indices.
"""

tensor_1 = np.copy(tensor_1)
tensor_2 = np.copy(tensor_2)

if len(tensor_1.shape) != len(tensor_2.shape):
raise ValueError("The tensors must have equal numbers of dimensions.")

Expand Down Expand Up @@ -127,8 +123,7 @@ def split_two_site_tensor(theta, chi_max=1e5, cut=1e-14, renormalise=False):
Right isometry on site j, with legs vC, j, vR.
"""

# merge the legs to form a matrix to feed into svd
theta = np.copy(theta)
# merge the legs to form a matrix to feed into the svd
chi_v_l, d_l, d_r, chi_v_r = theta.shape
theta = theta.reshape((chi_v_l * d_l, d_r * chi_v_r))

Expand Down Expand Up @@ -318,7 +313,7 @@ def mpo_from_matrix(matrix, num_sites, interlaced=True, phys_dim=2, chi_max=1e5)
f"or {tuple(phys_dims)}, instead, the matrix given has shape {matrix.shape}."
)

# Copying the matrix not to change the origonal one inplace
# Copying the matrix not to change the original one inplace
mat = matrix.copy()

# Reshaping the matrix
Expand Down
2 changes: 1 addition & 1 deletion tests/optimizer/test_dmrg.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_ground_states():

mps_start = create_product_state(number_of_sites, which="0")

engine = dmrg(mps_start.copy(), ham_mpo, chi_max=64, cut=1e-14, mode="SA")
engine = dmrg(mps_start, ham_mpo, chi_max=64, cut=1e-14, mode="SA")
engine.run(10)
ground_state_mps = engine.mps
ground_state_exact = eigsh(ham_exact, k=6)[1][:, 0]
Expand Down