-
Notifications
You must be signed in to change notification settings - Fork 1
/
gate_map.jl
652 lines (535 loc) · 19 KB
/
gate_map.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
module GateMap
# =========================================================================== #
# Imported modules
# =========================================================================== #
using Base
using LinearAlgebra
using StaticArrays
import QXZoo.GateOps
import QXZoo.DefaultGates
# =========================================================================== #
# Exported functions
# =========================================================================== #
export create_gate_1q, create_gate_2q
# =========================================================================== #
# Gate caching and retrieval
# =========================================================================== #
"""Module gate cache
Since many different circuits may use the same gates, keeping a module-global
cache makes sense to avoid recreating them. Each subcircuit can have a subset of
the global cache's gates."""
gates = Dict{Union{GateOps.GateSymbol, GateOps.GateSymbolP, Function}, Function}()
# TODO
# const gates = let .... end
"""
init_cache()
Initialise the cache for default gates used in circuit generation. Modules generating
gates not stored here should cache them for use by other circuits.
"""
function init_cache() #gates::Dict{Union{<:GateOps.AGateSymbol, Function}, Function})
push!(gates, DefaultGates.GateSymbols.p00 => p00)
push!(gates, DefaultGates.GateSymbols.p10 => p10)
push!(gates, DefaultGates.GateSymbols.p01 => p01)
push!(gates, DefaultGates.GateSymbols.p11 => p11)
push!(gates, DefaultGates.GateSymbols.I => I)
push!(gates, DefaultGates.GateSymbols.h => h)
push!(gates, DefaultGates.GateSymbols.x => x)
push!(gates, DefaultGates.GateSymbols.y => y)
push!(gates, DefaultGates.GateSymbols.z => z)
push!(gates, DefaultGates.GateSymbols.c_x => c_x)
push!(gates, DefaultGates.GateSymbols.c_y => c_y)
push!(gates, DefaultGates.GateSymbols.c_z => c_z)
push!(gates, DefaultGates.GateSymbols.r_x => r_x)
push!(gates, DefaultGates.GateSymbols.r_y => r_y)
push!(gates, DefaultGates.GateSymbols.r_z => r_z)
push!(gates, DefaultGates.GateSymbols.r_phase => r_phase)
push!(gates, DefaultGates.GateSymbols.c_r_x => c_r_x)
push!(gates, DefaultGates.GateSymbols.c_r_y => c_r_y)
push!(gates, DefaultGates.GateSymbols.c_r_z => c_r_z)
push!(gates, DefaultGates.GateSymbols.c_r_phase => c_r_phase)
push!(gates, DefaultGates.GateSymbols.s => s )
push!(gates, DefaultGates.GateSymbols.t => t )
return ;
end
# =========================================================================== #
# Custom gate storage: 1 qubit
# =========================================================================== #
"""
create_gate_1q(gate_label::String, gen_func::Function)
Creates a new user-defined gate, caches the generating function, and returns the
GateOps.GateSymbol key for use in a circuit.
# Examples
```julia-repl
```
"""
function create_gate_1q(gate_label::String, gen_func::Function)
mat2x2 = nothing
if applicable(gen_func, pi/2)
mat2x2 = gen_func(pi/2)
else
mat2x2 = gen_func()
end
if size(mat2x2) != (2,2)
error("Please ensure generated matrix is 2x2")
end
gs = GateOps.GateSymbol(Symbol(gate_label))
cache_gate!(gs, gen_func)
return gs
end
"""
create_gate_1q(gate_label::String, mat::SArray{Tuple{2,2},Complex{Float64},2,4})
Creates a new user-defined gate, caches the generating matrix, and returns the
GateOps.GateSymbol key for use in a circuit.
# Examples
```julia-repl
```
"""
function create_gate_1q(gate_label::String, mat::SArray{Tuple{2,2},Complex{Float64},2,4})
return create_gate_1q(gate_label, ()->mat)
end
"""
create_gate_1q(gate_label::String, mat::Array{Complex{Float64},2})
Creates a new user-defined gate, caches the generating matrix, and returns the
GateOps.GateSymbol key for use in a circuit. Matrix is converted to 2x2 StaticArrays
SMatrix internally.
# Examples
```julia-repl
```
"""
function create_gate_1q(gate_label::String, mat::Array{<:Number,2})
return create_gate_1q(gate_label, SArray{Tuple{2,2},Complex{Float64},2,4}(mat))
end
# =========================================================================== #
# Custom gate storage: 2 qubit
# =========================================================================== #
"""
create_gate_2q(gate_label::String, gen_func::Function)
Creates a new user-defined gate, caches the generating function, and returns the
GateOps.GateSymbol key for use in a circuit.
# Examples
```julia-repl
```
"""
function create_gate_2q(gate_label::String, gen_func::Function)
mat4x4 = nothing
if applicable(gen_func, pi/2)
mat4x4 = gen_func(pi/2)
else
mat4x4 = gen_func()
end
if size(mat4x4) != (4,4)
error("Please ensure generated matrix is 4x4")
end
gs = GateOps.GateSymbol(Symbol(gate_label))
cache_gate!(gs, gen_func)
return gs
end
"""
create_gate_2q(gate_label::String, mat::SArray{Tuple{2,2},Complex{Float64},2,4})
Creates a new user-defined gate, caches the generating matrix, and returns the
GateOps.GateSymbol key for use in a circuit.
# Examples
```julia-repl
```
"""
function create_gate_2q(gate_label::String, mat::SArray{Tuple{4,4},Complex{Float64},2,16})
return create_gate_2q(gate_label, ()->mat)
end
"""
create_gate_2q(gate_label::String, mat::Array{Complex{Float64},2})
Creates a new user-defined gate, caches the generating matrix, and returns the
GateOps.GateSymbol key for use in a circuit. Matrix is converted to 2x2 StaticArrays
SMatrix internally.
# Examples
```julia-repl
```
"""
function create_gate_2q(gate_label::String, mat::Array{<:Number,2})
return create_gate_2q(gate_label, SArray{Tuple{4,4},Complex{Float64},2,16}(mat))
end
# =========================================================================== #
"""
cache_gate!(label::GateOps.AGateSymbol, mat::Matrix{<:Number})
Adds a mapping between label=>mat for fast retrieval of gates in circuit generation.
# Examples
```julia-repl
julia> QXZoo.GateMap.cache_gate!(QXZoo.GateOps.GateSymbol(:mygate), ()->[ 1 0; 0 1])
```
"""
function cache_gate!(key::Union{GateOps.GateSymbol, GateOps.GateSymbolP, Function}, mat_func::Function)
if ~haskey(gates, key)
gates[key] = mat_func
end
return ;
end
"""
replace_gate!(label::GateOps.AGateSymbol, mat::Matrix{<:Number})
Replaces existing gate mapping as defined with cache_gate! otherwise performs no-op.
# Examples
```julia-repl
julia> QXZoo.GateMap.replace_gate!(QXZoo.GateOps.GateSymbol(:mygate), ()->[ 1 0; 0 -1])
```
"""
function replace_gate!(key::Union{GateOps.GateSymbol, GateOps.GateSymbolP, Function}, mat_func::Function)
if haskey(gates, key)
gates[key] = mat_func
end
return ;
end
# =========================================================================== #
# Projection operators
# =========================================================================== #
"""
p00()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the |0><0| projector gate.
# Examples
```julia-repl
julia> QXZoo.GateMap.p00()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
1.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im
```
"""
function p00()::SArray{Tuple{2,2},Complex{Float64},2,4}
return @SMatrix [1.0+0.0im 0.0; 0.0 0.0]
end
"""
p01()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the |0><1| projector gate.
# Examples
```julia-repl
julia> QXZoo.GateMap.p01()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
0.0+0.0im 1.0+0.0im
0.0+0.0im 0.0+0.0im
```
"""
function p01()::SArray{Tuple{2,2},Complex{Float64},2,4}
return @SMatrix [0.0 1.0+0.0im; 0.0 0.0]
end
"""
p10()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the |1><0| projector gate.
# Examples
```julia-repl
julia> QXZoo.GateMap.p10()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
0.0+0.0im 0.0+0.0im
1.0+0.0im 0.0+0.0im
```
"""
function p10()::SArray{Tuple{2,2},Complex{Float64},2,4}
return @SMatrix [0.0 0.0; 1.0+0.0im 0.0]
end
"""
p11()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the |1><1| projector gate.
# Examples
```julia-repl
julia> QXZoo.GateMap.p11()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
0.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im
```
"""
function p11()::SArray{Tuple{2,2},Complex{Float64},2,4}
return @SMatrix [0.0 0.0; 0.0 1.0+0.0im]
end
# =========================================================================== #
# Pauli operators
# =========================================================================== #
"""
x()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the Pauli-X gate.
# Examples
```julia-repl
julia> QXZoo.GateMap.x()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
0.0+0.0im 1.0+0.0im
1.0+0.0im 0.0+0.0im
```
"""
function x()::SArray{Tuple{2,2},Complex{Float64},2,4}
return @SMatrix [0.0 1.0+0.0im; 1.0+0.0im 0.0]
end
"""
y()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the Pauli-Y gate.
# Examples
```julia-repl
julia> QXZoo.GateMap.y()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
0.0+0.0im -0.0-1.0im
0.0+1.0im 0.0+0.0im
```
"""
function y()::SArray{Tuple{2,2},Complex{Float64},2,4}
return @SMatrix [0.0 -1.0im; 1.0im 0.0]
end
"""
z()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the Pauli-Z gate.
# Examples
```julia-repl
julia> QXZoo.GateMap.z()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
1.0+0.0im 0.0+0.0im
0.0+0.0im -1.0+0.0im
```
"""
function z()::SArray{Tuple{2,2},Complex{Float64},2,4}
return @SMatrix [1.0+0.0im 0.0; 0.0 -1.0+0.0im]
end
# =========================================================================== #
# Additional operators
# =========================================================================== #
"""
h()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the Hadamard gate.
# Examples
```julia-repl
julia> QXZoo.GateMap.h()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
0.707107+0.0im 0.707107+0.0im
0.707107+0.0im -0.707107+0.0im
```
"""
function h()::SArray{Tuple{2,2},Complex{Float64},2,4}
return SMatrix{2,2}([1.0+0.0im 1.0+0.0im; 1.0+0.0im -1.0+0.0im].*(1/sqrt(2)))
end
"""
I()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the 2x2 identity gate.
# Examples
```julia-repl
julia> QXZoo.GateMap.I()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
1.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im
```
"""
function I()::Diagonal{Complex{Float64},SArray{Tuple{2},Complex{Float64},1,2}}
return StaticArrays.SDiagonal(1.0+0im,1.0+0im)
end
"""
s()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the S gate (sqrt(Z)).
# Examples
```julia-repl
julia> QXZoo.GateMap.s()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
1.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+1.0im
```
"""
function s()::SArray{Tuple{2,2},Complex{Float64},2,4}
return sqrt(z())
end
"""
t()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the T gate (sqrt(S)).
# Examples
```julia-repl
julia> QXZoo.GateMap.t()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
1.0+0.0im 0.0+0.0im
0.0+0.0im 0.707107+0.707107im
```
"""
function t()::SArray{Tuple{2,2},Complex{Float64},2,4}
return sqrt(s())
end
# =========================================================================== #
# Rotation operators
# =========================================================================== #
"""
r_x(θ::Number)::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the parametric r_x gate: exp(-0.5im*θ*x())
# Examples
```julia-repl
julia> QXZoo.GateMap.r_x(pi/3)
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
0.866025+0.0im 0.0-0.5im
0.0-0.5im 0.866025+0.0im
```
"""
function r_x(θ::Number)::SArray{Tuple{2,2},Complex{Float64},2,4}
return exp(-1im*x()*θ/2)
end
"""
r_y(θ::Number)::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the parametric r_y gate: exp(-0.5im*θ*y())
# Examples
```julia-repl
julia> QXZoo.GateMap.r_y(pi/6)
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
0.965926+0.0im -0.258819+0.0im
0.258819+0.0im 0.965926+0.0im
```
"""
function r_y(θ::Number)::SArray{Tuple{2,2},Complex{Float64},2,4}
return exp(-1im*y()*θ/2)
end
"""
r_z(θ::Number)::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the parametric r_z gate: exp(-0.5im*θ*z())
# Examples
```julia-repl
julia> QXZoo.GateMap.r_z(pi/2)
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
0.707107-0.707107im 0.0+0.0im
0.0+0.0im 0.707107+0.707107im
```
"""
function r_z(θ::Number)::SArray{Tuple{2,2},Complex{Float64},2,4}
return exp(-1im*z()*θ/2)
end
"""
r_phase(θ::Number)::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the parametric phase shifting gate [1 0; 0 exp(1im*θ)].
Note, this is not the Phase gate.
# Examples
```julia-repl
julia> QXZoo.GateMap.r_phase(pi/4)
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
1.0+0.0im 0.0+0.0im
0.0+0.0im 0.707107+0.707107im
```
"""
function r_phase(θ::Number)::SArray{Tuple{2,2},Complex{Float64},2,4}
return [1 0; 0 exp(1im*θ)]
end
# =========================================================================== #
# Controlled Pauli operators
# =========================================================================== #
"""
c_x()::SArray{Tuple{4,4},Complex{Float64},2,16}
Function which generates the controlled Pauli-X gate as a block diagonal 4x4 matrix.
# Examples
```julia-repl
julia> QXZoo.GateMap.c_x()
4×4 StaticArrays.SArray{Tuple{4,4},Complex{Float64},2,16} with indices SOneTo(4)×SOneTo(4):
1.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 0.0+0.0im 1.0+0.0im
0.0+0.0im 0.0+0.0im 1.0+0.0im 0.0+0.0im
```
"""
function c_x()::SArray{Tuple{4,4},Complex{Float64},2,16}
return kron(p00(), I()) + kron(p11(), x())
end
"""
c_y()::SArray{Tuple{4,4},Complex{Float64},2,16}
Function which generates the controlled Pauli-X gate as a block diagonal 4x4 matrix.
# Examples
```julia-repl
julia> QXZoo.GateMap.c_y()
4×4 StaticArrays.SArray{Tuple{4,4},Complex{Float64},2,16} with indices SOneTo(4)×SOneTo(4):
1.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 0.0+0.0im 0.0-1.0im
0.0+0.0im 0.0+0.0im 0.0+1.0im 0.0+0.0im
```
"""
function c_y()::SArray{Tuple{4,4},Complex{Float64},2,16}
return kron(p00(), I()) + kron(p11(), y())
end
"""
c_z()::SArray{Tuple{4,4},Complex{Float64},2,16}
Function which generates the controlled Pauli-X gate as a block diagonal 4x4 matrix.
# Examples
```julia-repl
julia> QXZoo.GateMap.c_z()
4×4 StaticArrays.SArray{Tuple{4,4},Complex{Float64},2,16} with indices SOneTo(4)×SOneTo(4):
1.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 1.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 0.0+0.0im -1.0+0.0im
```
"""
function c_z()::SArray{Tuple{4,4},Complex{Float64},2,16}
return kron(p00(), I()) + kron(p11(), z())
end
# =========================================================================== #
# Controlled rotation operators
# =========================================================================== #
"""
c_r_x(θ::Number)::SArray{Tuple{4,4},Complex{Float64},2,16}
Function which generates the controlled parametric r_x gate as a block diagonal 4x4 matrix.
# Examples
```julia-repl
julia> QXZoo.GateMap.c_r_x(pi/3)
4×4 StaticArrays.SArray{Tuple{4,4},Complex{Float64},2,16} with indices SOneTo(4)×SOneTo(4):
1.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 0.866025+0.0im 0.0-0.5im
0.0+0.0im 0.0+0.0im 0.0-0.5im 0.866025+0.0im
```
"""
function c_r_x(θ::Number)::SArray{Tuple{4,4},Complex{Float64},2,16}
return kron(p00(), I()) + kron(p11(), r_x(θ))
end
"""
c_r_y(θ::Number)::SArray{Tuple{4,4},Complex{Float64},2,16}
Function which generates the controlled parametric r_y gate as a block diagonal 4x4 matrix.
# Examples
```julia-repl
julia> QXZoo.GateMap.c_r_y(pi/4)
4×4 StaticArrays.SArray{Tuple{4,4},Complex{Float64},2,16} with indices SOneTo(4)×SOneTo(4):
1.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 0.92388+0.0im -0.382683+0.0im
0.0+0.0im 0.0+0.0im 0.382683+0.0im 0.92388+0.0im
```
"""
function c_r_y(θ::Number)::SArray{Tuple{4,4},Complex{Float64},2,16}
return kron(p00(), I()) + kron(p11(), r_y(θ))
end
"""
c_r_z(θ::Number)::SArray{Tuple{4,4},Complex{Float64},2,16}
Function which generates the controlled parametric r_y gate as a block diagonal 4x4 matrix.
# Examples
```julia-repl
julia> QXZoo.GateMap.c_r_z(pi/6)
4×4 StaticArrays.SArray{Tuple{4,4},Complex{Float64},2,16} with indices SOneTo(4)×SOneTo(4):
1.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 0.965926-0.258819im 0.0+0.0im
0.0+0.0im 0.0+0.0im 0.0+0.0im 0.965926+0.258819im
```
"""
function c_r_z(θ::Number)::SArray{Tuple{4,4},Complex{Float64},2,16}
return kron(p00(), I()) + kron(p11(), r_z(θ))
end
"""
c_r_phase(θ::Number)::SArray{Tuple{4,4},Complex{Float64},2,16}
Function which generates the controlled parametric phase shifting gate [1 0; 0 exp(1im*θ)] as a block diagonal 4x4 matrix.
Note, this is not the controlled Phase gate.
# Examples
```julia-repl
julia> QXZoo.GateMap.c_r_phase(pi/9)
4×4 StaticArrays.SArray{Tuple{4,4},Complex{Float64},2,16} with indices SOneTo(4)×SOneTo(4):
1.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 1.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 0.0+0.0im 0.939693+0.34202im
```
"""
function c_r_phase(θ::Number)::SArray{Tuple{4,4},Complex{Float64},2,16}
return kron(p00(), I()) + kron(p11(), r_phase(θ))
end
# =========================================================================== #
"""
Allow access directly using a gate-call for ease-of-use
"""
function Base.getindex(gc::Dict{GateOps.AGateSymbol, Matrix{<:Number}}, gs::GateOps.AGateCall)
return gc[gs.gate_label]
end
"""
clear_cache()
Empty the stored gates from the cache.
"""
function clear_cache()
empty!(gates)
end
end