Skip to content

Commit

Permalink
Merge pull request #8 from lkdvos/master
Browse files Browse the repository at this point in the history
bump TensorKit compat
  • Loading branch information
lkdvos authored Sep 2, 2023
2 parents 62bb230 + 08bce53 commit 8c98198
Show file tree
Hide file tree
Showing 10 changed files with 382 additions and 322 deletions.
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style = "yas"
15 changes: 8 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ jobs:
fail-fast: false
matrix:
version:
# - '1.0'
- '1.4'
- '1.5'
- '1.6'
- '1'
- 'nightly'
os:
- ubuntu-latest
Expand All @@ -22,15 +21,17 @@ jobs:
arch:
- x64
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
env:
JULIA_NUM_THREADS: 4
- uses: julia-actions/julia-uploadcodecov@latest
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
with:
file: lcov.info
41 changes: 41 additions & 0 deletions .github/workflows/format_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: format-check

on:
push:
branches:
- 'master'
tags: '*'
pull_request:

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: [1]
julia-arch: [x86]
os: [ubuntu-latest]
steps:
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.julia-version }}

- uses: actions/checkout@v1
- name: Install JuliaFormatter and format
# This will use the latest version by default but you can set the version like so:
#
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
run: |
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
julia -e 'using JuliaFormatter; format(".", verbose=true)'
- name: Format check
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'
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name = "TensorKitManifolds"
uuid = "11fa318c-39cb-4a83-b1ed-cdc7ba1e3684"
authors = ["Jutho Haegeman <[email protected]>", "Markus Hauru <[email protected]>"]
version = "0.6.0"
version = "0.6.1"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
TensorKit = "07d1fe3e-3e46-537d-9eac-e9e13d0d4cec"

[compat]
TensorKit = "0.6,0.7,0.8,0.9,1"
julia = "1"
TensorKit = "0.11"
julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
49 changes: 25 additions & 24 deletions src/TensorKitManifolds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,52 +26,53 @@ function checkbase end
checkbase(x, y, z, args...) = checkbase(checkbase(x, y), z, args...)

# the machine epsilon for the elements of an object X, name inspired from eltype
eleps(X) = eps(real(eltype(X)))
scalareps(X) = eps(real(scalartype(X)))

function isisometry(W::AbstractTensorMap; tol = 10*eleps(W))
WdW = W'*W
s = zero(float(real(eltype(W))))
for (c,b) in blocks(WdW)
function isisometry(W::AbstractTensorMap; tol=10 * scalareps(W))
WdW = W' * W
s = zero(float(real(scalartype(W))))
for (c, b) in blocks(WdW)
_subtractone!(b)
s += dim(c)*length(b)
s += dim(c) * length(b)
end
return norm(WdW) <= tol*sqrt(s)
return norm(WdW) <= tol * sqrt(s)
end

isunitary(W::AbstractTensorMap; tol = 10*eleps(W)) =
isisometry(W; tol = tol) && isisometry(W'; tol = tol)
function isunitary(W::AbstractTensorMap; tol=10 * scalareps(W))
return isisometry(W; tol=tol) && isisometry(W'; tol=tol)
end

function projecthermitian!(W::AbstractTensorMap)
codomain(W) == domain(W) ||
throw(DomainError("Tensor with distinct domain and codomain cannot be hermitian."))
for (c,b) in blocks(W)
for (c, b) in blocks(W)
_projecthermitian!(b)
end
return W
end
function projectantihermitian!(W::AbstractTensorMap)
codomain(W) == domain(W) ||
throw(DomainError("Tensor with distinct domain and codomain cannot be anithermitian."))
for (c,b) in blocks(W)
for (c, b) in blocks(W)
_projectantihermitian!(b)
end
return W
end

struct PolarNewton <: TensorKit.OrthogonalFactorizationAlgorithm
end
function projectisometric!(W::AbstractTensorMap; alg = Polar())
function projectisometric!(W::AbstractTensorMap; alg=Polar())
if alg isa TensorKit.Polar || alg isa TensorKit.SDD
foreach(blocks(W)) do (c,b)
_polarsdd!(b)
foreach(blocks(W)) do (c, b)
return _polarsdd!(b)
end
elseif alg isa TensorKit.SVD
foreach(blocks(W)) do (c,b)
_polarsvd!(b)
foreach(blocks(W)) do (c, b)
return _polarsvd!(b)
end
elseif alg isa PolarNewton
foreach(blocks(W)) do (c,b)
_polarnewton!(b)
foreach(blocks(W)) do (c, b)
return _polarnewton!(b)
end
else
throw(ArgumentError("unkown algorithm for projectisometric!: alg = $alg"))
Expand All @@ -80,14 +81,14 @@ function projectisometric!(W::AbstractTensorMap; alg = Polar())
end

function projectcomplement!(X::AbstractTensorMap, W::AbstractTensorMap;
tol = 10*eleps(X))
P = W'*X
tol=10 * scalareps(X))
P = W' * X
nP = norm(P)
nX = norm(X)
dP = dim(P)
while nP > tol*max(dP, nX)
while nP > tol * max(dP, nX)
X = mul!(X, W, P, -1, 1)
P = W'*X
P = W' * X
nP = norm(P)
end
return X
Expand All @@ -97,11 +98,11 @@ projecthermitian(W::AbstractTensorMap) = projecthermitian!(copy(W))
projectantihermitian(W::AbstractTensorMap) = projectantihermitian!(copy(W))

function projectisometric(W::AbstractTensorMap;
alg::TensorKit.OrthogonalFactorizationAlgorithm = Polar())
alg::TensorKit.OrthogonalFactorizationAlgorithm=Polar())
return projectisometric!(copy(W); alg=alg)
end
function projectcomplement(X::AbstractTensorMap, W::AbstractTensorMap,
tol = 10*eleps(X))
tol=10 * scalareps(X))
return projectcomplement!(copy(X), W; tol=tol)
end

Expand Down
Loading

2 comments on commit 8c98198

@lkdvos
Copy link
Collaborator Author

@lkdvos lkdvos commented on 8c98198 Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/90841

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.1 -m "<description of version>" 8c9819842f4205c0ac1bd71f7667c517540e81e1
git push origin v0.6.1

Please sign in to comment.