{"id":32157523,"url":"https://github.com/under-peter/omeinsum.jl","last_synced_at":"2025-12-26T12:01:47.583Z","repository":{"id":34991513,"uuid":"186152981","full_name":"under-Peter/OMEinsum.jl","owner":"under-Peter","description":"One More Einsum for Julia! With runtime order-specification and high-level adjoints for AD","archived":false,"fork":false,"pushed_at":"2025-10-06T02:21:59.000Z","size":2523,"stargazers_count":203,"open_issues_count":11,"forks_count":29,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-11-21T16:16:49.977Z","etag":null,"topics":["automatic-differentiation","contraction","einsum"],"latest_commit_sha":null,"homepage":"https://under-peter.github.io/OMEinsum.jl/dev/","language":"Julia","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/under-Peter.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-05-11T15:56:47.000Z","updated_at":"2025-10-06T02:17:51.000Z","dependencies_parsed_at":"2023-02-12T20:45:37.868Z","dependency_job_id":"86e4bff2-4ce8-456e-ac19-4e72aa271e93","html_url":"https://github.com/under-Peter/OMEinsum.jl","commit_stats":{"total_commits":160,"total_committers":9,"mean_commits":17.77777777777778,"dds":0.44375,"last_synced_commit":"73e7c27b8358334284ba1f690a5ba007d2bf6610"},"previous_names":[],"tags_count":49,"template":false,"template_full_name":null,"purl":"pkg:github/under-Peter/OMEinsum.jl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/under-Peter%2FOMEinsum.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/under-Peter%2FOMEinsum.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/under-Peter%2FOMEinsum.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/under-Peter%2FOMEinsum.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/under-Peter","download_url":"https://codeload.github.com/under-Peter/OMEinsum.jl/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/under-Peter%2FOMEinsum.jl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28054229,"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","status":"online","status_checked_at":"2025-12-26T02:00:06.189Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["automatic-differentiation","contraction","einsum"],"created_at":"2025-10-21T12:50:23.176Z","updated_at":"2025-12-26T12:01:47.571Z","avatar_url":"https://github.com/under-Peter.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- # OMEinsum --\u003e\n\u003cdiv align=\"center\"\u003e \u003cimg\nsrc=\"ome-logo.png\"\nalt=\"OMEinsum logo\" width=\"510\"\u003e\u003c/img\u003e\n\u003ch1\u003eOMEinsum - One More Einsum\u003c/h1\u003e\n\u003c/div\u003e\n\n[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://under-Peter.github.io/OMEinsum.jl/dev)\n[![CI](https://github.com/under-Peter/OMEinsum.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/under-Peter/OMEinsum.jl/actions/workflows/ci.yml)\n[![Codecov](https://codecov.io/gh/under-Peter/OMEinsum.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/under-Peter/OMEinsum.jl)\n\nThis is a repository for the _Google Summer of Code_ project on *Differentiable Tensor Networks*.\nIt implements one function that both computer scientists and physicists love, the *Einstein summation*\n\n\u003cimg alt=\"einsum definition\" src=\"https://github.com/under-Peter/OMEinsum.jl/blob/master/docs/einsum_define.png?raw=true\" width=300/\u003e\n\nTo find out the details about einsum, please check out my [nextjournal-article](https://nextjournal.com/under-Peter/julia-summer-of-einsum) or the [numpy-manual](https://docs.scipy.org/doc/numpy/reference/generated/numpy.einsum.html).\n\nEinstein summation can be implemented in no more than 20 lines of Julia code, the automatic differentiation is also [straightforward](https://giggleliu.github.io/2019/04/02/einsumbp.html). The main effort of this package is improving the [performance](https://github.com/under-Peter/OMEinsum-Benchmarks) utilizing Julia [multiple dispatch on traits](https://white.ucc.asn.au/2018/10/03/Dispatch,-Traits-and-Metaprogramming-Over-Reflection.html). So that people can enjoy the speed of faster specific implementations like BLAS functions, `sum` and `permutedims` on both CPU and GPU without suffering from runtime overhead.\n\n*Note: why the test coverage is not 100%* - GPU-code coverage is not evaluated although we test the GPU code properly on gitlab. Ignoring the GPU-code, the actual coverage is at about _97%_.\n\n*Warning: since v0.4, OMEinsum does not optimize the contraction order anymore. One has to use nested einsum to specify the contraction order manually, e.g. `ein\"(ijk,jkl),klm-\u003eim\"(x, y, z)`.* Please check out the [documentation](https://under-Peter.github.io/OMEinsum.jl/dev/contractionorder/) for more details.\n\n## Install\n\nTo install, type `]` in a julia (\u003e=1.5) REPL and then input\n```julia pkg\npkg\u003e add OMEinsum\n```\n\n## Learn by Examples\nTo avoid runtime overhead, we recommend users to use [non-standard string literal](https://docs.julialang.org/en/v1/manual/metaprogramming/#Non-Standard-String-Literals-1) `@ein_str`. The following examples illustrates how `einsum` works\n\n```julia\njulia\u003e using OMEinsum, SymEngine\n\njulia\u003e catty = fill(Basic(:🐱), 2, 2)\n2×2 Array{Basic,2}:\n 🐱  🐱\n 🐱  🐱\n\njulia\u003e fish = fill(Basic(:🐟), 2, 3, 2)\n2×3×2 Array{Basic,3}:\n[:, :, 1] =\n 🐟  🐟  🐟\n 🐟  🐟  🐟\n\n[:, :, 2] =\n 🐟  🐟  🐟\n 🐟  🐟  🐟\n\njulia\u003e snake = fill(Basic(:🐍), 3, 3)\n3×3 Array{Basic,2}:\n 🐍  🐍  🐍\n 🐍  🐍  🐍\n 🐍  🐍  🐍\n\njulia\u003e medicine = ein\"ij,jki,kk-\u003ek\"(catty, fish, snake)\n3-element Array{Basic,1}:\n 4*🐱*🐍*🐟\n 4*🐱*🐍*🐟\n 4*🐱*🐍*🐟\n\njulia\u003e ein\"ik,kj -\u003e ij\"(catty, catty) # multiply two matrices `a` and `b`\n2×2 Array{Basic,2}:\n 2*🐱^2  2*🐱^2\n 2*🐱^2  2*🐱^2\n\njulia\u003e ein\"ij -\u003e \"(catty)[] # sum a matrix, output 0-dimensional array\n4*🐱\n\njulia\u003e ein\"-\u003eii\"(asarray(snake[1,1]), size_info=Dict('i'=\u003e5)) # get 5 x 5 identity matrix\n5×5 Array{Basic,2}:\n 🐍  0  0  0  0\n 0  🐍  0  0  0\n 0  0  🐍  0  0\n 0  0  0  🐍  0\n 0  0  0  0  🐍\n```\n\nAlternatively, people can specify the contraction with a construction approach, which is useful when the contraction code can only be obtained at run time\n```julia\njulia\u003e einsum(EinCode((('i','k'),('k','j')),('i','j')),(a,b))\n```\nor a macro based interface, `@ein` macro,\nwhich is closer to the standard way of writing einsum-operations in physics\n```julia\njulia\u003e @ein c[i,j] := a[i,k] * b[k,j];\n```\n\nIt is sometimes helpful to specify the order of operations, by inserting brackets, either because you know this will be more efficient,  or to help the computer see what kernels can be used.  For example:\n```julia\njulia\u003e @ein Z[o,s] := x[i,s] * (W[o,i,j] * y[j,s]);   # macro style\n\njulia\u003e Z = ein\"is, (oij, js) -\u003e os\"(x, W, y);         # string style\n```\nThis performs matrix multiplication (summing over `j`) \nfollowed by batched matrix multiplication (summing over `i`, batch label `s`). \nWithout the brackets, instead it uses the fallback `loop_einsum`, which is slower.\nCalling `allow_loops(false)` will print an error to help you spot such cases:\n```julia\njulia\u003e @ein Zl[o,s] := x[i,s] * W[o,i,j] * y[j,s];\n\njulia\u003e Z ≈ Zl\ntrue\n\njulia\u003e allow_loops(false);\n\njulia\u003e Zl = ein\"is, oij, js -\u003e os\"(x, W, y);\n┌ Error: using `loop_einsum` to evaluate\n│   code = is, oij, js -\u003e os\n│   size.(xs) = ((10, 50), (20, 10, 10), (10, 50))\n│   size(y) = (20, 50)\n└ @ OMEinsum ~/.julia/dev/OMEinsum/src/loop_einsum.jl:26\n```\n\n## GPU Acceleration\n\nOMEinsum supports CUDA GPU acceleration with two backends:\n\n| Backend | Library | Best For |\n|---------|---------|----------|\n| `DefaultBackend()` | CUBLAS | Matrix-like contractions |\n| `CuTensorBackend()` | cuTENSOR | General tensor contractions |\n\n```julia\nusing CUDA\nusing OMEinsum\n\nA = CUDA.rand(Float32, 100, 200)\nB = CUDA.rand(Float32, 200, 300)\n\n# Default backend (CUBLAS) - good for matrix-like operations\nC = ein\"ij,jk-\u003eik\"(A, B)\n```\n\nFor better performance on non-GEMM patterns (tensor networks, etc.), use the cuTENSOR backend:\n\n```julia\nusing CUDA\nusing cuTENSOR  # Pkg.add(\"cuTENSOR\") - loads the CuTENSORExt extension\nusing OMEinsum\n\nset_einsum_backend!(CuTensorBackend())\nC = ein\"ijk,jkl-\u003eil\"(CUDA.rand(Float32, 64, 64, 64), CUDA.rand(Float32, 64, 64, 64))\n```\n\nThe cuTENSOR backend provides native tensor contraction without reshape/permute overhead. See the [CUDA documentation](https://under-Peter.github.io/OMEinsum.jl/dev/cuda/) for details.\n\n## Comparison with other packages\nSimilar packages include:\n- [TensorOperations.jl](https://github.com/Jutho/TensorOperations.jl) and [TensorKit.jl](https://github.com/Jutho/TensorKit.jl)\n- [ITensors.jl](https://github.com/ITensor/ITensors.jl)\n\nComparing with the above packages, `OMEinsum` is optimized over large scale tensor network (or einsum, sum-product network) contraction.\n\n## Contribute\n\nSuggestions and Comments in the [_Issues_](https://github.com/under-Peter/OMEinsum.jl/issues) are welcome.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funder-peter%2Fomeinsum.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funder-peter%2Fomeinsum.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funder-peter%2Fomeinsum.jl/lists"}