-
Notifications
You must be signed in to change notification settings - Fork 2
[WIP] Define random_unitary
constructor
#39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mtfishman
wants to merge
12
commits into
main
Choose a base branch
from
random_unitary
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d132d0b
Define random_unitary constructor
mtfishman 8a1b555
Use MatrixAlgebraKit
mtfishman 6a849a7
Refactor in terms of in-place random_unitary
mtfishman 219ea49
Fix import
mtfishman 2e0e672
Simplify
mtfishman e47a544
Reorganize extensions
mtfishman bab22ac
Delete code duplication
mtfishman eb86d46
Format
mtfishman 0678785
Check square
mtfishman 9440534
Format
mtfishman 30999f2
Merge branch 'main' into random_unitary
mtfishman 879ef7d
Properly pass along RNG
mtfishman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...BlockSparseArraysGradedUnitRangesExt/TensorAlgebraBlockSparseArraysGradedUnitRangesExt.jl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module TensorAlgebraBlockSparseArraysGradedUnitRangesExt | ||
|
||
using BlockArrays: Block, blocksize | ||
using BlockSparseArrays: BlockSparseMatrix, @view! | ||
using GradedUnitRanges: AbstractGradedUnitRange, dual, tensor_product | ||
using Random: AbstractRNG | ||
using TensorAlgebra: TensorAlgebra, random_unitary! | ||
|
||
function TensorAlgebra.:⊗(a1::AbstractGradedUnitRange, a2::AbstractGradedUnitRange) | ||
return tensor_product(a1, a2) | ||
end | ||
|
||
function TensorAlgebra.square_zero_map( | ||
elt::Type, ax::Tuple{AbstractGradedUnitRange,Vararg{AbstractGradedUnitRange}} | ||
) | ||
return BlockSparseArray{elt}(undef, (dual.(ax)..., ax...)) | ||
end | ||
|
||
function TensorAlgebra.random_unitary!( | ||
rng::AbstractRNG, | ||
a::BlockSparseMatrix{ | ||
<:Any,<:Any,<:Any,<:Tuple{AbstractGradedUnitRange,Vararg{AbstractGradedUnitRange}} | ||
}, | ||
) | ||
# TODO: Define and use `blockdiagindices` | ||
# or `blockdiaglength`. | ||
for i in 1:blocksize(a, 1) | ||
a[Block(i, i)] = random_unitary!(rng, @view!(a[Block(i, i)])) | ||
end | ||
return a | ||
end | ||
|
||
end |
29 changes: 0 additions & 29 deletions
29
ext/TensorAlgebraGradedUnitRangesExt/TensorAlgebraGradedUnitRangesExt.jl
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something worth considering: in this function we are not guaranteed the user inputted a square matrix, in which case this function would still work, but spit out a random left- or right- isometry. I think if we call the function
unitary
, we probably want to check for this, either by an explicitchecksquare
, or some other means.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I had that in mind but forgot to add that check. We should definitely check it is square (and more specifically, the blocks are the same and the codomain is the dual of the domain).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is definitely that it is unitary in a strict sense, in that it literally maps the space back to itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After adding this check, I realized there is a crucial thing missing from this PR, which is specifying that the codomain and domain are duals of each other. That will require a separate PR to
fusedims
to support that, though @ogauthe is reworkingfusedims
/splitdims
to accommodate FusionTensors so I'll hold off on that for now.