-
Notifications
You must be signed in to change notification settings - Fork 32
/
interface.jl
187 lines (147 loc) · 3.78 KB
/
interface.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
module Op
using YaoBlocks
const n = YaoBlocks.ConstGate.P1
end
"""
emulate!(prob)
Run emulation of a given problem.
"""
function emulate! end
"""
rydberg_h(atoms; [C=2π * 862690 * MHz*µm^6], Ω[, ϕ, Δ])
Create a rydberg hamiltonian
```math
∑ \\frac{C}{|r_i - r_j|^6} n_i n_j + \\frac{Ω}{2} σ_x - Δ σ_n
```
shorthand for
```julia
RydInteract(C, atoms) + SumOfXPhase(length(atoms), Ω, ϕ) - SumOfN(length(atoms), Δ)
```
# Arguments
- `atoms`: a collection of atom positions.
# Keyword Arguments
- `C`: optional, default unit is `MHz*µm^6`, interation parameter,
see also [`RydInteract`](@ref).
- `Ω`: optional, default unit is `MHz`, Rabi frequencies, divided by 2, see also [`SumOfX`](@ref).
- `Δ`: optional, default unit is `MHz`, detuning parameter, see [`SumOfN`](@ref).
- `ϕ`: optional, does not have unit, the phase, see [`SumOfXPhase`](@ref).
!!! tips
The rabi frequencies are divided by two in the Rydberg hamiltonian unlike
directly constructing via [`SumOfX`](@ref) or [`SumOfXPhase`](@ref).
!!! tips
The parameters of Hamiltonian have their own default units to match hardware,
one can use [`Unitful.jl`](https://github.com/PainterQubits/Unitful.jl)
to specify their units explicitly. If the units are specified explicitly,
they will be converted to default units automatically.
# Example
```julia-repl
julia> using Bloqade
julia> atoms = [(1, ), (2, ), (3, ), (4, )]
4-element Vector{Tuple{Int64}}:
(1,)
(2,)
(3,)
(4,)
julia> rydberg_h(atoms)
∑ 5.42e6/|r_i-r_j|^6 n_i n_j
```
```julia-repl
julia> rydberg_h(atoms; Ω=0.1)
nqubits: 4
+
├─ ∑ 5.42e6/|r_i-r_j|^6 n_i n_j
└─ 0.05 ⋅ ∑ σ^x_i
```
"""
function rydberg_h(atom_positions; C=2π * 862690, Ω=nothing, ϕ=nothing, Δ=nothing)
positions = map(atom_positions) do pos
(pos..., )
end
nsites = length(positions)
term = RydInteract(positions, C)
Ω = div_by_two(Ω)
if !isnothing(Ω) && !isnothing(ϕ)
term += SumOfXPhase(nsites, Ω, ϕ)
elseif !isnothing(Ω) && isnothing(ϕ)
term += SumOfX(nsites, Ω)
end
if !isnothing(Δ)
term -= SumOfN(nsites, Δ)
end
return YaoBlocks.Optimise.simplify(term)
end
function div_by_two(Ω)
isnothing(Ω) && return
if is_const_param(Ω)
return Ω ./ 2
end
return if Ω isa Vector
map(Ω) do Ω_i
t->Ω_i(t) / 2
end
else
t->Ω(t)/2
end
end
attime(t::Real) = h->attime(h, t)
function attime(h::AbstractBlock, t::Real)
blks = map(subblocks(h)) do blk
attime(blk, t)
end
return chsubblocks(h, blks)
end
# Yao Blocks cannot take time-dependent function
"""
attime(h, t)
attime(t)
Return the hamiltonian at time `t`.
# Example
```julia
julia> h = rydberg_h(atoms; Ω=sin)
nqudits: 4
+
├─ ∑ 5.42e6/|r_i-r_j|^6 n_i n_j
└─ Ω(t) ⋅ ∑ σ^x_i
julia> h |> attime(0.1)
nqudits: 4
+
├─ ∑ 5.42e6/|r_i-r_j|^6 n_i n_j
└─ 0.0499 ⋅ ∑ σ^x_i
```
"""
attime(h::PrimitiveBlock, ::Real) = h
function attime(h::SumOfX, t::Real)
is_const_param(h.Ω) && return h
if h.Ω isa Vector
SumOfX(h.nsites, map(x->x(t), h.Ω))
else
SumOfX(h.nsites, h.Ω(t))
end
end
function attime(h::SumOfXPhase, t::Real)
if is_const_param(h.Ω)
Ω = h.Ω
elseif h.Ω isa Vector
Ω = map(x->x(t), h.Ω)
else
Ω = h.Ω(t)
end
if is_const_param(h.ϕ)
ϕ = h.ϕ
elseif h.ϕ isa Vector
ϕ = map(x->x(t), h.ϕ)
else
ϕ = h.ϕ(t)
end
return SumOfXPhase(h.nsites, Ω, ϕ)
end
function attime(h::Union{SumOfZ, SumOfN}, t::Real)
if is_const_param(h.Δ)
Δ = h.Δ
elseif h.Δ isa Vector
Δ = map(x->x(t), h.Δ)
else
Δ = h.Δ(t)
end
return typeof(h)(h.nsites, Δ)
end