Skip to content
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

Move nsubsystems from QOBase #19

Merged
merged 5 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# News

## v0.3.3

- Add `nsubsystems` for computing the number of subsystems in a state.

## v0.3.2

- Cleanup - removing forgotten debug print statements.
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QuantumInterface"
uuid = "5717a53b-5d69-4fa3-b976-0bf2f97ca1e5"
authors = ["QuantumInterface.jl contributors"]
version = "0.3.2"
version = "0.3.3"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
8 changes: 8 additions & 0 deletions src/embed_permute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,11 @@
end

permutesystems(a::AbstractOperator, perm) = arithmetic_unary_error("Permutations of subsystems", a)

nsubsystems(s::AbstractKet) = nsubsystems(basis(s))
function nsubsystems(s::AbstractOperator)
s.basis_l == s.basis_r || throw(ArgumentError("`nsubsystem(::AbstractOperator)` is well defined only if the left and right bases are the same"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

same comment as with ::AbstractKet. We can not rely on AbstractOperator to have .basis_l and .basis_r fields.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think a basis(op) call will raise an error if the left and right basis are not the same, so maybe just use it directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should we stick to throwing the current error message with the basis(op) in a try catch or just let the basis(op) error show when the bases are unequal?

Copy link
Collaborator

Choose a reason for hiding this comment

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

no need to stick to the current message, it is fine to rely on whatever message basis throws. Just check that it actually works (you know, never trust me, I can always be wrong ;)

nsubsystems(s.basis_l)

Check warning on line 91 in src/embed_permute.jl

View check run for this annotation

Codecov / codecov/patch

src/embed_permute.jl#L88-L91

Added lines #L88 - L91 were not covered by tests
end
nsubsystems(b::CompositeBasis) = length(b.bases)
nsubsystems(b::Basis) = 1

Check warning on line 94 in src/embed_permute.jl

View check run for this annotation

Codecov / codecov/patch

src/embed_permute.jl#L93-L94

Added lines #L93 - L94 were not covered by tests
Loading