Skip to content

Commit

Permalink
Reduce RepeatedBlock compiling time (#501)
Browse files Browse the repository at this point in the history
* reduce repeated compiling time

* update KrylovKit
  • Loading branch information
GiggleLiu authored Apr 12, 2024
1 parent c23f515 commit 47034ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
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

0 comments on commit 47034ce

Please sign in to comment.