Giter Site home page Giter Site logo

itensorsgrad.jl's Introduction

⚠️ INFO: This repository is deprecated

The functionality of ITensorsGrad has been moved into the monorepo at ITensors.jl. It is loaded by default when the ITensors package is imported.

ITensorsGrad

This extends the ITensors.jl library to make operations involving ITensors differentiable.

It uses ChainRulesCore to define reverse-mode AD rules for differentiating basic ITensor operations, like contraction, addition, priming, tagging, and construction from arrays. Then, if an AD library like Zygote.jl is used that recognizes rules written with the ChainRules interface, functions making use of those ITensor operations that we currently support will be differentiable.

For example:

using ITensors
using ITensorsGrad
using Zygote

function f(x)
  i = Index(2, "i")
  T = itensor([exp(-x) exp(x); exp(x) exp(-x)], i', dag(i))
  Z = T'' * T' * T
  Z *= δ(dag(inds(Z))) 
  return (Z[])^(1//3)
end

x = 0.3
@show f(x)
@show f'(x)

returns:

f(x) = 2.0733047296286964
(f')(x) = 0.4388827959004289

We can compare against the result obtained from finite differencing:

using FiniteDifferences
function FiniteDifferences.to_vec(A::ITensor)
  function vec_to_ITensor(x)
    return isempty(inds(A)) ? ITensor(x[]) : itensor(x, inds(A))
  end
  return vec(array(A)), vec_to_ITensor
end

@show gradient(f, x)[1]

returns:

(gradient(f, x))[1] = 0.4388827959004289

Limitations

For now, this package does not yet support tensor decompositions like SVD or QR. Stay tuned!

The same functionality is available in ITensorNetworkAD.jl, which will also provide more network-level optimizations of tensor contractions and derivatives through tensor contractions and for now will be more actively developed.

itensorsgrad.jl's People

Contributors

mtfishman avatar github-actions[bot] avatar

Stargazers

Han Meh avatar Samuele Piccinelli avatar Linjian Ma avatar Lei Wang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.