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.

70 changes: 11 additions & 59 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -1,63 +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
arch:
- x64
steps:
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}

- uses: actions/checkout@v5
- name: Install JuliaFormatter and format
run: |
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="v1"))'
julia -e 'using JuliaFormatter; format(".", verbose=true)'
- name: Format check
id: format
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'
- name: Create pull request
if: ${{ failure() && steps.format.conclusion == 'failure' }}
id: cpr
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Format .jl files
title: 'Automatic JuliaFormatter.jl run'
base: ${{ github.head_ref }}
branch: auto-juliaformatter-pr
delete-branch: true
labels: formatting, automated pr, no changelog
permissions:
contents: read
actions: write
pull-requests: write

- name: Check outputs
if: ${{ success() && steps.cpr.conclusion == 'success' }}
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
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
36 changes: 21 additions & 15 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
if Base.active_project() != joinpath(@__DIR__, "Project.toml")
using Pkg
Pkg.activate(@__DIR__)
Pkg.develop(PackageSpec(; path=(@__DIR__) * "/../"))
Pkg.develop(PackageSpec(; path = (@__DIR__) * "/../"))
Pkg.resolve()
Pkg.instantiate()
end
Expand All @@ -11,18 +11,24 @@ using Documenter
using MPSKitModels

makedocs(;
modules=[MPSKitModels],
sitename="MPSKitModels.jl",
authors="Maarten Vandamme",
format=Documenter.HTML(;
prettyurls=get(ENV, "CI", nothing) == "true",
mathengine=MathJax()),
pages=["Home" => "index.md",
"Manual" => ["man/operators.md",
"man/mpoham.md",
"man/lattices.md",
"man/models.md"],
"Index" => "package_index.md"],
checkdocs=:public)
modules = [MPSKitModels],
sitename = "MPSKitModels.jl",
authors = "Maarten Vandamme",
format = Documenter.HTML(;
prettyurls = get(ENV, "CI", nothing) == "true",
mathengine = MathJax()
),
pages = [
"Home" => "index.md",
"Manual" => [
"man/operators.md",
"man/mpoham.md",
"man/lattices.md",
"man/models.md",
],
"Index" => "package_index.md",
],
checkdocs = :public
)

deploydocs(; repo="github.com/QuantumKitHub/MPSKitModels.jl.git")
deploydocs(; repo = "github.com/QuantumKitHub/MPSKitModels.jl.git")
10 changes: 5 additions & 5 deletions src/lattices/chains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A one dimensional infinite lattice with a unit cell containing `L` sites.
"""
struct InfiniteChain <: AbstractLattice{1}
L::Int
function InfiniteChain(L::Integer=1)
function InfiniteChain(L::Integer = 1)
return L > 0 ? new(L) : error("period should be positive ($L)")
end
end
Expand All @@ -19,15 +19,15 @@ A one-dimensional lattice of length `L`
"""
struct FiniteChain <: AbstractLattice{1}
L::Int
function FiniteChain(L::Integer=1)
function FiniteChain(L::Integer = 1)
return L > 0 ? new(L) : error("length should be positive ($L)")
end
end
Base.axes(chain::FiniteChain) = (1:(chain.L),)
Base.isfinite(::Type{FiniteChain}) = true
Base.isfinite(::FiniteChain) = true

const Chain = Union{InfiniteChain,FiniteChain}
const Chain = Union{InfiniteChain, FiniteChain}

vertices(chain::Chain) = LatticePoint.(1:(chain.L), Ref(chain))
nearest_neighbours(chain::InfiniteChain) = map(v -> v => v + 1, vertices(chain))
Expand All @@ -44,12 +44,12 @@ function bipartition(chain::Chain)
end

linearize_index(chain::InfiniteChain, i::Int) = i
linearize_index(chain::Chain, i::NTuple{1,Int}) = linearize_index(chain, i...)
linearize_index(chain::Chain, i::NTuple{1, Int}) = linearize_index(chain, i...)
function linearize_index(chain::FiniteChain, i::Int)
0 < i <= chain.L || throw(BoundsError("lattice point out of bounds"))
return i
end

function LinearAlgebra.norm(p::LatticePoint{1,<:Union{FiniteChain,InfiniteChain}})
function LinearAlgebra.norm(p::LatticePoint{1, <:Union{FiniteChain, InfiniteChain}})
return abs(p.coordinates[1])
end
32 changes: 16 additions & 16 deletions src/lattices/latticepoints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

represents an `N`-dimensional point on a `G` lattice.
"""
struct LatticePoint{N,G<:AbstractLattice{N}}
coordinates::NTuple{N,Int}
struct LatticePoint{N, G <: AbstractLattice{N}}
coordinates::NTuple{N, Int}
lattice::G
function LatticePoint(coordinates::NTuple{N,Int}, lattice::AbstractLattice{N}) where {N}
function LatticePoint(coordinates::NTuple{N, Int}, lattice::AbstractLattice{N}) where {N}
checkbounds(lattice, coordinates...)
return new{N,typeof(lattice)}(coordinates, lattice)
return new{N, typeof(lattice)}(coordinates, lattice)
end
end

function LatticePoint(ind::Int, lattice::G) where {G<:AbstractLattice{1}}
function LatticePoint(ind::Int, lattice::G) where {G <: AbstractLattice{1}}
return LatticePoint((ind,), lattice)
end

Expand All @@ -21,47 +21,47 @@ function Base.show(io::IO, p::LatticePoint)
end

function Base.show(io::IO, ::MIME"text/plain", p::LatticePoint)
if get(io, :typeinfo, Any) === typeof(p)
return if get(io, :typeinfo, Any) === typeof(p)
print(io, [p.coordinates...])
else
print(io, p.lattice, [p.coordinates...])
end
end

function Base.getindex(lattice::AbstractLattice{N}, inds::Vararg{Int,N}) where {N}
function Base.getindex(lattice::AbstractLattice{N}, inds::Vararg{Int, N}) where {N}
return LatticePoint(inds, lattice)
end

Base.to_index(p::LatticePoint) = linearize_index(p)
linearize_index(p::LatticePoint) = linearize_index(p.lattice, p.coordinates...)

function Base.:+(i::LatticePoint{N,G}, j::LatticePoint{N,G}) where {N,G}
function Base.:+(i::LatticePoint{N, G}, j::LatticePoint{N, G}) where {N, G}
i.lattice == j.lattice || throw(ArgumentError("lattices should be equal"))
return LatticePoint(i.coordinates .+ j.coordinates, i.lattice)
end
function Base.:-(i::LatticePoint{N,G}, j::LatticePoint{N,G}) where {N,G}
function Base.:-(i::LatticePoint{N, G}, j::LatticePoint{N, G}) where {N, G}
i.lattice == j.lattice || throw(ArgumentError("lattices should be equal"))
return LatticePoint(i.coordinates .- j.coordinates, i.lattice)
end

function Base.:+(i::LatticePoint{N}, j::NTuple{N,Int}) where {N}
function Base.:+(i::LatticePoint{N}, j::NTuple{N, Int}) where {N}
return LatticePoint(i.coordinates .+ j, i.lattice)
end
Base.:+(i::LatticePoint{1}, j::Int) = LatticePoint(i.coordinates .+ j, i.lattice)
Base.:+(i::NTuple{N,Int}, j::LatticePoint{N}) where {N} = j + i
Base.:+(i::NTuple{N, Int}, j::LatticePoint{N}) where {N} = j + i
Base.:+(i::Int, j::LatticePoint{1}) = j + i

function Base.:-(i::LatticePoint{N}, j::NTuple{N,Int}) where {N}
function Base.:-(i::LatticePoint{N}, j::NTuple{N, Int}) where {N}
return LatticePoint(i.coordinates .- j, i.lattice)
end
Base.:-(i::LatticePoint{1}, j::Int) = LatticePoint(i.coordinates .- j, i.lattice)
function Base.:-(i::NTuple{N,Int}, j::LatticePoint{N}) where {N}
function Base.:-(i::NTuple{N, Int}, j::LatticePoint{N}) where {N}
return LatticePoint(i .- j.coordinates, j.lattice)
end
Base.:-(i::Int, j::LatticePoint{1}) = LatticePoint(i .- j, j.lattice)

Base.isless(i::L, j::L) where {L<:LatticePoint} = linearize_index(i) < linearize_index(j)
function Base.isfinite(::Union{LatticePoint{N,G},Type{<:LatticePoint{N,G}}}) where {N,G}
Base.isless(i::L, j::L) where {L <: LatticePoint} = linearize_index(i) < linearize_index(j)
function Base.isfinite(::Union{LatticePoint{N, G}, Type{<:LatticePoint{N, G}}}) where {N, G}
return isfinite(G)
end
latticetype(::Union{LatticePoint{N,G},Type{<:LatticePoint{N,G}}}) where {N,G} = G
latticetype(::Union{LatticePoint{N, G}, Type{<:LatticePoint{N, G}}}) where {N, G} = G
8 changes: 5 additions & 3 deletions src/lattices/lattices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ Base.length(L::AbstractLattice) = length(vertices(L))
Base.isfinite(L::AbstractLattice) = isfinite(typeof(L))
Base.iterate(L::AbstractLattice) = iterate(vertices(L))

function Base.checkbounds(L::AbstractLattice{N}, inds::Vararg{Int,N}) where {N}
function Base.checkbounds(L::AbstractLattice{N}, inds::Vararg{Int, N}) where {N}
return checkbounds(Bool, L, inds...) || throw(BoundsError(L, inds))
end

function Base.checkbounds(::Type{Bool}, L::AbstractLattice{N},
inds::Vararg{Int,N}) where {N}
function Base.checkbounds(
::Type{Bool}, L::AbstractLattice{N},
inds::Vararg{Int, N}
) where {N}
return Base.checkbounds_indices(Bool, axes(L), inds)
end
4 changes: 2 additions & 2 deletions src/lattices/snakepattern.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

Represents a given lattice with a linear order that is provided by `pattern`.
"""
struct SnakePattern{N,G<:AbstractLattice{N},F} <: AbstractLattice{N}
struct SnakePattern{N, G <: AbstractLattice{N}, F} <: AbstractLattice{N}
lattice::G
pattern::F
end

SnakePattern(lattice) = SnakePattern(lattice, identity)

Base.axes(lattice::SnakePattern) = axes(lattice.lattice)
Base.isfinite(::Type{SnakePattern{N,G}}) where {N,G} = isfinite(G)
Base.isfinite(::Type{SnakePattern{N, G}}) where {N, G} = isfinite(G)

function linearize_index(snake::SnakePattern, i...)
return snake.pattern(linearize_index(snake.lattice, i...))
Expand Down
Loading
Loading