This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using KrylovKit, Yao | |
""" | |
J1J2{D} | |
J1J2(size::Int...; J2::Real, periodic::Bool) -> J1J2 | |
D ∈ {1, 2} is the dimension target system. | |
""" | |
struct J1J2{D} | |
size::NTuple{D, Int} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#= | |
To use this script, please install Flux.jl first by typing `]add Flux` in a Julia REPL. | |
=# | |
import LinearAlgebra | |
using Flux.Tracker: @grad, data, track, TrackedTuple, TrackedArray | |
using Flux | |
import Flux.Tracker: _forward | |
""" | |
backward function for svd. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using OMEinsum, LinearAlgebra | |
using TupleTools | |
import OMEinsum: einsum! | |
"""The rule type used for dispatch.""" | |
struct EinRule{S} end | |
EinRule(S) = EinRule{S}() | |
global einsum_rules = NTuple{2, Any}[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# `]add OMEinsum#master` | |
# `]add TupleTools` | |
using OMEinsum | |
using CuArrays | |
using CUDAdrv | |
using CUDAnative, TupleTools | |
using OMEinsum: index_map, map_prod | |
using Base.Cartesian | |
using GPUArrays |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using TupleTools | |
using Base.Cartesian | |
using CuArrays, CUDAnative | |
""" | |
A naive implementation of `einsum!` | |
* `ixs`: input tensor indices, | |
* `xs`: input tensors, | |
* `iy`: output tensor indices, | |
* `y`: accumulated tensor, notice it is initialized to 0 as output! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# References | |
# * Yao: https://arxiv.org/abs/1912.10877 | |
# * ForwardDiff: https://arxiv.org/abs/1607.07892 | |
# * Tropical Numbers: https://en.wikipedia.org/wiki/Tropical_geometry | |
using ForwardDiff, Yao, LinearAlgebra | |
# define tropical numbers with the following property. | |
# x ⊕ y := max(x ,y) | |
# x ⊗ y := x + y | |
struct Tropical{T} <: Number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using NiLang, NiLang.AD | |
function f!(du, u, p, t) | |
y₁, y₂, y₃ = u | |
k₁, k₂, k₃ = p | |
du[1] = -k₁*y₁ + k₃*y₂*y₃ | |
du[2] = k₁*y₁ - k₃*y₂*y₃ - k₂*y₂^2 | |
du[3] = y₁ + y₂ + y₃ - 1 | |
return nothing | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### A Pluto.jl notebook ### | |
# v0.11.14 | |
using Markdown | |
using InteractiveUtils | |
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error). | |
macro bind(def, element) | |
quote | |
local el = $(esc(element)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Yao | |
using YaoBlocks | |
using YaoBlocks.ConstGate: TGate, SGate, TdagGate, SdagGate | |
function Base.show(io::IO, ::MIME"qasm/open", blk::AbstractBlock) | |
qcode = qasm(blk) | |
println(io, "OPENQASM 2.0") | |
maincode = pop!(qcode, "main") | |
for k in keys | |
println(io, qcode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 3 | |
3 1 | |
3 2 | |
4 4 | |
2 2 | |
5 4 | |
1 2 | |
5 2 | |
2 1 |
OlderNewer