{"id":21757738,"url":"https://github.com/joserapa98/tensorkrowch","last_synced_at":"2025-04-10T03:52:44.854Z","repository":{"id":131453372,"uuid":"453954432","full_name":"joserapa98/tensorkrowch","owner":"joserapa98","description":"Smooth integration of tensor networks in machine learning","archived":false,"fork":false,"pushed_at":"2025-03-29T19:16:20.000Z","size":19617,"stargazers_count":39,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T03:52:35.752Z","etag":null,"topics":["machine-learning","pytorch","tensor-networks"],"latest_commit_sha":null,"homepage":"https://joserapa98.github.io/tensorkrowch/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joserapa98.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-31T10:01:39.000Z","updated_at":"2025-02-19T18:26:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"c680e7b4-db03-4583-81e1-29d206fba253","html_url":"https://github.com/joserapa98/tensorkrowch","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joserapa98%2Ftensorkrowch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joserapa98%2Ftensorkrowch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joserapa98%2Ftensorkrowch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joserapa98%2Ftensorkrowch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joserapa98","download_url":"https://codeload.github.com/joserapa98/tensorkrowch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248154998,"owners_count":21056542,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["machine-learning","pytorch","tensor-networks"],"created_at":"2024-11-26T11:16:54.164Z","updated_at":"2025-04-10T03:52:44.825Z","avatar_url":"https://github.com/joserapa98.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![logo](https://github.com/joserapa98/tensorkrowch/blob/master/docs/figures/svg/tensorkrowch_logo_dark.svg#gh-dark-mode-only)\n![logo](https://github.com/joserapa98/tensorkrowch/blob/master/docs/figures/svg/tensorkrowch_logo_light.svg#gh-light-mode-only)\n\n[![DOI](https://zenodo.org/badge/453954432.svg)](https://zenodo.org/badge/latestdoi/453954432)\n\n# Tensor Networks with PyTorch\n\n**TensorKrowch** is a Python library built on top of **PyTorch** that simplifies\nthe training of Tensor Networks as machine learning models and their integration\ninto deep learning pipelines.\n\nThe primary goal of **TensorKrowch** is to offer an efficient and user-friendly\nframework for constructing and training diverse Tensor Networks. By providing\nessential components like ``Nodes``, ``Edges``, and ``TensorNetworks``,\n**TensorKrowch** facilitates the creation and training of these models. Notably,\neven the included implementations of ``MPS`` or ``PEPS`` only rely on these\nfundamental components.\n\nAs a result, users who grasp the basic tools of **TensorKrowch** gain the ability\nto build a wide range of networks, ranging from simple Matrix Product States to\nmore intricate architectures.\n\nThe true strength of **TensorKrowch** lies in its support for rapid experimentation,\nenabling users to create and train different models with just a few lines of code\nchanges.\n\nIt's important to note that while **TensorKrowch** is a versatile library, it\nmay not always be the fastest option in certain scenarios. However, it excels\nas a tool for exploration and identification of the most suitable Tensor Network.\nOnce the ideal network is determined, users can develop further optimized code\nspecifically tailored to that network.\n\nNevertheless, **TensorKrowch** incorporates various optimizations to ensure\nefficient training performance.\n\n\n## Documentation\n\nFor detailed usage instructions, API reference, and code examples, please refer\nto the official **TensorKrowch** [documentation](https://joserapa98.github.io/tensorkrowch).\n\n\n## Requirements\n\n* python \u003e= 3.8\n* torch \u003e= 1.9\n* opt_einsum \u003e= 3.0\n\n\n## Installation\n\nTo install the package, run the following command:\n\n```\npip install tensorkrowch\n```\n\nYou can also install directly from GitHub with:\n\n```\npip install git+https://github.com/joserapa98/tensorkrowch.git@master\n```\n\nor download the repository on your computer and run \n\n```\npip install .\n```\n\nin the repository folder.\n\nTests are written outside the Python module, therefore they are not installed\ntogether with the package. To test the installation, clone the repository and\nrun, in a Unix terminal\n\n```\npython -m pytest -v\n```\n\ninside the repository folder.\n\n\u003e [!NOTE]\nCertain tests may experience failure as a result of statistical anomalies or \nhardware constraints. We advise reviewing the error messages to determine if \nthese failures stem from such occurrences. Should this be the case, consider \nrerunning the tests to ascertain if the errors persist.\n\n\n## Example\n\nWith **TensorKrowch** you can experiment building Tensor Networks:\n\n```python\nimport torch\nimport tensorkrowch as tk\n\nnet = tk.TensorNetwork()\n\nnode1 = tk.randn(shape=(7, 5),\n                 axes_names=('left', 'right'),\n                 name='node1',\n                 network=net,\n                 param_node=True)\nnode2 = tk.randn(shape=(7, 5),\n                 axes_names=('left', 'right'),\n                 name='node2',\n                 network=net,\n                 param_node=True)\n\nnode1['left'] ^ node2['left']\nnode1['right'] ^ node2['right']\n```\n\nIt is also quite easy to contract the network and compute gradients:\n\n```python\nresult = node1 @ node2\nresult.tensor.backward()\n\nassert node1.grad is not None\nassert node2.grad is not None\n```\n\nIn **TensorKrowch** ``TensorNetworks`` work like **PyTorch** layers. Thus\ncreating hybrid neural-tensor network models is straightforward:\n\n```python\nimport torch.nn as nn\n\nmy_model = nn.Sequential(\n    tk.models.MPSLayer(n_features=101,\n                       in_dim=3,\n                       out_dim=10,\n                       bond_dim=5),\n    nn.ReLU(),\n    nn.Linear(10, 10))\n\ndata = torch.randn(500, 100, 3)  # batch x n_features x in_dim\nmy_model(data)  # batch x out_dim\n```\n\n\n## Tutorials\n\nTo fully grasp the basic components of **TensorKrowch** and harness its potential,\nit is highly recommended to explore the available tutorials. These tutorials\nprovide a detailed introduction to the fundamental elements of the library and\nguide you through the process of constructing and training tensor networks.\n\nBy immersing yourself in the tutorials, you will become familiar with key\nconcepts and best practices for using **TensorKrowch**. You will learn how to\ndefine ``Nodes``, create connections between through their ``Edges``, and\nconfigure the ``TensorNetwork`` structure. This hands-on approach will greatly\nenhance your understanding and proficiency with **TensorKrowch**.\n\n* [First Steps with TensorKrowch](https://joserapa98.github.io/tensorkrowch/_build/html/tutorials/0_first_steps.html)\n* [Creating a Tensor Network in TensorKrowch](https://joserapa98.github.io/tensorkrowch/_build/html/tutorials/1_creating_tensor_network.html)\n* [Contracting and Differentiating the Tensor Network](https://joserapa98.github.io/tensorkrowch/_build/html/tutorials/2_contracting_tensor_network.html)\n* [How to save Memory and Time with TensorKrowch (ADVANCED)](https://joserapa98.github.io/tensorkrowch/_build/html/tutorials/3_memory_management.html)\n* [The different Types of Nodes (ADVANCED)](https://joserapa98.github.io/tensorkrowch/_build/html/tutorials/4_types_of_nodes.html)\n* [How to subclass TensorNetwork to build Custom Models](https://joserapa98.github.io/tensorkrowch/_build/html/tutorials/5_subclass_tensor_network.html)\n* [Creating a Hybrid Neural-Tensor Network Model](https://joserapa98.github.io/tensorkrowch/_build/html/tutorials/6_mix_with_pytorch.html)\n\n\n## Example Notebooks\n\nIn addition to the informative tutorials, there is also a collection of examples\nthat serve as practical demonstrations of how to apply **TensorKrowch** in\nvarious contexts, showcasing its versatility.\n\nWith the code provided in the examples, you will be able to reproduce key research\nfindings that bridge the gap between tensor networks and machine learning. These\nexamples provide a hands-on approach to understanding the intricacies of\n**TensorKrowch**, allowing you to explore its potential and adapt it to your\nspecific needs.\n\n* [Training MPS in different ways](https://joserapa98.github.io/tensorkrowch/_build/html/examples/training_mps.html)\n* [Hybrid Tensorial Neural Network model](https://joserapa98.github.io/tensorkrowch/_build/html/examples/hybrid_tnn_model.html)\n* [Tensorizing Neural Networks](https://joserapa98.github.io/tensorkrowch/_build/html/examples/tensorizing_nn.html)\n* [DMRG-like training of MPS](https://joserapa98.github.io/tensorkrowch/_build/html/examples/mps_dmrg.html)\n* [Hybrid DMRG-like training of MPS](https://joserapa98.github.io/tensorkrowch/_build/html/examples/mps_dmrg_hybrid.html)\n\n\n## License\n\n**TensorKrowch** is licensed under the MIT License. Please see the [LICENSE](https://github.com/joserapa98/tensorkrowch/blob/master/LICENSE.txt) file for more information.\n\n\n## Citing\n\nIf you use TensorKrowch in your work, please cite [TensorKrowch's paper](https://www.arxiv.org/abs/2306.08595):\n\n- J. R. Pareja Monturiol, D. Pérez-García, and A. Pozas-Kerstjens, \n\"TensorKrowch: Smooth integration of tensor networks in machine learning\", \nQuantum **8**, 1364 (2024), arXiv:2306.08595.\n\n```\n@article{pareja2024tensorkrowch,\n  title={Tensor{K}rowch: {S}mooth integration of tensor networks in machine learning},\n  author={Pareja Monturiol, Jos{\\'e} Ram{\\'o}n and P{\\'e}rez-Garc{\\'i}a, David and Pozas-Kerstjens, Alejandro},\n  journal={Quantum},\n  volume={8},\n  pages={1364},\n  year={2024},\n  publisher={Verein zur F{\\\"o}rderung des Open Access Publizierens in den Quantenwissenschaften},\n  doi={10.22331/q-2024-06-11-1364},\n  archivePrefix={arXiv},\n  eprint={2306.08595}\n}\n```\n\n\n## Acknowledgments\n\nThis work has been financially supported by the Ministry for Digital\nTransformation and of Civil Service of the Spanish Government through the\nQUANTUM ENIA project call – Quantum Spain project, and by the European Union\nthrough the Recovery, Transformation and Resilience Plan – NextGenerationEU\nwithin the framework of the Digital Spain 2026 Agenda.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoserapa98%2Ftensorkrowch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoserapa98%2Ftensorkrowch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoserapa98%2Ftensorkrowch/lists"}