Package: tensorkrowch
Tensor Networks with PyTorchTensorKrowchis a Python library built on top ofPyTorchthat simplifies
the training of Tensor Networks as machine learning models and their integration
into deep learning pipelines.The primary goal ofTensorKrowchis to offer an efficient and user-friendly
framework for constructing and training diverse Tensor Networks. By providing
essential components likeNodes,Edges, andTensorNetworks,TensorKrowchfacilitates the creation and training of these models. Notably,
even the included implementations ofMPSorPEPSonly rely on these
fundamental components.As a result, users who grasp the basic tools ofTensorKrowchgain the ability
to build a wide range of networks, ranging from simple Matrix Product States to
more intricate architectures.The true strength ofTensorKrowchlies in its support for rapid experimentation,
enabling users to create and train different models with just a few lines of code
changes.It's important to note that whileTensorKrowchis a versatile library, it
may not always be the fastest option in certain scenarios. However, it excels
as a tool for exploration and identification of the most suitable Tensor Network.
Once the ideal network is determined, users can develop further optimized code
specifically tailored to that network.Nevertheless,TensorKrowchincorporates various optimizations to ensure
efficient training performance.DocumentationFor detailed usage instructions, API reference, and code examples, please refer
to the officialTensorKrowchdocumentation.Requirementspython >= 3.7torch >= 1.9opt_einsum >= 3.0InstallationTo install the package, run the following command:pip install tensorkrowchYou can also install directly from GitHub with:pip install git+https://github.com/joserapa98/tensorkrowch.git@masteror download the repository on your computer and runpip install .in the repository folder.WARNING:SinceTensorKrowchhas aPyTorch C++ Extension,
it has to be built from source, so make sure you have installed on your system
a C++ compiler compatible with C++14.Tests are written outside the Python module, therefore they are not installed
together with the package. To test the installation, clone the repository and
run, in a Unix terminalpython -m pytest -vinside the repository folder.ExampleWithTensorKrowchyou can experiment building Tensor Networks:importtorchimporttensorkrowchastknet=tk.TensorNetwork()node1=tk.randn(shape=(7,5),axes_names=('left','right'),name='node1',network=net,param_node=True)node2=tk.randn(shape=(7,5),axes_names=('left','right'),name='node2',network=net,param_node=True)node1['left']^node2['left']node1['right']^node2['right']It is also quite easy to contract the network and compute gradients:result=node1@node2result.tensor.backward()assertnode1.gradisnotNoneassertnode2.gradisnotNoneInTensorKrowchTensorNetworkswork likePyTorchlayers. Thus
creating hybrid neural-tensor network models is straightforward:importtorch.nnasnnmy_model=nn.Sequential(tk.models.MPSLayer(n_features=100,in_dim=3,out_dim=10,bond_dim=5),nn.ReLU(),nn.Linear(10,10))data=torch.randn(500,100,3)# batch x n_features x in_dimmy_model(data)# batch x out_dimTutorialsTo fully grasp the basic components ofTensorKrowchand harness its potential,
it is highly recommended to explore the available tutorials. These tutorials
provide a detailed introduction to the fundamental elements of the library and
guide you through the process of constructing and training tensor networks.By immersing yourself in the tutorials, you will become familiar with key
concepts and best practices for usingTensorKrowch. You will learn how to
defineNodes, create connections between through theirEdges, and
configure theTensorNetworkstructure. This hands-on approach will greatly
enhance your understanding and proficiency withTensorKrowch.First Steps with TensorKrowchCreating a Tensor Network in TensorKrowchContracting and Differentiating the Tensor NetworkHow to save Memory and Time with TensorKrowch (ADVANCED)The different Types of Nodes (ADVANCED)How to subclass TensorNetwork to build Custom ModelsCreating a Hybrid Neural-Tensor Network ModelLicenseTensorKrowch is licensed under the MIT License. Please see theLICENSEfile for more information.Citing