This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* new measure * new mutiple qubit gates * multi-gate labeling
- Loading branch information
Showing
9 changed files
with
105 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 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,35 @@ | ||
using YaoBlocks | ||
export LabelBlock | ||
|
||
""" | ||
LabelBlock{BT,N} <: TagBlock{N} | ||
A marker to mark a circuit applying on a continous block for better plotting. | ||
""" | ||
struct LabelBlock{BT<:AbstractBlock,N} <: TagBlock{BT,N} | ||
content::BT | ||
name::String | ||
end | ||
|
||
YaoBlocks.content(cb::LabelBlock) = cb.content | ||
function LabelBlock(x::BT, name::String) where {N,BT<:AbstractBlock{N}} | ||
LabelBlock{BT,N}(x, name) | ||
end | ||
|
||
function is_continuous_chunk(x) | ||
length(x) == 0 && return true | ||
return length(x) == maximum(x)-minimum(x)+1 | ||
end | ||
|
||
YaoBlocks.PropertyTrait(::LabelBlock) = YaoBlocks.PreserveAll() | ||
YaoBlocks.mat(::Type{T}, blk::LabelBlock) where {T} = mat(T, content(blk)) | ||
YaoBlocks.apply!(reg::YaoBlocks.AbstractRegister, blk::LabelBlock) = apply!(reg, content(blk)) | ||
YaoBlocks.chsubblocks(blk::LabelBlock, target::AbstractBlock) = LabelBlock(target, blk.name) | ||
|
||
Base.adjoint(x::LabelBlock) = LabelBlock(adjoint(content(x)), endswith(x.name, "†") ? x.name[1:end-1] : x.name*"†") | ||
Base.copy(x::LabelBlock) = LabelBlock(copy(content(x)), x.name) | ||
YaoBlocks.Optimise.to_basictypes(block::LabelBlock) = block | ||
|
||
export label | ||
label(b::AbstractBlock, str::String) = LabelBlock(b, str) | ||
|
This file contains 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 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,28 @@ | ||
using YaoPlots, Yao | ||
using Test | ||
|
||
@testset "LabelBlock" begin | ||
x = put(5, (2,3)=>matblock(rand_unitary(4))) | ||
cb = LabelBlock(x, "x") | ||
@test mat(copy(cb)) == mat(cb) | ||
@test isunitary(cb) | ||
@test ishermitian(cb) == ishermitian(x) | ||
@test isreflexive(cb) == isreflexive(x) | ||
@test mat(cb) == mat(x) | ||
reg = rand_state(5) | ||
@test apply!(copy(reg), cb) ≈ apply!(copy(reg), x) | ||
@test cb' isa LabelBlock && mat(cb') ≈ mat(cb)' | ||
@test (cb').name == "x†" && (cb'').name == "x" | ||
|
||
y = put(5, (3,4)=>matblock(rand_unitary(4))) | ||
cc = chsubblocks(cb, y) | ||
@test YaoPlots.is_continuous_chunk([1,2,3]) == true | ||
@test YaoPlots.is_continuous_chunk([1,2,4]) == false | ||
@test YaoPlots.is_continuous_chunk([3,2,4]) == true | ||
|
||
c1 = chain(5, [put(5, (2,3)=>label(SWAP, "SWAP")), put(5, 2=>label(I2, "id")), put(5, 2=>label(X, "X")), control(5, (5,3), (2,4,1)=>put(3, (1,3)=>label(SWAP, "SWAP")))]) | ||
c2 = chain(5, [put(5, (2,3)=>label(SWAP, "SWAP")), put(5, 2=>label(I2, "id")), put(5, 2=>label(X, "X")), control(5, (5,3), (2,4,1)=>put(3, (1,2)=>label(SWAP, "SWAP")))]) | ||
|
||
@test vizcircuit(c1) isa Context | ||
@test_throws ErrorException vizcircuit(c2) | ||
end |
This file contains 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