Skip to content

Commit

Permalink
Merge pull request #11 from RoyElkabetz/re/add-pre-commit
Browse files Browse the repository at this point in the history
Add lint and code reformatting with pre-commit
  • Loading branch information
RoyElkabetz authored Jul 20, 2024
2 parents b4391e0 + 5ed2382 commit 3268d48
Show file tree
Hide file tree
Showing 17 changed files with 853 additions and 607 deletions.
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ assignees: ''

---

### Short Description
### Short Description
<!--**Is your feature request related to a problem? Please describe shortly (a single paragraph).**-->

### Current Behavior
### Current Behavior
<!--**Describe the current behavior. This is the place to add a minimal reproducer of the problem/behavior.**-->

### Expected Behavior
### Expected Behavior
<!--**Describe the expected behavior after solution implemented.**-->

### Additional context
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements-dev.txt --timeout=60 --retries=5
pip install scipy
pip install -e .
pip install -e .
- name: Run tests
run: |
Expand Down
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
args: [--line-length=120]
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ We use github to host code, to track issues and feature requests, as well as acc
Pull requests are the best way to propose changes to the codebase. We actively welcome your pull requests:

1. Fork the repo and create your branch from `dev` (not `main`).
2. Install locally using `requirements-dev.txt`.
2. Install locally using `requirements.txt`.
3. If you've added code that should be tested, add tests to `tests/test_main.py`.
4. If you've changed APIs, update the documentation.
5. Ensure the test suite passes by install and run `pytest`.
6. Issue that pull request!
6. You are encouraged to use `pre-commit` with `pip install pre-commit` and then `pre-commit install`.
7. Issue that pull request!

## Any contributions you make will be under the MIT Software License
In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
57 changes: 28 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Tensor Networks Simple-Update (SU) Algorithm
> This python package contains an implementation of the Simple-Update Tensor Network algorithm as described in the paper - A universal tensor network algorithm for any infinite lattice by Saeed S. Jahromi and Roman Orus [1].

### Installation
```bash
pip3 install tnsu
Expand All @@ -25,7 +25,7 @@ where finally,

<img src="https://github.com/RoyElkabetz/Tensor-Networks-Simple-Update/blob/main/assets/ITE_local_gate.png?raw=true" width="200" height="">

When performing the ITE scheme, the TN virtual bond dimension increases. Therefore, after every few ITE iterations, we need to truncate the bond dimensions so the number of parameters in the tensor network state would stay bounded. The truncation step is implemented via a [Singular Value Decomposition (SVD)](https://en.wikipedia.org/wiki/Singular_value_decomposition) step. A full step-by-step illustrated description of the Simple Update algorithm (which is based on the ITE scheme) is depicted below.
When performing the ITE scheme, the TN virtual bond dimension increases. Therefore, after every few ITE iterations, we need to truncate the bond dimensions so the number of parameters in the tensor network state would stay bounded. The truncation step is implemented via a [Singular Value Decomposition (SVD)](https://en.wikipedia.org/wiki/Singular_value_decomposition) step. A full step-by-step illustrated description of the Simple Update algorithm (which is based on the ITE scheme) is depicted below.

<img src="https://github.com/RoyElkabetz/Tensor-Networks-Simple-Update/blob/main/assets/simple_update_algorithm.png?raw=true" width="1000" height="">

Expand All @@ -36,10 +36,10 @@ For a more comprehensive explanation of the algorithm, the interested reader sho

The [`src.tnsu`](/src/tnsu) folder contains the source code for this project

| # | file | Subject |
| # | file | Subject |
|:----:|------------------------------------------------|:-----------------:|
| 1 | `tensor_network.py` | a Tensor Network class object which tracks the tensors, weights, and their connectivity|
| 2 | `simple_update.py` | a Tensor Network Simple-Update algorithm class, which gets as an input a `TensorNetwork` object and performs a simple-update run on it using Imaginary Time Evolution. |
| 1 | `tensor_network.py` | a Tensor Network class object which tracks the tensors, weights, and their connectivity|
| 2 | `simple_update.py` | a Tensor Network Simple-Update algorithm class, which gets as an input a `TensorNetwork` object and performs a simple-update run on it using Imaginary Time Evolution. |
| 3 | `structure_matrix_constructor.py` | Contains a dictionary of common iPEPS structure matrices and also functionality construction of 2D square and rectangular lattices structure matrices (**still in progress**).
| 4 | `examples.py` | Few scripts for loading a tensor network state from memory and a full Antiferromagnetic Heisenberg model PEPS experiment.|
| 5 | `ncon.py` | A module for tensors contraction in python copied from the [ncon](https://github.com/mhauru/ncon) GitHub repository.|
Expand Down Expand Up @@ -69,7 +69,7 @@ Next we initialize a random Tensor Network with a virtual bond dimension of size
tensornet = TensorNetwork(structure_matrix=smat, virtual_size=2, spin_dim=2)
```

Then, set up the spin 1/2 operators and the simple update class parameters
Then, set up the spin 1/2 operators and the simple update class parameters
```python
# pauli matrices
pauli_x = np.array([[0, 1],
Expand All @@ -84,7 +84,7 @@ dts = [0.1, 0.01, 0.001, 0.0001, 0.00001]
# Local spin operators
s = [pauli_x / 2., pauli_y / 2., pauli_z / 2.]

# The Hamiltonian's 2-body interaction constants
# The Hamiltonian's 2-body interaction constants
j_ij = [1., 1., 1., 1., 1., 1.]

# The Hamiltonian's 1-body field constant
Expand All @@ -99,16 +99,16 @@ d_max = 2

Now, we initialize the simple update class
```python
star_su = su.SimpleUpdate(tensor_network=tensornet,
dts=dts,
j_ij=j_ij,
h_k=h_k,
s_i=s,
s_j=s,
s_k=s_k,
d_max=d_max,
max_iterations=200,
convergence_error=1e-6,
star_su = su.SimpleUpdate(tensor_network=tensornet,
dts=dts,
j_ij=j_ij,
h_k=h_k,
s_i=s,
s_j=s,
s_k=s_k,
d_max=d_max,
max_iterations=200,
convergence_error=1e-6,
log_energy=False,
print_process=False)
```
Expand Down Expand Up @@ -140,16 +140,16 @@ The trivial SU algorithm is equivalent to the SU algorithm without the ITE and t

In order to implement the trivial-SU algorithm, we can initialize the simple update class with zero time step as follows
```python
su.SimpleUpdate(tensor_network=tensornet,
dts=[0],
j_ij=j_ij,
h_k=0,
s_i=s,
s_j=s,
s_k=s_k,
d_max=d_max,
max_iterations=1000,
convergence_error=1e-6,
su.SimpleUpdate(tensor_network=tensornet,
dts=[0],
j_ij=j_ij,
h_k=0,
s_i=s,
s_j=s,
s_k=s_k,
d_max=d_max,
max_iterations=1000,
convergence_error=1e-6,
log_energy=False,
print_process=False)
```
Expand Down Expand Up @@ -178,7 +178,7 @@ Below are some results of ground-state energy per-site simulated with the Simple
In the case of the Star tensor network lattice, the AFH Hamiltonian consists of two parts that correspond to different types of edges (see [1]).
The Chain, Star, PEPS, and Cube infinite tensor networks are illustrated in the next figure.

<img src="https://github.com/RoyElkabetz/Tensor-Networks-Simple-Update/blob/main/assets/Tensor_Networks_diagrams.png?raw=true" width="1000" height="">
<img src="https://github.com/RoyElkabetz/Tensor-Networks-Simple-Update/blob/main/assets/Tensor_Networks_diagrams.png?raw=true" width="1000" height="">


Here is the ground-state energy per-site vs. inverse virtual bond-dimension simulations for the tensor networks diagrams above
Expand Down Expand Up @@ -228,4 +228,3 @@ To cite this repository in academic works or for any other purpose, please use t
type = "Python package"
}
```

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
build-backend = "setuptools.build_meta"
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
numpy
ncon --global-option="--user"
pytest
pytest
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ matplotlib
numpy
scipy
tqdm
ncon --global-option="--user"
ncon --global-option="--user"
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ where=src
tnsu = networks/*.pkl

[options.extras_require]
dev = pytest
dev = pytest
Loading

0 comments on commit 3268d48

Please sign in to comment.