From 47034ce517e98bb2bd724a87abfa521ec7ce488a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jinguo=20Liu=20=28=E5=88=98=E9=87=91=E5=9B=BD=29?= Date: Fri, 12 Apr 2024 11:21:52 +0800 Subject: [PATCH] Reduce RepeatedBlock compiling time (#501) * reduce repeated compiling time * update KrylovKit --- lib/YaoBlocks/Project.toml | 2 +- lib/YaoBlocks/src/composite/repeated.jl | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/YaoBlocks/Project.toml b/lib/YaoBlocks/Project.toml index 490a200a..4d82965a 100644 --- a/lib/YaoBlocks/Project.toml +++ b/lib/YaoBlocks/Project.toml @@ -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" diff --git a/lib/YaoBlocks/src/composite/repeated.jl b/lib/YaoBlocks/src/composite/repeated.jl index b3d7bc13..eed9e79c 100644 --- a/lib/YaoBlocks/src/composite/repeated.jl +++ b/lib/YaoBlocks/src/composite/repeated.jl @@ -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} @@ -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))