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
3 changes: 0 additions & 3 deletions .JuliaFormatter.toml

This file was deleted.

13 changes: 8 additions & 5 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
name: "Format Check"

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

permissions:
contents: read
actions: write
pull-requests: write

jobs:
format-check:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
.vscode/
Manifest.toml
benchmark/*.json
dev/
docs/LocalPreferences.toml
docs/Manifest.toml
docs/build/
docs/src/index.md
examples/LocalPreferences.toml
test/LocalPreferences.toml
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ci:
skip: [julia-formatter]
skip: [runic]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -11,7 +11,7 @@ repos:
- id: end-of-file-fixer
exclude_types: [markdown] # incompatible with Literate.jl

- repo: "https://github.com/domluna/JuliaFormatter.jl"
rev: v2.1.6
- repo: https://github.com/fredrikekre/runic-pre-commit
rev: v2.0.1
hooks:
- id: "julia-formatter"
- id: runic
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "KroneckerArrays"
uuid = "05d0b138-81bc-4ff7-84be-08becefb1ccc"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.2.3"
version = "0.2.4"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
22 changes: 11 additions & 11 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ using KroneckerArrays: KroneckerArrays
using Documenter: Documenter, DocMeta, deploydocs, makedocs

DocMeta.setdocmeta!(
KroneckerArrays, :DocTestSetup, :(using KroneckerArrays); recursive=true
KroneckerArrays, :DocTestSetup, :(using KroneckerArrays); recursive = true
)

include("make_index.jl")

makedocs(;
modules=[KroneckerArrays],
authors="ITensor developers <[email protected]> and contributors",
sitename="KroneckerArrays.jl",
format=Documenter.HTML(;
canonical="https://itensor.github.io/KroneckerArrays.jl",
edit_link="main",
assets=["assets/favicon.ico", "assets/extras.css"],
),
pages=["Home" => "index.md", "Reference" => "reference.md"],
modules = [KroneckerArrays],
authors = "ITensor developers <[email protected]> and contributors",
sitename = "KroneckerArrays.jl",
format = Documenter.HTML(;
canonical = "https://itensor.github.io/KroneckerArrays.jl",
edit_link = "main",
assets = ["assets/favicon.ico", "assets/extras.css"],
),
pages = ["Home" => "index.md", "Reference" => "reference.md"],
)

deploydocs(;
repo="github.com/ITensor/KroneckerArrays.jl", devbranch="main", push_preview=true
repo = "github.com/ITensor/KroneckerArrays.jl", devbranch = "main", push_preview = true
)
16 changes: 8 additions & 8 deletions docs/make_index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ using Literate: Literate
using KroneckerArrays: KroneckerArrays

function ccq_logo(content)
include_ccq_logo = """
include_ccq_logo = """
```@raw html
<img class="display-light-only" src="assets/CCQ.png" width="20%" alt="Flatiron Center for Computational Quantum Physics logo."/>
<img class="display-dark-only" src="assets/CCQ-dark.png" width="20%" alt="Flatiron Center for Computational Quantum Physics logo."/>
```
"""
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
end

Literate.markdown(
joinpath(pkgdir(KroneckerArrays), "examples", "README.jl"),
joinpath(pkgdir(KroneckerArrays), "docs", "src");
flavor=Literate.DocumenterFlavor(),
name="index",
postprocess=ccq_logo,
joinpath(pkgdir(KroneckerArrays), "examples", "README.jl"),
joinpath(pkgdir(KroneckerArrays), "docs", "src");
flavor = Literate.DocumenterFlavor(),
name = "index",
postprocess = ccq_logo,
)
16 changes: 8 additions & 8 deletions docs/make_readme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ using Literate: Literate
using KroneckerArrays: KroneckerArrays

function ccq_logo(content)
include_ccq_logo = """
include_ccq_logo = """
<picture>
<source media="(prefers-color-scheme: dark)" width="20%" srcset="docs/src/assets/CCQ-dark.png">
<img alt="Flatiron Center for Computational Quantum Physics logo." width="20%" src="docs/src/assets/CCQ.png">
</picture>
"""
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
end

Literate.markdown(
joinpath(pkgdir(KroneckerArrays), "examples", "README.jl"),
joinpath(pkgdir(KroneckerArrays));
flavor=Literate.CommonMarkFlavor(),
name="README",
postprocess=ccq_logo,
joinpath(pkgdir(KroneckerArrays), "examples", "README.jl"),
joinpath(pkgdir(KroneckerArrays));
flavor = Literate.CommonMarkFlavor(),
name = "README",
postprocess = ccq_logo,
)
2 changes: 1 addition & 1 deletion examples/README.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# # KroneckerArrays.jl
#
#
# [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://itensor.github.io/KroneckerArrays.jl/stable/)
# [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://itensor.github.io/KroneckerArrays.jl/dev/)
# [![Build Status](https://github.com/ITensor/KroneckerArrays.jl/actions/workflows/Tests.yml/badge.svg?branch=main)](https://github.com/ITensor/KroneckerArrays.jl/actions/workflows/Tests.yml?query=branch%3Amain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ using BlockArrays: Block
using BlockSparseArrays: BlockIndexVector, GenericBlockIndex
using KroneckerArrays: CartesianPair, CartesianProduct
function Base.getindex(
b::Block,
I1::Union{CartesianPair,CartesianProduct},
Irest::Union{CartesianPair,CartesianProduct}...,
)
return GenericBlockIndex(b, (I1, Irest...))
b::Block,
I1::Union{CartesianPair, CartesianProduct},
Irest::Union{CartesianPair, CartesianProduct}...,
)
return GenericBlockIndex(b, (I1, Irest...))
end
function Base.getindex(b::Block, I1::CartesianProduct, Irest::CartesianProduct...)
return BlockIndexVector(b, (I1, Irest...))
return BlockIndexVector(b, (I1, Irest...))
end

using BlockSparseArrays: BlockSparseArrays, blockrange
using KroneckerArrays: CartesianPair, CartesianProduct, cartesianrange
function BlockSparseArrays.blockrange(bs::Vector{<:CartesianPair})
return blockrange(map(cartesianrange, bs))
return blockrange(map(cartesianrange, bs))
end
function BlockSparseArrays.blockrange(bs::Vector{<:CartesianProduct})
return blockrange(map(cartesianrange, bs))
return blockrange(map(cartesianrange, bs))
end

using BlockArrays: BlockArrays, mortar
Expand All @@ -31,56 +31,56 @@ using KroneckerArrays: CartesianProductUnitRange
# This is helpful when indexing `BlockUnitRange`, for example:
# https://github.com/JuliaArrays/BlockArrays.jl/blob/v1.7.1/src/blockaxis.jl#L540-L547
function BlockArrays.mortar(blocks::AbstractVector{<:CartesianProductUnitRange})
return mortar(blocks, (blockrange(map(Base.axes1, blocks)),))
return mortar(blocks, (blockrange(map(Base.axes1, blocks)),))
end

using BlockArrays: AbstractBlockedUnitRange
using BlockSparseArrays: Block, ZeroBlocks, eachblockaxis, mortar_axis
using KroneckerArrays: KroneckerArrays, KroneckerArray, ⊗, arg1, arg2, isactive

function KroneckerArrays.arg1(r::AbstractBlockedUnitRange)
return mortar_axis(arg1.(eachblockaxis(r)))
return mortar_axis(arg1.(eachblockaxis(r)))
end
function KroneckerArrays.arg2(r::AbstractBlockedUnitRange)
return mortar_axis(arg2.(eachblockaxis(r)))
return mortar_axis(arg2.(eachblockaxis(r)))
end

function block_axes(
ax::NTuple{N,AbstractUnitRange{<:Integer}}, I::Vararg{Block{1},N}
) where {N}
return ntuple(N) do d
return only(axes(ax[d][I[d]]))
end
ax::NTuple{N, AbstractUnitRange{<:Integer}}, I::Vararg{Block{1}, N}
) where {N}
return ntuple(N) do d
return only(axes(ax[d][I[d]]))
end
end
function block_axes(ax::NTuple{N,AbstractUnitRange{<:Integer}}, I::Block{N}) where {N}
return block_axes(ax, Tuple(I)...)
function block_axes(ax::NTuple{N, AbstractUnitRange{<:Integer}}, I::Block{N}) where {N}
return block_axes(ax, Tuple(I)...)
end

using DiagonalArrays: ShapeInitializer

## TODO: Is this needed?
function Base.getindex(
a::ZeroBlocks{N,KroneckerArray{T,N,A1,A2}}, I::Vararg{Int,N}
) where {T,N,A1<:AbstractArray{T,N},A2<:AbstractArray{T,N}}
ax_a1 = map(arg1, a.parentaxes)
ax_a2 = map(arg2, a.parentaxes)
block_ax_a1 = arg1.(block_axes(a.parentaxes, Block(I)))
block_ax_a2 = arg2.(block_axes(a.parentaxes, Block(I)))
# TODO: Is this a good definition? It is similar to
# the definition of `similar` and `adapt_structure`.
return if isactive(A1) == isactive(A2)
ZeroBlocks{N,A1}(ax_a1)[I...] ⊗ ZeroBlocks{N,A2}(ax_a2)[I...]
elseif isactive(A1)
ZeroBlocks{N,A1}(ax_a1)[I...] ⊗ A2(ShapeInitializer(), block_ax_a2)
elseif isactive(A2)
A1(ShapeInitializer(), block_ax_a1) ⊗ ZeroBlocks{N,A2}(ax_a2)[I...]
end
a::ZeroBlocks{N, KroneckerArray{T, N, A1, A2}}, I::Vararg{Int, N}
) where {T, N, A1 <: AbstractArray{T, N}, A2 <: AbstractArray{T, N}}
ax_a1 = map(arg1, a.parentaxes)
ax_a2 = map(arg2, a.parentaxes)
block_ax_a1 = arg1.(block_axes(a.parentaxes, Block(I)))
block_ax_a2 = arg2.(block_axes(a.parentaxes, Block(I)))
# TODO: Is this a good definition? It is similar to
# the definition of `similar` and `adapt_structure`.
return if isactive(A1) == isactive(A2)
ZeroBlocks{N, A1}(ax_a1)[I...] ⊗ ZeroBlocks{N, A2}(ax_a2)[I...]
elseif isactive(A1)
ZeroBlocks{N, A1}(ax_a1)[I...] ⊗ A2(ShapeInitializer(), block_ax_a2)
elseif isactive(A2)
A1(ShapeInitializer(), block_ax_a1) ⊗ ZeroBlocks{N, A2}(ax_a2)[I...]
end
end

using BlockSparseArrays: BlockSparseArrays
using KroneckerArrays: KroneckerArrays, KroneckerVector
function BlockSparseArrays.to_truncated_indices(values::KroneckerVector, I)
return KroneckerArrays.to_truncated_indices(values, I)
return KroneckerArrays.to_truncated_indices(values, I)
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,41 @@ module KroneckerArraysTensorAlgebraExt

using KroneckerArrays: KroneckerArrays, KroneckerArray, ⊗, arg1, arg2
using TensorAlgebra:
TensorAlgebra, AbstractBlockPermutation, FusionStyle, matricize, unmatricize
TensorAlgebra, AbstractBlockPermutation, FusionStyle, matricize, unmatricize

struct KroneckerFusion{A<:FusionStyle,B<:FusionStyle} <: FusionStyle
a::A
b::B
struct KroneckerFusion{A <: FusionStyle, B <: FusionStyle} <: FusionStyle
a::A
b::B
end
KroneckerArrays.arg1(style::KroneckerFusion) = style.a
KroneckerArrays.arg2(style::KroneckerFusion) = style.b
function TensorAlgebra.FusionStyle(a::KroneckerArray)
return KroneckerFusion(FusionStyle(arg1(a)), FusionStyle(arg2(a)))
return KroneckerFusion(FusionStyle(arg1(a)), FusionStyle(arg2(a)))
end
function matricize_kronecker(
style::KroneckerFusion, a::AbstractArray, biperm::AbstractBlockPermutation{2}
)
return matricize(arg1(style), arg1(a), biperm) ⊗ matricize(arg2(style), arg2(a), biperm)
style::KroneckerFusion, a::AbstractArray, biperm::AbstractBlockPermutation{2}
)
return matricize(arg1(style), arg1(a), biperm) ⊗ matricize(arg2(style), arg2(a), biperm)
end
function TensorAlgebra.matricize(
style::KroneckerFusion, a::AbstractArray, biperm::AbstractBlockPermutation{2}
)
return matricize_kronecker(style, a, biperm)
style::KroneckerFusion, a::AbstractArray, biperm::AbstractBlockPermutation{2}
)
return matricize_kronecker(style, a, biperm)
end
# Fix ambiguity error.
# TODO: Investigate rewriting the logic in `TensorAlgebra.jl` to avoid this.
using TensorAlgebra: BlockedTrivialPermutation, unmatricize
function TensorAlgebra.matricize(
style::KroneckerFusion, a::AbstractArray, biperm::BlockedTrivialPermutation{2}
)
return matricize_kronecker(style, a, biperm)
style::KroneckerFusion, a::AbstractArray, biperm::BlockedTrivialPermutation{2}
)
return matricize_kronecker(style, a, biperm)
end
function unmatricize_kronecker(style::KroneckerFusion, a::AbstractArray, ax)
return unmatricize(arg1(style), arg1(a), arg1.(ax)) ⊗
unmatricize(arg2(style), arg2(a), arg2.(ax))
return unmatricize(arg1(style), arg1(a), arg1.(ax)) ⊗
unmatricize(arg2(style), arg2(a), arg2.(ax))
end
function TensorAlgebra.unmatricize(style::KroneckerFusion, a::AbstractArray, ax)
return unmatricize_kronecker(style, a, ax)
return unmatricize_kronecker(style, a, ax)
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module KroneckerArraysTensorProductsExt
using KroneckerArrays: CartesianProductOneTo, ×, arg1, arg2, cartesianrange, unproduct
using TensorProducts: TensorProducts, tensor_product
function TensorProducts.tensor_product(a1::CartesianProductOneTo, a2::CartesianProductOneTo)
prod = tensor_product(arg1(a1), arg1(a2)) × tensor_product(arg2(a1), arg2(a2))
range = tensor_product(unproduct(a1), unproduct(a2))
return cartesianrange(prod, range)
prod = tensor_product(arg1(a1), arg1(a2)) × tensor_product(arg2(a1), arg2(a2))
range = tensor_product(unproduct(a1), unproduct(a2))
return cartesianrange(prod, range)
end

end
Loading
Loading