Skip to content
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

Refactor Ansatz to be a concrete type with lattice information #223

Open
wants to merge 30 commits into
base: master
Choose a base branch
from

Conversation

mofeing
Copy link
Member

@mofeing mofeing commented Oct 26, 2024

As discussed offline, we decided to slice #204 into smaller PRs. This first PR makes Ansatz a concrete type with lattice information contained in a graph.

The important thing you should review is the API, not the details; we can change the graph type in the future but we want the API to be stable.

Changelog

  • Make Ansatz a concrete type in the type hierarchy.
    • Its abstract counterpart is AbstractAnsatz.
    • It adds Graphs and MetaGraphsNext as dependencies.
  • Delete Chain, Product, Grid and Dense
    • These will be re-added in subsequent PRs, adapted to the new Ansatz layer.
  • Make Form as the trait canonical form information.
  • Refactor some evolve! methods based on simple-update to simple_update! and generalize it for any AbstractAnsatz.

Notes

  • Currently there is a bug in Julia makes Enzyme crash on an Ansatz due to its field lattice being abstract active_reg_inner crashes on Tuple{X} where {X} EnzymeAD/Enzyme.jl#1923
    • It's fixed in Julia 1.11.0 and should be fixed in Julia 1.10.6 1.10.7
    • I temporarily fixed it by fixing Ansatz to just 1D connectivity (i.e. Site{1}) but I'm removing it now -> For the time being you will need Julia 1.11 if you want to diff an Ansatz
  • There are other bug fixes (like Base.in or GraphMakie.graphplot! on AbstractTensorNetwork) that I'm gonna remove now and move to other PRs.

@mofeing mofeing added refactor Change internals triage Needs group consensus breaking-change labels Oct 26, 2024
@mofeing mofeing requested review from a team, arturgs, jofrevalles and Todorbsc October 26, 2024 22:14
@@ -26,24 +26,9 @@ include("Ansatz/Ansatz.jl")
export Ansatz
export socket, Scalar, State, Operator
export boundary, Open, Periodic
export form

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not export it?

@jofrevalles
Copy link
Member

@mofeing @starsfordummies I think that when we talked about splitting the large PR into small ones, we meant that this PR would only contain the new Ansatz struct, and I see here that you pushed the commits regarding the canonical form, which IMO they should be in another PR. In this way, we can refactor the tests that are failing (like Chain, Dense, ...) in another PR.

@mofeing
Copy link
Member Author

mofeing commented Oct 29, 2024

@mofeing @starsfordummies I think that when we talked about splitting the large PR into small ones, we meant that this PR would only contain the new Ansatz struct, and I see here that you pushed the commits regarding the canonical form, which IMO they should be in another PR. In this way, we can refactor the tests that are failing (like Chain, Dense, ...) in another PR.

Sorry, but I don't agree. The Form trait is part of Ansatz, even if it doesn't have a field for that.

The other ansatzes will be reimplemented in subsequent PRs because tests had to be changed.

Copy link
Member

@jofrevalles jofrevalles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to have @test_skip instead of commenting all the tests.

@@ -8,35 +8,35 @@
@test issetequal(sites(tn), [site"1", site"2", site"1'", site"2'"])
@test Tenet.ntensors(tn) == 2

@testset "GHZ Circuit" begin
circuit_GHZ = chain(n_qubits, put(1 => Yao.H), Yao.control(1, 2 => Yao.X), Yao.control(2, 3 => Yao.X))
# @testset "GHZ Circuit" begin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# @testset "GHZ Circuit" begin
@test_skip begin #@testset "GHZ Circuit"

@@ -1,33 +1,33 @@
@testset "Product ansatz" begin
using LinearAlgebra
# @testset "Product ansatz" begin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# @testset "Product ansatz" begin
@test_skip begin # @testset "Product ansatz"

@@ -0,0 +1,2 @@
@testset "Ansatz" begin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on it.

- Either `threshold` or `maxdim` must be provided. If both are provided, `maxdim` is used.
- The bond must contain the Schmidt coefficients, i.e. a site canonization must be performed before calling `truncate!`.
"""
function truncate!(tn::AbstractAnsatz, bond; threshold=nothing, maxdim=nothing)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should have truncate only for Canonical or MixedCanonical now

@mofeing
Copy link
Member Author

mofeing commented Oct 29, 2024

I prefer to have @test_skip instead of commenting all the tests.

That's a valid request and a good idea. Will change it now and recover the deleted tests as @test_skip... The only thing is I'm not sure if it will still try to evaluate the code, which will obviously crash because we're breaking the API. So maybe @test_broken but doesn't matter which.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change refactor Change internals triage Needs group consensus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants