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

Reduce RepeatedBlock compiling time #501

Merged
merged 2 commits into from
Apr 12, 2024
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
2 changes: 1 addition & 1 deletion lib/YaoBlocks/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CacheServers = "0.2"
ChainRulesCore = "1.11"
DocStringExtensions = "0.8, 0.9"
InteractiveUtils = "1"
KrylovKit = "0.5, 0.6"
KrylovKit = "0.5, 0.6, 0.7"
LegibleLambdas = "0.2, 0.3"
LinearAlgebra = "1"
LuxurySparse = "0.7"
Expand Down
8 changes: 4 additions & 4 deletions lib/YaoBlocks/src/composite/repeated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ struct RepeatedBlock{D,C,GT<:AbstractBlock} <: AbstractContainer{GT,D}
end

function RepeatedBlock(n::Int, block::AbstractBlock{D}, locs::NTuple{C,Int}) where {D,C}
@assert_locs_safe n Tuple(i:i+nqudits(block)-1 for i in locs)
@assert_locs_safe n [i:i+nqudits(block)-1 for i in locs]
nqudits(block) > 1 && throw(
ArgumentError("RepeatedBlock does not support multi-qubit content for the moment."),
)
# sort the locations
locs = TupleTools.sort(locs)
return RepeatedBlock{D,C,typeof(block)}(n, block, locs)
slocs = sort([locs...])
return RepeatedBlock{D,C,typeof(block)}(n, block, (slocs...,))
end

function RepeatedBlock(n::Int, block::AbstractBlock{D}, locs::UnitRange{Int}) where {D}
Expand Down Expand Up @@ -105,7 +105,7 @@ julia> @time apply!(reg, chain([put(20, i=>X) for i=1:20]));
Base.repeat(n::Int, x::AbstractBlock, locs::Int...) = repeat(n, x, locs)
Base.repeat(n::Int, x::AbstractBlock, locs::NTuple{C,Int}) where {C} =
RepeatedBlock(n, x, locs)
Base.repeat(n::Int, x::AbstractBlock, locs) = repeat(n, x, locs...)
Base.repeat(n::Int, x::AbstractBlock, locs) = repeat(n, x, (locs...,))
Base.repeat(n::Int, x::AbstractBlock, locs::UnitRange) = RepeatedBlock(n, x, locs)
Base.repeat(n::Int, x::AbstractBlock) = RepeatedBlock(n, x)
Base.repeat(x::AbstractBlock) = @λ(n -> repeat(n, x))
Expand Down
Loading