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.

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

on:
schedule:
- cron: 0 0 * * *
- cron: '0 0 * * *'
workflow_dispatch:
permissions:
contents: write
Expand Down
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
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 = "BlockSparseArrays"
uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4"
authors = ["ITensor developers <support@itensor.org> and contributors"]
version = "0.10.6"
version = "0.10.7"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ This step is only required once.
```julia
julia> using Pkg: Pkg

julia> Pkg.Registry.add(url="https://github.com/ITensor/ITensorRegistry")
julia> Pkg.Registry.add(url = "https://github.com/ITensor/ITensorRegistry")
```
or:
```julia
julia> Pkg.Registry.add(url="git@github.com:ITensor/ITensorRegistry.git")
julia> Pkg.Registry.add(url = "git@github.com:ITensor/ITensorRegistry.git")
```
if you want to use SSH credentials, which can make it so you don't have to enter your Github ursername and password when registering packages.

Expand Down
28 changes: 14 additions & 14 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ using BlockSparseArrays: BlockSparseArrays
using Documenter: Documenter, DocMeta, deploydocs, makedocs

DocMeta.setdocmeta!(
BlockSparseArrays, :DocTestSetup, quote
using BlockSparseArrays
using LinearAlgebra: Diagonal
end; recursive=true
BlockSparseArrays, :DocTestSetup, quote
using BlockSparseArrays
using LinearAlgebra: Diagonal
end; recursive = true
)

include("make_index.jl")

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

deploydocs(;
repo="github.com/ITensor/BlockSparseArrays.jl", devbranch="main", push_preview=true
repo = "github.com/ITensor/BlockSparseArrays.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 BlockSparseArrays: BlockSparseArrays

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(BlockSparseArrays), "examples", "README.jl"),
joinpath(pkgdir(BlockSparseArrays), "docs", "src");
flavor=Literate.DocumenterFlavor(),
name="index",
postprocess=ccq_logo,
joinpath(pkgdir(BlockSparseArrays), "examples", "README.jl"),
joinpath(pkgdir(BlockSparseArrays), "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 BlockSparseArrays: BlockSparseArrays

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(BlockSparseArrays), "examples", "README.jl"),
joinpath(pkgdir(BlockSparseArrays));
flavor=Literate.CommonMarkFlavor(),
name="README",
postprocess=ccq_logo,
joinpath(pkgdir(BlockSparseArrays), "examples", "README.jl"),
joinpath(pkgdir(BlockSparseArrays));
flavor = Literate.CommonMarkFlavor(),
name = "README",
postprocess = ccq_logo,
)
6 changes: 3 additions & 3 deletions examples/README.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# # BlockSparseArrays.jl
#
#
# [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://itensor.github.io/BlockSparseArrays.jl/stable/)
# [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://itensor.github.io/BlockSparseArrays.jl/dev/)
# [![Build Status](https://github.com/ITensor/BlockSparseArrays.jl/actions/workflows/Tests.yml/badge.svg?branch=main)](https://github.com/ITensor/BlockSparseArrays.jl/actions/workflows/Tests.yml?query=branch%3Amain)
Expand All @@ -24,13 +24,13 @@
```julia
julia> using Pkg: Pkg

julia> Pkg.Registry.add(url="https://github.com/ITensor/ITensorRegistry")
julia> Pkg.Registry.add(url = "https://github.com/ITensor/ITensorRegistry")
```
=#
# or:
#=
```julia
julia> Pkg.Registry.add(url="git@github.com:ITensor/ITensorRegistry.git")
julia> Pkg.Registry.add(url = "git@github.com:ITensor/ITensorRegistry.git")
```
=#
# if you want to use SSH credentials, which can make it so you don't have to enter your Github ursername and password when registering packages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,64 @@ module BlockSparseArraysTensorAlgebraExt

using BlockSparseArrays: AbstractBlockSparseArray, blockreshape
using TensorAlgebra:
TensorAlgebra,
BlockedTrivialPermutation,
BlockedTuple,
FusionStyle,
ReshapeFusion,
fuseaxes
TensorAlgebra,
BlockedTrivialPermutation,
BlockedTuple,
FusionStyle,
ReshapeFusion,
fuseaxes

struct BlockReshapeFusion <: FusionStyle end

function TensorAlgebra.FusionStyle(::Type{<:AbstractBlockSparseArray})
return BlockReshapeFusion()
return BlockReshapeFusion()
end

using BlockArrays: Block, blocklength, blocks
using BlockSparseArrays: blocksparse
using SparseArraysBase: eachstoredindex
using TensorAlgebra: TensorAlgebra, matricize, unmatricize
function TensorAlgebra.matricize(
::BlockReshapeFusion, a::AbstractArray, biperm::BlockedTrivialPermutation{2}
)
ax = fuseaxes(axes(a), biperm)
reshaped_blocks_a = reshape(blocks(a), map(blocklength, ax))
key(I) = Block(Tuple(I))
value(I) = matricize(reshaped_blocks_a[I], biperm)
Is = eachstoredindex(reshaped_blocks_a)
bs = if isempty(Is)
# Catch empty case and make sure the type is constrained properly.
# This seems to only be necessary in Julia versions below v1.11,
# try removing it when we drop support for those versions.
keytype = Base.promote_op(key, eltype(Is))
valtype = Base.promote_op(value, eltype(Is))
valtype′ = !isconcretetype(valtype) ? AbstractMatrix{eltype(a)} : valtype
Dict{keytype,valtype′}()
else
Dict(key(I) => value(I) for I in Is)
end
return blocksparse(bs, ax)
::BlockReshapeFusion, a::AbstractArray, biperm::BlockedTrivialPermutation{2}
)
ax = fuseaxes(axes(a), biperm)
reshaped_blocks_a = reshape(blocks(a), map(blocklength, ax))
key(I) = Block(Tuple(I))
value(I) = matricize(reshaped_blocks_a[I], biperm)
Is = eachstoredindex(reshaped_blocks_a)
bs = if isempty(Is)
# Catch empty case and make sure the type is constrained properly.
# This seems to only be necessary in Julia versions below v1.11,
# try removing it when we drop support for those versions.
keytype = Base.promote_op(key, eltype(Is))
valtype = Base.promote_op(value, eltype(Is))
valtype′ = !isconcretetype(valtype) ? AbstractMatrix{eltype(a)} : valtype
Dict{keytype, valtype′}()
else
Dict(key(I) => value(I) for I in Is)
end
return blocksparse(bs, ax)
end

using BlockArrays: blocklengths
function TensorAlgebra.unmatricize(
::BlockReshapeFusion,
m::AbstractMatrix,
blocked_ax::BlockedTuple{2,<:Any,<:Tuple{Vararg{AbstractUnitRange}}},
)
ax = Tuple(blocked_ax)
reshaped_blocks_m = reshape(blocks(m), map(blocklength, ax))
function f(I)
block_axes_I = BlockedTuple(
map(ntuple(identity, length(ax))) do i
return Base.axes1(ax[i][Block(I[i])])
end,
blocklengths(blocked_ax),
::BlockReshapeFusion,
m::AbstractMatrix,
blocked_ax::BlockedTuple{2, <:Any, <:Tuple{Vararg{AbstractUnitRange}}},
)
return unmatricize(reshaped_blocks_m[I], block_axes_I)
end
bs = Dict(Block(Tuple(I)) => f(I) for I in eachstoredindex(reshaped_blocks_m))
return blocksparse(bs, ax)
ax = Tuple(blocked_ax)
reshaped_blocks_m = reshape(blocks(m), map(blocklength, ax))
function f(I)
block_axes_I = BlockedTuple(
map(ntuple(identity, length(ax))) do i
return Base.axes1(ax[i][Block(I[i])])
end,
blocklengths(blocked_ax),
)
return unmatricize(reshaped_blocks_m[I], block_axes_I)
end
bs = Dict(Block(Tuple(I)) => f(I) for I in eachstoredindex(reshaped_blocks_m))
return blocksparse(bs, ax)
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ using TensorProducts: TensorProducts, tensor_product
# TODO: Dispatch on `FusionStyle` to allow different kinds of products,
# for example to allow merging common symmetry sectors.
function TensorProducts.tensor_product(a1::BlockUnitRange, a2::BlockUnitRange)
new_blockaxes = vec(
map(splat(tensor_product), Iterators.product(eachblockaxis(a1), eachblockaxis(a2)))
)
return blockrange(new_blockaxes)
new_blockaxes = vec(
map(splat(tensor_product), Iterators.product(eachblockaxis(a1), eachblockaxis(a2)))
)
return blockrange(new_blockaxes)
end

end
Loading
Loading