Skip to content
Open
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
143 changes: 105 additions & 38 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
paths-ignore:
- 'docs/**'
pull_request:
types: [opened, synchronize, reopened, ready_for_review, converted_to_draft]
workflow_dispatch:

concurrency:
Expand All @@ -19,55 +20,121 @@ concurrency:
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

jobs:
setup-matrix:
runs-on: ubuntu-latest
outputs:
groups: ${{ steps.mk.outputs.groups }}
version: ${{ steps.mk.outputs.version }}
os: ${{ steps.mk.outputs.os }}
steps:
- uses: actions/checkout@v6
- id: mk
shell: bash
run: |
# Auto-discover test groups from all subdirectory names.
groups=$(find test -mindepth 1 -maxdepth 1 -type d \
| xargs -I{} basename {} | sort \
| jq -R -s -c '[split("\n")[] | select(length > 0)]')

echo "groups=${groups}" >> "$GITHUB_OUTPUT"

# Draft PR: only run ubuntu-latest + version=1
if [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.draft }}" == "true" ]]; then
echo 'version=["1"]' >> "$GITHUB_OUTPUT"
echo 'os=["ubuntu-latest"]' >> "$GITHUB_OUTPUT"
else
echo 'version=["lts","1"]' >> "$GITHUB_OUTPUT"
echo 'os=["ubuntu-latest","macOS-latest","windows-latest"]' >> "$GITHUB_OUTPUT"
fi

test:
name: "Tests"
needs: setup-matrix
strategy:
fail-fast: false
matrix:
version:
- 'lts'
- '1'
group:
- symmetries
- tensors
- other
- mooncake
- chainrules
os:
- ubuntu-latest
- macOS-latest
- windows-latest
uses: "QuantumKitHub/QuantumKitHubActions/.github/workflows/Tests.yml@main"
with:
group: "${{ matrix.group }}"
julia-version: "${{ matrix.version }}"
os: "${{ matrix.os }}"
nthreads: 4
timeout-minutes: 120
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
version: ${{ fromJSON(needs.setup-matrix.outputs.version) }}
os: ${{ fromJSON(needs.setup-matrix.outputs.os) }}
group: ${{ fromJSON(needs.setup-matrix.outputs.groups) }}
runs-on: ${{ matrix.os }}
timeout-minutes: 120
steps:
- uses: actions/checkout@v6
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
with:
test_args: '${{ matrix.group }}${{ github.event.pull_request.draft == true && '' --fast'' || '''' }}'
env:
JULIA_NUM_THREADS: "4"
- uses: julia-actions/julia-processcoverage@v1
with:
directories: 'src,ext'
- uses: codecov/codecov-action@v5
with:
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false

test-nightly:
needs: test
name: "Tests (nightly)"
needs: [setup-matrix, test]
if: github.event.pull_request.draft != true
strategy:
fail-fast: false
matrix:
version:
- 'nightly'
group:
- symmetries
- tensors
- other
- mooncake
- chainrules
group: ${{ fromJSON(needs.setup-matrix.outputs.groups) }}
os:
- ubuntu-latest
- macOS-latest
- windows-latest
uses: "QuantumKitHub/QuantumKitHubActions/.github/workflows/Tests.yml@main"
with:
group: "${{ matrix.group }}"
julia-version: "${{ matrix.version }}"
os: "${{ matrix.os }}"
nthreads: 4
timeout-minutes: 120
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
runs-on: ${{ matrix.os }}
timeout-minutes: 120
steps:
- uses: actions/checkout@v6
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
with:
test_args: '${{ matrix.group }}'
continue-on-error: true
- uses: julia-actions/julia-processcoverage@v1
with:
directories: 'src,ext'
- uses: codecov/codecov-action@v5
with:
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false

compatcheck:
name: "Compat check - ${{ matrix.julia-version }}"
needs: [setup-matrix, test]
if: github.event.pull_request.draft != true
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
downgrade_mode: ['deps']
group: ${{ fromJSON(needs.setup-matrix.outputs.groups) }}
julia-version: ['1.10', '1']
steps:
- uses: actions/checkout@v6
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.julia-version }}
- uses: julia-actions/julia-downgrade-compat@v2.1
with:
mode: ${{ matrix.downgrade_mode }}
skip: Random, LinearAlgebra, Test, Combinatorics
julia_version: ${{ matrix.julia-version }}
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
38 changes: 0 additions & 38 deletions .github/workflows/CompatCheck.yml

This file was deleted.

37 changes: 3 additions & 34 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,58 +32,27 @@ TensorKitChainRulesCoreExt = "ChainRulesCore"
TensorKitFiniteDifferencesExt = "FiniteDifferences"
TensorKitMooncakeExt = "Mooncake"

[workspace]
projects = ["test"]

[compat]
Adapt = "4"
AllocCheck = "0.2.3"
Aqua = "0.6, 0.7, 0.8"
ArgParse = "1.2.0"
CUDA = "5.9"
ChainRulesCore = "1"
ChainRulesTestUtils = "1"
Combinatorics = "1"
FiniteDifferences = "0.12"
GPUArrays = "11.3.1"
JET = "0.9, 0.10, 0.11"
LRUCache = "1.0.2"
LinearAlgebra = "1"
MatrixAlgebraKit = "0.6.5"
Mooncake = "0.5"
OhMyThreads = "0.8.0"
Printf = "1"
Random = "1"
SafeTestsets = "0.1"
ScopedValues = "1.3.0"
Strided = "2"
TensorKitSectors = "0.3.6"
TensorOperations = "5.1"
Test = "1"
TestExtras = "0.2,0.3"
TupleTools = "1.5"
VectorInterface = "0.4.8, 0.5"
Zygote = "0.7"
cuTENSOR = "2"
julia = "1.10"

[extras]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestExtras = "5ed8adda-3752-4e41-b88a-e8b09835ee3a"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
cuTENSOR = "011b41b2-24ef-40a8-b3eb-fa098493e9e1"

[targets]
test = ["ArgParse", "Adapt", "Aqua", "AllocCheck", "Combinatorics", "CUDA", "cuTENSOR", "GPUArrays", "JET", "LinearAlgebra", "SafeTestsets", "TensorOperations", "Test", "TestExtras", "ChainRulesCore", "ChainRulesTestUtils", "FiniteDifferences", "Zygote", "Mooncake"]
62 changes: 31 additions & 31 deletions src/fusiontrees/braiding_manipulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -299,44 +299,44 @@ Base.@assume_effects :foldable function _fsdicttype(::Type{T}) where {I, N₁, N
return Pair{FusionTreeBlock{I, N₁, N₂, Tuple{F₁, F₂}}, Matrix{E}}
end

@cached function fsbraid(key::K)::_fsdicttype(K) where {I, N₁, N₂, K <: FSPBraidKey{I, N₁, N₂}}
((f₁, f₂), (p1, p2), (l1, l2)) = key
p = linearizepermutation(p1, p2, length(f₁), length(f₂))
levels = (l1..., reverse(l2)...)
(f, f0), coeff1 = repartition((f₁, f₂), N₁ + N₂)
f′, coeff2 = braid(f, p, levels)
(f₁′, f₂′), coeff3 = repartition((f′, f0), N₁)
return (f₁′, f₂′) => coeff1 * coeff2 * coeff3
end
@cached function fsbraid(key::K)::_fsdicttype(K) where {I, N₁, N₂, K <: FSBBraidKey{I, N₁, N₂}}
src, (p1, p2), (l1, l2) = key
@cached function fsbraid(key::K)::_fsdicttype(K) where {I, N₁, N₂, K <: Union{FSPBraidKey{I, N₁, N₂}, FSBBraidKey{I, N₁, N₂}}}
if K <: FSPBraidKey
((f₁, f₂), (p1, p2), (l1, l2)) = key
p = linearizepermutation(p1, p2, length(f₁), length(f₂))
levels = (l1..., reverse(l2)...)
(f, f0), coeff1 = repartition((f₁, f₂), N₁ + N₂)
f′, coeff2 = braid(f, p, levels)
(f₁′, f₂′), coeff3 = repartition((f′, f0), N₁)
return (f₁′, f₂′) => coeff1 * coeff2 * coeff3

p = linearizepermutation(p1, p2, numout(src), numin(src))
levels = (l1..., reverse(l2)...)
else
src, (p1, p2), (l1, l2) = key

dst, U = repartition(src, numind(src))
p = linearizepermutation(p1, p2, numout(src), numin(src))
levels = (l1..., reverse(l2)...)

for s in permutation2swaps(p)
inv = levels[s] > levels[s + 1]
dst, U_tmp = artin_braid(dst, s; inv)
U = U_tmp * U
l = levels[s]
levels = TupleTools.setindex(levels, levels[s + 1], s)
levels = TupleTools.setindex(levels, l, s + 1)
end
dst, U = repartition(src, numind(src))

if N₂ == 0
return dst => U
else
dst, U_tmp = repartition(dst, N₁)
U = U_tmp * U
return dst => U
for s in permutation2swaps(p)
inv = levels[s] > levels[s + 1]
dst, U_tmp = artin_braid(dst, s; inv)
U = U_tmp * U
l = levels[s]
levels = TupleTools.setindex(levels, levels[s + 1], s)
levels = TupleTools.setindex(levels, l, s + 1)
end

if N₂ == 0
return dst => U
else
dst, U_tmp = repartition(dst, N₁)
U = U_tmp * U
return dst => U
end
end
end

CacheStyle(::typeof(fsbraid), k::FSPBraidKey{I}) where {I} =
FusionStyle(I) isa UniqueFusion ? NoCache() : GlobalLRUCache()
CacheStyle(::typeof(fsbraid), k::FSBBraidKey{I}) where {I} =
CacheStyle(::typeof(fsbraid), k::Union{FSPBraidKey{I}, FSBBraidKey{I}}) where {I} =
FusionStyle(I) isa UniqueFusion ? NoCache() : GlobalLRUCache()

"""
Expand Down
38 changes: 38 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name = "TensorKitTests"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MatrixAlgebraKit = "6c742aac-3347-4629-af66-fc926824e5e4"
Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
ParallelTestRunner = "d3525ed8-44d0-4b2c-a655-542cee43accc"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
TensorKit = "07d1fe3e-3e46-537d-9eac-e9e13d0d4cec"
TensorKitSectors = "13a9c161-d5da-41f0-bcbd-e1a08ae0647f"
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestExtras = "5ed8adda-3752-4e41-b88a-e8b09835ee3a"
TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6"
VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
cuTENSOR = "011b41b2-24ef-40a8-b3eb-fa098493e9e1"

[sources]
TensorKit = {path = ".."}

[compat]
Aqua = "0.6, 0.7, 0.8"
ChainRulesTestUtils = "1"
Combinatorics = "1"
GPUArrays = "11.3.1"
ParallelTestRunner = "2"
Test = "1"
TestExtras = "0.2,0.3"
Zygote = "0.7"
Loading
Loading