-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Contraction path optimization with EinExprs #120
Conversation
Thanks for opening this!
|
As an example. The following
returns
telling you to first contract the tensors on sites |
Thanks @mofeing, seems like this will be good to have. Currently we use OMEinsumContractionOrders.jl as a backend, how does that compare to Adding on to Joey's comments:
|
In comparison with There is also some support for slicing and visualization so users can see where the cost of their tensor networks is going to be spent before the execution.
Okay, great. But I see that you use a kind of "dynamic" check for loading packages using
mmm so 2 indices with the same |
The only reason we don't use package extensions right now for Yeah, ITensor indices can have the same ID but if they have different prime levels or tags they won't compare equal. Distinguishing indices by either IDs, prime levels, or tags can be convenient in different situations (for example we have a convention that operators distinguish bra and ket spaces using prime levels, which is much more convenient than distinguishing them by IDs which are randomly generated). |
ah ok, then should I use |
|
mmm then the |
Maybe, though it seems like there can still be hash collisions: https://docs.julialang.org/en/v1/base/base/#Base.objectid. |
I'm picturing something like this: julia> using ITensors
julia> i, j, k = Index.((2, 2, 2))
((dim=2|id=45), (dim=2|id=388), (dim=2|id=489))
julia> symbols = Dict{Index,Symbol}()
Dict{Index, Symbol}()
julia> using Random
julia> get!(symbols, i, Symbol(randstring()))
:maCJxbai
julia> get!(symbols, j, Symbol(randstring()))
:bfRnBZjQ
julia> get!(symbols, k, Symbol(randstring()))
:wiM0i2Oe
julia> get!(symbols, i, Symbol(randstring()))
:maCJxbai
julia> symbols
Dict{Index, Symbol} with 3 entries:
(dim=2|id=489) => :wiM0i2Oe
(dim=2|id=388) => :bfRnBZjQ
(dim=2|id=45) => :maCJxbai Another option is to make a unique vector of all ITensor indices (say with julia> inds = unique([i, j, k, k])
3-element Vector{Index{Int64}}:
(dim=2|id=45)
(dim=2|id=388)
(dim=2|id=489)
julia> symbols = Symbol.(eachindex(inds))
3-element Vector{Symbol}:
Symbol("1")
Symbol("2")
Symbol("3")
julia> inds[parse(Int, String(symbols[2]))]
(dim=2|id=388) |
okay, will try to refactor based on your examples. what should I use to get the full list of indices of the TN? |
|
@JoeyT1994 does that make a flat list of indices ( I think that is probably the most succinct way for now. |
Actually I see |
Though the definition of |
@mtfishman #123 should hopefully fix that and export those functions? |
I parametrized the label type in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mofeing ! I think we could follow the pattern we have for OMEinsumContractionOrders
here and put this code in a file src/requires/EinExprs.jl
Then you can write a function in src/contraction_sequences
which checks the EinExprs.jl
module exist and then passes to this function ?
That way we don't need EinExprs.jl
in the dependencies at all and can just add it to src/test/Project.toml
as a required dependency for testing.
Also could you then add to |
From #120 (comment), I understood you wanted it as a package extension. Currently it's set as a weakdep. |
Ah yes good point. @mtfishman what do you think? Shall we have this as a package extension as it is currently? And then in a future PR also switch |
The error that CI is throwing now is: ERROR: LoadError: UndefVarError: `@Algorithm_str` not defined
Stacktrace:
[1] top-level scope
@ :0
[2] include
@ Base ./Base.jl:495 [inlined]
[3] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::String)
@ Base ./loading.jl:2216
[4] top-level scope
@ stdin:3
in expression starting at /home/runner/work/ITensorNetworks.jl/ITensorNetworks.jl/ext/ITensorNetworksEinExprsExt/ITensorNetworksEinExprsExt.jl:36
in expression starting at /home/runner/work/ITensorNetworks.jl/ITensorNetworks.jl/ext/ITensorNetworksEinExprsExt/ITensorNetworksEinExprsExt.jl:1
in expression starting at stdin:3
#... since |
@mofeing at least now |
I moved KaHyPar to a package extension and bumped the patch version. |
@mofeing still more test failures due to bugs caused by the refactor. |
Great, thanks. I think that is a good move. |
Co-authored-by: Matt Fishman <[email protected]>
The error in "Julia 1" should be solved, but I can't figure out why this error is happening in "Julia 1.7". https://github.com/mtfishman/ITensorNetworks.jl/actions/runs/7887034139/job/21524035311 |
From what I can see you haven't added and set up PackageExtensionCompat.jl in this PR so the package extension won't work on Julia versions below 1.9. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #120 +/- ##
==========================================
+ Coverage 72.73% 73.43% +0.69%
==========================================
Files 68 69 +1
Lines 3947 4062 +115
==========================================
+ Hits 2871 2983 +112
- Misses 1076 1079 +3 ☔ View full report in Codecov by Sentry. |
Ahh, I misunderstood you. I thought you refer to Now should be fixed. |
Right, both |
The CI failures on Julia 1.7 are the same ones on |
Thanks @mtfishman for the reviewing and @mofeing for the PR. Lets set up a call to discuss running some timing tests to compare |
This is an ongoing work with @JoeyT1994 to add support for contraction path optimization using EinExprs.jl. It is a lightweight package ONLY for contraction path optimization. Inspired by
opt_einsum
andcotengra
Python packages, but with more effort spent on simplicity and performance (algorithms occupy 10s of lines and are easy to comprehend).KaHyPar.jl
an optional dependency ofEinExprs.jl
, since it is not available for Windows so the extension fails to load since it is looking for a library that doesn't exist.EinExprs
is not yet in the General registry, so the @bsc-quantic registry has to be added. We are working towards moving it to the General registry for the next release.EinExprs
has been moved to the General registry.This is a WIP, not yet ready to be merged.@JoeyT1994 I have a couple of questions:
Symbol
s. Since anIndex
has no name, it is ok if I use theid
?ITensorNetwork
?contraction_sequence
?