Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.

Commit

Permalink
fix doc test
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger-luo committed Dec 13, 2019
1 parent 745277f commit 092fa86
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 52 deletions.
14 changes: 7 additions & 7 deletions src/composite/control.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ Return a [`ControlBlock`](@ref) with number of active qubits `n` and control loc
julia> control(4, (1, 2), 3=>X)
nqubits: 4
control(1, 2)
└─ (3,) X gate
└─ (3,) X
julia> control(4, 1, 3=>X)
nqubits: 4
control(1)
└─ (3,) X gate
└─ (3,) X
```
"""
control(total::Int, ctrl_locs, target::Pair) = ControlBlock{total}(Tuple(ctrl_locs), target)
Expand All @@ -94,10 +94,10 @@ Return a lambda that takes the number of total active qubits as input. See also
```jldoctest; setup=:(using YaoBlocks)
julia> control((2, 3), 1=>X)
(n -> control(n, (2, 3), 1 => X gate))
(n -> control(n, (2, 3), 1 => X))
julia> control(2, 1=>X)
(n -> control(n, 2, 1 => X gate))
(n -> control(n, 2, 1 => X))
```
"""
control(ctrl_locs, target::Pair) = (n -> control(n, ctrl_locs, target))
Expand All @@ -113,10 +113,10 @@ Return a lambda that takes a `Tuple` of control qubits locs as input. See also
```jldoctest; setup=:(using YaoBlocks)
julia> control(1=>X)
(ctrl_locs -> control(ctrl_locs, 1 => X gate))
(ctrl_locs -> control(ctrl_locs, 1 => X))
julia> control((2, 3) => YaoBlocks.ConstGate.CNOT)
(ctrl_locs -> control(ctrl_locs, (2, 3) => CNOT gate))
(ctrl_locs -> control(ctrl_locs, (2, 3) => CNOT))
```
"""
control(target::Pair) = (ctrl_locs -> control(ctrl_locs, target))
Expand Down Expand Up @@ -148,7 +148,7 @@ Return a speical [`ControlBlock`](@ref), aka CNOT gate with number of active qub
julia> cnot(3, (2, 3), 1)
nqubits: 3
control(2, 3)
└─ (1,) X gate
└─ (1,) X
julia> cnot(2, 1)
(n -> cnot(n, 2, 1))
Expand Down
20 changes: 10 additions & 10 deletions src/composite/kron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ and a `Y` gate on the `3`rd qubit.
julia> kron(4, 1=>X, 3=>Y)
nqubits: 4
kron
├─ 1=>X gate
└─ 3=>Y gate
├─ 1=>X
└─ 3=>Y
```
"""
Expand All @@ -88,10 +88,10 @@ You can use kronecker product to composite small blocks to a large blocks.
julia> kron(X, Y, Z, Z)
nqubits: 4
kron
├─ 1=>X gate
├─ 2=>Y gate
├─ 3=>Z gate
└─ 4=>Z gate
├─ 1=>X
├─ 2=>Y
├─ 3=>Z
└─ 4=>Z
```
"""
Expand Down Expand Up @@ -127,16 +127,16 @@ If you don't know the number of qubit yet, or you are just too lazy, it is fine.
```jldoctest; setup=:(using YaoBlocks)
julia> kron(put(1=>X) for _ in 1:2)
(n -> kron(n, (n -> put(n, 1 => X gate)), (n -> put(n, 1 => X gate))))
(n -> kron(n, (n -> put(n, 1 => X)), (n -> put(n, 1 => X))))
julia> kron(X for _ in 1:2)
nqubits: 2
kron
├─ 1=>X gate
└─ 2=>X gate
├─ 1=>X
└─ 2=>X
julia> kron(1=>X, 3=>Y)
(n -> kron(n, 1 => X gate, 3 => Y gate))
(n -> kron(n, 1 => X, 3 => Y))
```
"""
Base.kron(blocks::Pair{<:Any,<:AbstractBlock}...) = (n -> kron(n, blocks...))
Expand Down
10 changes: 5 additions & 5 deletions src/composite/put_block.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ location and block to put on.
julia> put(4, 1=>X)
nqubits: 4
put on (1)
└─ X gate
└─ X
```
If you want to put a multi-qubit gate on specific locations, you need to write down all possible locations.
Expand All @@ -39,8 +39,8 @@ julia> put(4, (1, 3)=>kron(X, Y))
nqubits: 4
put on (1, 3)
└─ kron
├─ 1=>X gate
└─ 2=>Y gate
├─ 1=>X
└─ 2=>Y
```
The outter locations creates a scope which make it seems to be a contiguous two qubits for the block inside `PutBlock`.
Expand All @@ -63,7 +63,7 @@ Lazy curried version of [`put`](@ref).
```jldoctest; setup=:(using YaoBlocks)
julia> put(1=>X)
(n -> put(n, 1 => X gate))
(n -> put(n, 1 => X))
```
"""
put(pa::Pair) = (n -> put(n, pa))
Expand Down Expand Up @@ -124,7 +124,7 @@ Create a `n`-qubit [`Swap`](@ref) gate which swap `loc1` and `loc2`.
julia> swap(4, 1, 2)
nqubits: 4
put on (1, 2)
└─ SWAP gate
└─ SWAP
```
"""
swap(n::Int, loc1::Int, loc2::Int) = Swap{n}((loc1, loc2))
Expand Down
4 changes: 2 additions & 2 deletions src/composite/repeated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ This will create a repeat block which puts 4 X gates on each location.
julia> repeat(4, X)
nqubits: 4
repeat on (1, 2, 3, 4)
└─ X gate
└─ X
```
You can also specify the location
Expand All @@ -53,7 +53,7 @@ You can also specify the location
julia> repeat(4, X, (1, 2))
nqubits: 4
repeat on (1, 2)
└─ X gate
└─ X
```
But repeat won't copy the gate, thus, if it is a gate with parameter, e.g a `phase(0.1)`, the parameter
Expand Down
8 changes: 4 additions & 4 deletions src/composite/subroutine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ julia> cc = subroutine(4, kron(X, Y), (1, 3))
nqubits: 4
Subroutine: (1, 3)
└─ kron
├─ 1=>X gate
└─ 2=>Y gate
├─ 1=>X
└─ 2=>Y
julia> pp = chain(4, put(1=>X), put(3=>Y))
nqubits: 4
chain
├─ put on (1)
│ └─ X gate
│ └─ X
└─ put on (3)
└─ Y gate
└─ Y
julia> apply!(copy(r), cc) ≈ apply!(copy(r), pp)
true
Expand Down
6 changes: 3 additions & 3 deletions src/composite/tag/cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ it calls [`mat`](@ref), and use the cached matrix in the following calculations.
julia> cache(control(3, 1, 2=>X))
nqubits: 3
[cached] control(1)
└─ (2,) X gate
└─ (2,) X
julia> chain(cache(control(3, 1, 2=>X)), repeat(H))
nqubits: 3
chain
├─ [cached] control(1)
│ └─ (2,) X gate
│ └─ (2,) X
└─ repeat on (1, 2, 3)
└─ H gate
└─ H
```
"""
Expand Down
8 changes: 4 additions & 4 deletions src/composite/tag/scale.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ export Scale, factor
```jldoctest; setup=:(using YaoBlocks)
julia> 2 * X
[scale: 2] X gate
[scale: 2] X
julia> im * Z
[+im] Z gate
[+im] Z
julia> -im * Z
[-im] Z gate
[-im] Z
julia> -Z
[-] Z gate
[-] Z
```
"""
struct Scale{S<:Union{Number,Val},N,BT<:AbstractBlock{N}} <: TagBlock{BT,N}
Expand Down
12 changes: 6 additions & 6 deletions src/composite/unitary_channel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ The unitary channel is defined as below in Kraus representation
julia> UnitaryChannel([X, Y, Z])
nqubits: 1
unitary_channel
├─ [1.0] X gate
├─ [1.0] Y gate
└─ [1.0] Z gate
├─ [1.0] X
├─ [1.0] Y
└─ [1.0] Z
```
Or with weights
Expand All @@ -54,9 +54,9 @@ Or with weights
julia> UnitaryChannel([X, Y, Z], [0.1, 0.2, 0.7])
nqubits: 1
unitary_channel
├─ [0.1] X gate
├─ [0.2] Y gate
└─ [0.7] Z gate
├─ [0.1] X
├─ [0.2] Y
└─ [0.7] Z
```
"""
struct UnitaryChannel{N,W<:AbstractWeights} <: CompositeBlock{N}
Expand Down
6 changes: 3 additions & 3 deletions src/primitive/rotation_gate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Return a [`RotationGate`](@ref) on X axis.
```jldoctest; setup=:(using YaoBlocks)
julia> Rx(0.1)
rot(XGate, 0.1)
rot(X, 0.1)
```
"""
Rx(theta) = RotationGate(X, theta)
Expand All @@ -52,7 +52,7 @@ Return a [`RotationGate`](@ref) on Y axis.
```jldoctest; setup=:(using YaoBlocks)
julia> Ry(0.1)
rot(YGate, 0.1)
rot(Y, 0.1)
```
"""
Ry(theta) = RotationGate(Y, theta)
Expand All @@ -66,7 +66,7 @@ Return a [`RotationGate`](@ref) on Z axis.
```jldoctest; setup=:(using YaoBlocks)
julia> Rz(0.1)
rot(ZGate, 0.1)
rot(Z, 0.1)
```
"""
Rz(theta) = RotationGate(Z, theta)
Expand Down
16 changes: 8 additions & 8 deletions src/treeutils/address_manipulate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ julia> c = chain(5, repeat(H, 1:5), put(2=>X), kron(1=>X, 3=>Y))
nqubits: 5
chain
├─ repeat on (1, 2, 3, 4, 5)
│ └─ H gate
│ └─ H
├─ put on (2)
│ └─ X gate
│ └─ X
└─ kron
├─ 1=>X gate
└─ 3=>Y gate
├─ 1=>X
└─ 3=>Y
julia> map_address(c, AddressInfo(10, [6,7,8,9,10]))
nqubits: 10
chain
├─ repeat on (6, 7, 8, 9, 10)
│ └─ H gate
│ └─ H
├─ put on (7)
│ └─ X gate
│ └─ X
└─ kron
├─ 6=>X gate
└─ 8=>Y gate
├─ 6=>X
└─ 8=>Y
```
"""
function map_address end
Expand Down

0 comments on commit 092fa86

Please sign in to comment.