{"id":21231955,"url":"https://github.com/bsc-quantic/tn4ml","last_synced_at":"2026-01-04T15:04:47.260Z","repository":{"id":251027810,"uuid":"513094561","full_name":"bsc-quantic/tn4ml","owner":"bsc-quantic","description":"Tensor Networks for Machine Learning","archived":false,"fork":false,"pushed_at":"2025-06-02T15:47:50.000Z","size":40075,"stargazers_count":18,"open_issues_count":1,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-02T18:56:29.763Z","etag":null,"topics":["flax","jax","machine-learning","matrix-product-states","optax","python","python3","quimb","tensor-network","tensor-networks"],"latest_commit_sha":null,"homepage":"https://tn4ml.readthedocs.io","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/bsc-quantic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2022-07-12T10:18:19.000Z","updated_at":"2025-06-02T15:47:54.000Z","dependencies_parsed_at":"2024-09-09T14:19:14.203Z","dependency_job_id":"8d5a0868-4a13-401b-aa5c-ed792e6c2902","html_url":"https://github.com/bsc-quantic/tn4ml","commit_stats":null,"previous_names":["bsc-quantic/tn4ml"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/bsc-quantic/tn4ml","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsc-quantic%2Ftn4ml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsc-quantic%2Ftn4ml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsc-quantic%2Ftn4ml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsc-quantic%2Ftn4ml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bsc-quantic","download_url":"https://codeload.github.com/bsc-quantic/tn4ml/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsc-quantic%2Ftn4ml/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264618923,"owners_count":23638370,"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":["flax","jax","machine-learning","matrix-product-states","optax","python","python3","quimb","tensor-network","tensor-networks"],"created_at":"2024-11-20T23:48:59.548Z","updated_at":"2026-01-04T15:04:47.254Z","avatar_url":"https://github.com/bsc-quantic.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"docs/_static/logo_light.png\" position=\"center\" alt=\"logo\" width=\"300\" height=\"200\"\u003e\n\n# Tensor Networks for Machine Learning\n![Static Badge](https://img.shields.io/badge/tests-passing-blue)\n![Static Badge](https://img.shields.io/badge/docs-passing-green)\u003cbr\u003e\n**tn4ml** is a Python library that handles tensor networks for machine learning applications.\u003cbr\u003e\nIt is built on top of **Quimb**, for Tensor Network objects, and **JAX**, for optimization pipeline.\u003cbr\u003e\nFor now, the library supports 1D Tensor Network structures: \n- **Matrix Product State**\n- **Matrix Product Operator**\n- **Spaced Matrix Product Operator**\n\nIt supports different **embedding** functions, **initialization** techniques, **objective functions** and **optimization strategies**.\u003cbr\u003e\n\n## Installation\n\nFirst create a virtualenv using `pyenv` or `conda`. Then install the package and its dependencies.\n\u003cbr\u003e\n\n**With** `pip` (tag v1.0.5):\n```bash\npip install tn4ml\n```\n\u003cbr\u003e\n\nor **directly from github**:\n```bash\npip install -U git+https://github.com/bsc-quantic/tn4ml.git\n```\n\u003cbr\u003e\n\nIf you want to test and edit the code, you can clone the local version of the package and install it.\n```bash\ngit clone https://github.com/bsc-quantic/tn4ml.git\npip install -e tn4ml/\n```\nIf you want to install dependices for *docs*, *test* and *examples*:\n\n```zsh\npip install \"tn4ml[docs]\"\n```\n```zsh\npip install \"tn4ml[test]\"\n```\n```zsh\npip install \"tn4ml[examples]\"\n```\n\n\n**Accelerated runtime** \u003cbr\u003e\n\n(Optional) To improve runtime precision set these flags:\n```python\njax.config.update(\"jax_enable_x64\", True)\njax.config.update('jax_default_matmul_precision', 'highest')\n```\n\n**Running on GPU**\u003cbr\u003e\nBefore everything install `JAX` version that supports CUDA and its suitable for runs on GPU.\u003cbr\u003e\nCheckout how to install here: [jax[cuda]](https://docs.jax.dev/en/latest/installation.html#pip-installation-nvidia-gpu-cuda-installed-via-pip-easier) \u003cbr\u003e\n\nNext, at the beginning of your script set:\n```python\nimport os\nos.environ[\"CUDA_VISIBLE_DEVICES\"] = \"0\"  # Use GPU 0 - or set any GPU ID\nimport jax\njax.config.update(\"jax_platform_name\", 'gpu')\n```\nThen when training `Model` set:\n```python\ndevice = 'gpu'\nmodel.configure(device=device)\n```\n\n## Documentation\nVisit [tn4ml.readthedocs.io](https://tn4ml.readthedocs.io/en/latest/)\n\n## Example notebooks\n\n[TN for Classification](docs/source/examples/mnist_classification.ipynb)\u003cbr\u003e\n[TN for Anomaly Detection](docs/source/examples/mnist_ad.ipynb)\u003cbr\u003e\n[TN for Anomaly Detection with DMRG-like method](docs/source/examples/mnist_ad_sweeps.ipynb)\n\n## Examples from the paper\n[Breast Cancer Classification](docs/source/examples/supervised)\u003cbr\u003e\n[Unsupervised Learning with MNIST](docs/source/examples/unsupervised)\u003cbr\u003e\n[MPS for Anomaly Detection in the Latent Space of Proton Collision Events at the LHC](docs/source/examples/tnad_latent)\n\n\n## Citation\n\nIf you use **tn4ml** in your work, please cite the following paper: [arXiv:2502.13090](https://arxiv.org/abs/2502.13090)\n\n```bibtex\n@article{puljak2025tn4mltensornetworktraining,\n      title={tn4ml: Tensor Network Training and Customization for Machine Learning}, \n      author={Ema Puljak and Sergio Sanchez-Ramirez and Sergi Masot-Llima and Jofre Vallès-Muns and Artur Garcia-Saez and Maurizio Pierini},\n      year={2025},\n      eprint={2502.13090},\n      archivePrefix={arXiv},\n      primaryClass={cs.LG},\n      url={https://arxiv.org/abs/2502.13090}, \n      }\n```\n\n\n## License\nMIT license - check it out [here](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsc-quantic%2Ftn4ml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbsc-quantic%2Ftn4ml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsc-quantic%2Ftn4ml/lists"}