Skip to content

Commit eca0523

Browse files
authored
Runic formatter (#293)
* Runic formatting * update actions and workflows
1 parent a7d2bbb commit eca0523

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2661
-2288
lines changed

.JuliaFormatter.toml

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ concurrency:
1515

1616
jobs:
1717
test:
18-
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
18+
name: Julia ${{ matrix.version }} - ${{ matrix.os }}
1919
runs-on: ${{ matrix.os }}
2020
strategy:
2121
fail-fast: false

.github/workflows/Documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
workflow_dispatch:
1212

1313
jobs:
14-
build:
14+
Documentation:
1515
runs-on: ${{ matrix.os }}
1616
strategy:
1717
matrix:

.github/workflows/FormatCheck.yml

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,15 @@
1-
name: FormatCheck
1+
name: 'Format'
22

33
on:
4-
push:
5-
branches:
6-
- 'main'
7-
- 'master'
8-
- 'release-'
9-
tags: '*'
10-
pull_request:
4+
pull_request_target:
5+
paths: ['**/*.jl']
6+
types: [opened, synchronize, reopened, ready_for_review]
117

12-
jobs:
13-
build:
14-
runs-on: ${{ matrix.os }}
15-
strategy:
16-
matrix:
17-
version:
18-
- '1' # automatically expands to the latest stable 1.x release of Julia
19-
os:
20-
- ubuntu-latest
21-
steps:
22-
- uses: julia-actions/setup-julia@latest
23-
with:
24-
version: ${{ matrix.version }}
8+
permissions:
9+
contents: read
10+
actions: write
11+
pull-requests: write
2512

26-
- uses: actions/checkout@v5
27-
- name: Install JuliaFormatter and format
28-
# This will use the latest version by default but you can set the version like so:
29-
#
30-
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
31-
run: |
32-
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="1"))'
33-
julia -e 'using JuliaFormatter; format(".", verbose=true)'
34-
- name: Format check
35-
run: |
36-
julia -e '
37-
out = Cmd(`git diff --name-only`) |> read |> String
38-
if out == ""
39-
exit(0)
40-
else
41-
@error "Some files have not been formatted !!!"
42-
write(stdout, out)
43-
exit(1)
44-
end'
13+
jobs:
14+
formatcheck:
15+
uses: "QuantumKitHub/QuantumKitHubActions/.github/workflows/FormatCheck.yml@main"

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
repos:
2+
- repo: https://github.com/fredrikekre/runic-pre-commit
3+
rev: v2.0.1
4+
hooks:
5+
- id: runic

benchmark/TensorKitBenchmarks/TensorKitBenchmarks.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ BenchmarkTools.DEFAULT_PARAMETERS.memory_tolerance = 0.01
1111

1212
const PARAMS_PATH = joinpath(@__DIR__, "etc", "params.json")
1313
const SUITE = BenchmarkGroup()
14-
const MODULES = Dict("linalg" => :LinalgBenchmarks,
15-
"indexmanipulations" => :IndexManipulationBenchmarks,
16-
"tensornetworks" => :TensorNetworkBenchmarks)
14+
const MODULES = Dict(
15+
"linalg" => :LinalgBenchmarks,
16+
"indexmanipulations" => :IndexManipulationBenchmarks,
17+
"tensornetworks" => :TensorNetworkBenchmarks
18+
)
1719

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

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

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

36-
function loadall!(group::BenchmarkGroup; verbose::Bool=true, tune::Bool=false)
38+
function loadall!(group::BenchmarkGroup; verbose::Bool = true, tune::Bool = false)
3739
for id in keys(MODULES)
3840
if verbose
3941
print("loading group $(repr(id))... ")
40-
time = @elapsed load!(group, id, tune=false)
42+
time = @elapsed load!(group, id, tune = false)
4143
println("done (took $time seconds)")
4244
else
43-
load!(group, id; tune=false)
45+
load!(group, id; tune = false)
4446
end
4547
end
4648
if tune

benchmark/TensorKitBenchmarks/indexmanipulations/IndexManipulationBenchmarks.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ function benchmark_permute!(benchgroup, params::Dict)
2525
end
2626
return nothing
2727
end
28-
function benchmark_permute!(bench; sigmas=nothing, T="Float64", I="Trivial", dims, p)
28+
function benchmark_permute!(bench; sigmas = nothing, T = "Float64", I = "Trivial", dims, p)
2929
T_ = parse_type(T)
3030
I_ = parse_type(I)
3131

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

35-
codomain = mapreduce(Base.Fix1(getindex, Vs), , p_[1]; init=one(eltype(Vs)))
36-
domain = mapreduce(Base.Fix1(getindex, Vs), , p_[2]; init=one(eltype(Vs)))
35+
codomain = mapreduce(Base.Fix1(getindex, Vs), , p_[1]; init = one(eltype(Vs)))
36+
domain = mapreduce(Base.Fix1(getindex, Vs), , p_[2]; init = one(eltype(Vs)))
3737
init() = init_permute_tensors(T_, codomain domain, p_)
3838

3939
bench[T, I, dims, sigmas, p] = @benchmarkable permute!(C, A, $p_) setup = ((C, A) = $init())

benchmark/TensorKitBenchmarks/linalg/LinalgBenchmarks.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function benchmark_mul!(benchgroup, params::Dict)
2828
return nothing
2929
end
3030

31-
function benchmark_mul!(bench; sigmas=nothing, T="Float64", I="Trivial", dims)
31+
function benchmark_mul!(bench; sigmas = nothing, T = "Float64", I = "Trivial", dims)
3232
T_ = parse_type(T)
3333
I_ = parse_type(I)
3434

@@ -62,7 +62,7 @@ function benchmark_svd!(benchgroup, params::Dict)
6262
end
6363
return nothing
6464
end
65-
function benchmark_svd!(bench; sigmas=nothing, T="Float64", I="Trivial", dims)
65+
function benchmark_svd!(bench; sigmas = nothing, T = "Float64", I = "Trivial", dims)
6666
T_ = parse_type(T)
6767
I_ = parse_type(I)
6868
Vs = generate_space.(I_, dims, sigmas)

benchmark/TensorKitBenchmarks/tensornetworks/TensorNetworkBenchmarks.jl

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function benchmark_mpo!(benchgroup, params::Dict)
3232
end
3333
return nothing
3434
end
35-
function benchmark_mpo!(bench; sigmas=nothing, T="Float64", I="Trivial", dims)
35+
function benchmark_mpo!(bench; sigmas = nothing, T = "Float64", I = "Trivial", dims)
3636
T_ = parse_type(T)
3737
I_ = parse_type(I)
3838

@@ -64,8 +64,8 @@ end
6464

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

7171
function benchmark_pepo!(benchgroup, params::Dict)
@@ -76,7 +76,7 @@ function benchmark_pepo!(benchgroup, params::Dict)
7676
end
7777
return nothing
7878
end
79-
function benchmark_pepo!(bench; sigmas=nothing, T="Float64", I="Trivial", dims)
79+
function benchmark_pepo!(bench; sigmas = nothing, T = "Float64", I = "Trivial", dims)
8080
T_ = parse_type(T)
8181
I_ = parse_type(I)
8282

@@ -105,11 +105,18 @@ function init_mera_tensors(T, V)
105105
end
106106

107107
function benchmark_mera(u, w, ρ, h)
108-
return @tensor (((((((h[9, 3, 4, 5, 1, 2] * u[1, 2, 7, 12]) * conj(u[3, 4, 11, 13])) *
109-
(u[8, 5, 15, 6] * w[6, 7, 19])) *
110-
(conj(u[8, 9, 17, 10]) * conj(w[10, 11, 22]))) *
111-
((w[12, 14, 20] * conj(w[13, 14, 23])) * ρ[18, 19, 20, 21, 22, 23])) *
112-
w[16, 15, 18]) * conj(w[16, 17, 21]))
108+
return @tensor (
109+
(
110+
(
111+
(
112+
(
113+
((h[9, 3, 4, 5, 1, 2] * u[1, 2, 7, 12]) * conj(u[3, 4, 11, 13])) *
114+
(u[8, 5, 15, 6] * w[6, 7, 19])
115+
) * (conj(u[8, 9, 17, 10]) * conj(w[10, 11, 22]))
116+
) * ((w[12, 14, 20] * conj(w[13, 14, 23])) * ρ[18, 19, 20, 21, 22, 23])
117+
) * w[16, 15, 18]
118+
) * conj(w[16, 17, 21])
119+
)
113120
end
114121

115122
function benchmark_mera!(benchgroup, params::Dict)
@@ -121,7 +128,7 @@ function benchmark_mera!(benchgroup, params::Dict)
121128
return nothing
122129
end
123130

124-
function benchmark_mera!(bench; sigmas=nothing, T="Float64", I="Trivial", dims)
131+
function benchmark_mera!(bench; sigmas = nothing, T = "Float64", I = "Trivial", dims)
125132
T_ = parse_type(T)
126133
I_ = parse_type(I)
127134

benchmark/TensorKitBenchmarks/utils/BenchUtils.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ using TensorKit
88
parse_type(x::String) = eval(Meta.parse(x))
99

1010
function expand_kwargs(params::Dict)
11-
const_params = NamedTuple(Symbol(key) => value
12-
for (key, value) in params if !(value isa Vector))
11+
const_params = NamedTuple(
12+
Symbol(key) => value for (key, value) in params if !(value isa Vector)
13+
)
1314
nonconst_keys = Tuple(Symbol(key) for (key, value) in params if value isa Vector)
1415
nonconst_vals = (value for value in values(params) if value isa Vector)
1516
return Iterators.map(Iterators.product(nonconst_vals...)) do expanded_vals
@@ -22,15 +23,15 @@ end
2223
2324
Creates a (graded) vector space with sectortype `I` and total dimension `D`, where the distribution of charges is controlled through a spread parameter `sigma`.
2425
"""
25-
function generate_space(::Type{Trivial}, D::Int, sigma::Nothing=nothing)
26+
function generate_space(::Type{Trivial}, D::Int, sigma::Nothing = nothing)
2627
return ComplexSpace(round(Int, D))
2728
end
28-
function generate_space(::Type{Z2Irrep}, D::Int, sigma::Real=0.5)
29+
function generate_space(::Type{Z2Irrep}, D::Int, sigma::Real = 0.5)
2930
D_even = ceil(Int, sigma * D)
3031
D_odd = D - D_even
3132
return Z2Space(0 => D_even, 1 => D_odd)
3233
end
33-
function generate_space(::Type{U1Irrep}, D::Int, sigma::Real=0.5)
34+
function generate_space(::Type{U1Irrep}, D::Int, sigma::Real = 0.5)
3435
# use ceil here to avoid getting stuck
3536
normal_pdf = let D = D
3637
x -> ceil(Int, D * exp(-0.5 * (x / sigma)^2) / (sigma * sqrt(2π)))
@@ -54,7 +55,7 @@ function generate_space(::Type{U1Irrep}, D::Int, sigma::Real=0.5)
5455

5556
return U1Space((s => d for (s, d) in zip(sectors, dims))...)
5657
end
57-
function generate_space(::Type{SU2Irrep}, D::Int, sigma::Real=0.5)
58+
function generate_space(::Type{SU2Irrep}, D::Int, sigma::Real = 0.5)
5859
normal_pdf = let D = D
5960
x -> D * exp(-0.5 * (x / sigma)^2) / (sigma * sqrt(2π))
6061
end

0 commit comments

Comments
 (0)