Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .JuliaFormatter.toml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ concurrency:

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
name: Julia ${{ matrix.version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
workflow_dispatch:

jobs:
build:
Documentation:
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down
51 changes: 11 additions & 40 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,15 @@
name: FormatCheck
name: 'Format'

on:
push:
branches:
- 'main'
- 'master'
- 'release-'
tags: '*'
pull_request:
pull_request_target:
paths: ['**/*.jl']
types: [opened, synchronize, reopened, ready_for_review]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
version:
- '1' # automatically expands to the latest stable 1.x release of Julia
os:
- ubuntu-latest
steps:
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.version }}
permissions:
contents: read
actions: write
pull-requests: write

- uses: actions/checkout@v5
- name: Install JuliaFormatter and format
# This will use the latest version by default but you can set the version like so:
#
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
run: |
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="1"))'
julia -e 'using JuliaFormatter; format(".", verbose=true)'
- name: Format check
run: |
julia -e '
out = Cmd(`git diff --name-only`) |> read |> String
if out == ""
exit(0)
else
@error "Some files have not been formatted !!!"
write(stdout, out)
exit(1)
end'
jobs:
formatcheck:
uses: "QuantumKitHub/QuantumKitHubActions/.github/workflows/FormatCheck.yml@main"
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/fredrikekre/runic-pre-commit
rev: v2.0.1
hooks:
- id: runic
16 changes: 9 additions & 7 deletions benchmark/TensorKitBenchmarks/TensorKitBenchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ BenchmarkTools.DEFAULT_PARAMETERS.memory_tolerance = 0.01

const PARAMS_PATH = joinpath(@__DIR__, "etc", "params.json")
const SUITE = BenchmarkGroup()
const MODULES = Dict("linalg" => :LinalgBenchmarks,
"indexmanipulations" => :IndexManipulationBenchmarks,
"tensornetworks" => :TensorNetworkBenchmarks)
const MODULES = Dict(
"linalg" => :LinalgBenchmarks,
"indexmanipulations" => :IndexManipulationBenchmarks,
"tensornetworks" => :TensorNetworkBenchmarks
)

load!(id::AbstractString; kwargs...) = load!(SUITE, id; kwargs...)

function load!(group::BenchmarkGroup, id::AbstractString; tune::Bool=false)
function load!(group::BenchmarkGroup, id::AbstractString; tune::Bool = false)
modsym = MODULES[id]
modpath = joinpath(dirname(@__FILE__), id, "$(modsym).jl")
Core.eval(@__MODULE__, :(include($modpath)))
Expand All @@ -33,14 +35,14 @@ end

loadall!(; kwargs...) = loadall!(SUITE; kwargs...)

function loadall!(group::BenchmarkGroup; verbose::Bool=true, tune::Bool=false)
function loadall!(group::BenchmarkGroup; verbose::Bool = true, tune::Bool = false)
for id in keys(MODULES)
if verbose
print("loading group $(repr(id))... ")
time = @elapsed load!(group, id, tune=false)
time = @elapsed load!(group, id, tune = false)
println("done (took $time seconds)")
else
load!(group, id; tune=false)
load!(group, id; tune = false)
end
end
if tune
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ function benchmark_permute!(benchgroup, params::Dict)
end
return nothing
end
function benchmark_permute!(bench; sigmas=nothing, T="Float64", I="Trivial", dims, p)
function benchmark_permute!(bench; sigmas = nothing, T = "Float64", I = "Trivial", dims, p)
T_ = parse_type(T)
I_ = parse_type(I)

p_ = (Tuple(p[1]), Tuple(p[2]))
Vs = generate_space.(I_, dims, sigmas)

codomain = mapreduce(Base.Fix1(getindex, Vs), ⊗, p_[1]; init=one(eltype(Vs)))
domain = mapreduce(Base.Fix1(getindex, Vs), ⊗, p_[2]; init=one(eltype(Vs)))
codomain = mapreduce(Base.Fix1(getindex, Vs), ⊗, p_[1]; init = one(eltype(Vs)))
domain = mapreduce(Base.Fix1(getindex, Vs), ⊗, p_[2]; init = one(eltype(Vs)))
init() = init_permute_tensors(T_, codomain ← domain, p_)

bench[T, I, dims, sigmas, p] = @benchmarkable permute!(C, A, $p_) setup = ((C, A) = $init())
Expand Down
4 changes: 2 additions & 2 deletions benchmark/TensorKitBenchmarks/linalg/LinalgBenchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function benchmark_mul!(benchgroup, params::Dict)
return nothing
end

function benchmark_mul!(bench; sigmas=nothing, T="Float64", I="Trivial", dims)
function benchmark_mul!(bench; sigmas = nothing, T = "Float64", I = "Trivial", dims)
T_ = parse_type(T)
I_ = parse_type(I)

Expand Down Expand Up @@ -62,7 +62,7 @@ function benchmark_svd!(benchgroup, params::Dict)
end
return nothing
end
function benchmark_svd!(bench; sigmas=nothing, T="Float64", I="Trivial", dims)
function benchmark_svd!(bench; sigmas = nothing, T = "Float64", I = "Trivial", dims)
T_ = parse_type(T)
I_ = parse_type(I)
Vs = generate_space.(I_, dims, sigmas)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function benchmark_mpo!(benchgroup, params::Dict)
end
return nothing
end
function benchmark_mpo!(bench; sigmas=nothing, T="Float64", I="Trivial", dims)
function benchmark_mpo!(bench; sigmas = nothing, T = "Float64", I = "Trivial", dims)
T_ = parse_type(T)
I_ = parse_type(I)

Expand Down Expand Up @@ -64,8 +64,8 @@ end

function benchmark_pepo(A, P, FL, FD, FR, FU)
return @tensor FL[18, 7, 4, 2, 1] * FU[1, 3, 6, 9, 10] * A[2, 17, 5, 3, 11] *
P[4, 16, 8, 5, 6, 12] * conj(A[7, 15, 8, 9, 13]) *
FR[10, 11, 12, 13, 14] * FD[14, 15, 16, 17, 18]
P[4, 16, 8, 5, 6, 12] * conj(A[7, 15, 8, 9, 13]) *
FR[10, 11, 12, 13, 14] * FD[14, 15, 16, 17, 18]
end

function benchmark_pepo!(benchgroup, params::Dict)
Expand All @@ -76,7 +76,7 @@ function benchmark_pepo!(benchgroup, params::Dict)
end
return nothing
end
function benchmark_pepo!(bench; sigmas=nothing, T="Float64", I="Trivial", dims)
function benchmark_pepo!(bench; sigmas = nothing, T = "Float64", I = "Trivial", dims)
T_ = parse_type(T)
I_ = parse_type(I)

Expand Down Expand Up @@ -105,11 +105,18 @@ function init_mera_tensors(T, V)
end

function benchmark_mera(u, w, ρ, h)
return @tensor (((((((h[9, 3, 4, 5, 1, 2] * u[1, 2, 7, 12]) * conj(u[3, 4, 11, 13])) *
(u[8, 5, 15, 6] * w[6, 7, 19])) *
(conj(u[8, 9, 17, 10]) * conj(w[10, 11, 22]))) *
((w[12, 14, 20] * conj(w[13, 14, 23])) * ρ[18, 19, 20, 21, 22, 23])) *
w[16, 15, 18]) * conj(w[16, 17, 21]))
return @tensor (
(
(
(
(
((h[9, 3, 4, 5, 1, 2] * u[1, 2, 7, 12]) * conj(u[3, 4, 11, 13])) *
(u[8, 5, 15, 6] * w[6, 7, 19])
) * (conj(u[8, 9, 17, 10]) * conj(w[10, 11, 22]))
) * ((w[12, 14, 20] * conj(w[13, 14, 23])) * ρ[18, 19, 20, 21, 22, 23])
) * w[16, 15, 18]
) * conj(w[16, 17, 21])
)
end

function benchmark_mera!(benchgroup, params::Dict)
Expand All @@ -121,7 +128,7 @@ function benchmark_mera!(benchgroup, params::Dict)
return nothing
end

function benchmark_mera!(bench; sigmas=nothing, T="Float64", I="Trivial", dims)
function benchmark_mera!(bench; sigmas = nothing, T = "Float64", I = "Trivial", dims)
T_ = parse_type(T)
I_ = parse_type(I)

Expand Down
13 changes: 7 additions & 6 deletions benchmark/TensorKitBenchmarks/utils/BenchUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ using TensorKit
parse_type(x::String) = eval(Meta.parse(x))

function expand_kwargs(params::Dict)
const_params = NamedTuple(Symbol(key) => value
for (key, value) in params if !(value isa Vector))
const_params = NamedTuple(
Symbol(key) => value for (key, value) in params if !(value isa Vector)
)
nonconst_keys = Tuple(Symbol(key) for (key, value) in params if value isa Vector)
nonconst_vals = (value for value in values(params) if value isa Vector)
return Iterators.map(Iterators.product(nonconst_vals...)) do expanded_vals
Expand All @@ -22,15 +23,15 @@ end

Creates a (graded) vector space with sectortype `I` and total dimension `D`, where the distribution of charges is controlled through a spread parameter `sigma`.
"""
function generate_space(::Type{Trivial}, D::Int, sigma::Nothing=nothing)
function generate_space(::Type{Trivial}, D::Int, sigma::Nothing = nothing)
return ComplexSpace(round(Int, D))
end
function generate_space(::Type{Z2Irrep}, D::Int, sigma::Real=0.5)
function generate_space(::Type{Z2Irrep}, D::Int, sigma::Real = 0.5)
D_even = ceil(Int, sigma * D)
D_odd = D - D_even
return Z2Space(0 => D_even, 1 => D_odd)
end
function generate_space(::Type{U1Irrep}, D::Int, sigma::Real=0.5)
function generate_space(::Type{U1Irrep}, D::Int, sigma::Real = 0.5)
# use ceil here to avoid getting stuck
normal_pdf = let D = D
x -> ceil(Int, D * exp(-0.5 * (x / sigma)^2) / (sigma * sqrt(2π)))
Expand All @@ -54,7 +55,7 @@ function generate_space(::Type{U1Irrep}, D::Int, sigma::Real=0.5)

return U1Space((s => d for (s, d) in zip(sectors, dims))...)
end
function generate_space(::Type{SU2Irrep}, D::Int, sigma::Real=0.5)
function generate_space(::Type{SU2Irrep}, D::Int, sigma::Real = 0.5)
normal_pdf = let D = D
x -> D * exp(-0.5 * (x / sigma)^2) / (sigma * sqrt(2π))
end
Expand Down
70 changes: 35 additions & 35 deletions benchmark/comparisons/benchtools.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
function distributeZ2(D; p=0.5)
function distributeZ2(D; p = 0.5)
D0 = ceil(Int, p * D)
D1 = D - D0
return [(0, D0), (1, D1)]
end

distributeU1(D; p=0.25) = distributeU1_poisson(D; p=p)
distributeU1(D; p = 0.25) = distributeU1_poisson(D; p = p)

function distributeU1_exponential(D; p=0.25)
function distributeU1_exponential(D; p = 0.25)
λ = (1 - p) / (1 + p)
D0 = ceil(Int, p * D)
if isodd(D - D0)
Expand All @@ -22,10 +22,10 @@ function distributeU1_exponential(D; p=0.25)
Drem -= 2 * Dn
n += 1
end
return sort!(sectors; by=first)
return sort!(sectors; by = first)
end

function distributeU1_poisson(D; p=0.25)
function distributeU1_poisson(D; p = 0.25)
λ = log((1 / p + 1) / 2)
D0 = ceil(Int, p * D)
if isodd(D - D0)
Expand All @@ -41,42 +41,42 @@ function distributeU1_poisson(D; p=0.25)
Drem -= 2 * Dn
n += 1
end
return sort!(sectors; by=first)
return sort!(sectors; by = first)
end

module Timers
struct Timer{F,D<:Tuple}
f::F
argsref::Base.RefValue{D}
Timer(f, args...) = new{typeof(f),typeof(args)}(f, Ref(args))
end
struct Timer{F, D <: Tuple}
f::F
argsref::Base.RefValue{D}
Timer(f, args...) = new{typeof(f), typeof(args)}(f, Ref(args))
end

@noinline donothing(arg) = arg
function (t::Timer)(; inner=1, outer=1)
args = t.argsref[]
f = t.f
f(args...) # run once to compile
times = zeros(Float64, (outer,))
gctimes = zeros(Float64, (outer,))
@inbounds for i in 1:outer
if inner == 1
gcstart = Base.gc_num()
start = Base.time_ns()
donothing(f(args...))
stop = Base.time_ns()
gcstop = Base.gc_num()
else
gcstart = Base.gc_num()
start = Base.time_ns()
for _ in 1:inner
@noinline donothing(arg) = arg
function (t::Timer)(; inner = 1, outer = 1)
args = t.argsref[]
f = t.f
f(args...) # run once to compile
times = zeros(Float64, (outer,))
gctimes = zeros(Float64, (outer,))
@inbounds for i in 1:outer
if inner == 1
gcstart = Base.gc_num()
start = Base.time_ns()
donothing(f(args...))
stop = Base.time_ns()
gcstop = Base.gc_num()
else
gcstart = Base.gc_num()
start = Base.time_ns()
for _ in 1:inner
donothing(f(args...))
end
stop = Base.time_ns()
gcstop = Base.gc_num()
end
stop = Base.time_ns()
gcstop = Base.gc_num()
times[i] = (stop - start) / (1.0e9) / inner
gctimes[i] = Base.GC_Diff(gcstop, gcstart).total_time / 1.0e9 / inner
end
times[i] = (stop - start) / (1e9) / inner
gctimes[i] = Base.GC_Diff(gcstop, gcstart).total_time / 1e9 / inner
return times, gctimes
end
return times, gctimes
end
end
Loading