@@ -6,6 +6,10 @@ Subtypes include [`Gate`](@ref), [`Noise`](@ref), [`Observable`](@ref BraketSimu
6
6
"""
7
7
abstract type Operator end
8
8
9
+ abstract type Parametrizable end
10
+ struct Parametrized end
11
+ struct NonParametrized end
12
+
9
13
"""
10
14
QuantumOperator < Operator
11
15
@@ -15,28 +19,20 @@ Subtypes include [`Gate`](@ref) and [`Noise`](@ref).
15
19
abstract type QuantumOperator <: Operator end
16
20
StructTypes. StructType (:: Type{QuantumOperator} ) = StructTypes. AbstractType ()
17
21
StructTypes. subtypes (:: Type{QuantumOperator} ) = (h= H, i= I, x= X, y= Y, z= Z, s= S, si= Si, t= T, ti= Ti, v= V, vi= Vi, cnot= CNot, swap= Swap, iswap= ISwap, cv= CV, cy= CY, cz= CZ, ecr= ECR, ccnot= CCNot, cswap= CSwap, unitary= Unitary, rx= Rx, ry= Ry, rz= Rz, phaseshift= PhaseShift, pswap= PSwap, xy= XY, cphaseshift= CPhaseShift, cphaseshift00= CPhaseShift00, cphaseshift01= CPhaseShift01, cphaseshift10= CPhaseShift10, xx= XX, yy= YY, zz= ZZ, gpi= GPi, gpi2= GPi2, ms= MS, prx= PRx, u= U, gphase= GPhase, kraus= Kraus, bit_flip= BitFlip, phase_flip= PhaseFlip, pauli_channel= PauliChannel, amplitude_damping= AmplitudeDamping, phase_damping= PhaseDamping, depolarizing= Depolarizing, two_qubit_dephasing= TwoQubitDephasing, two_qubit_depolarizing= TwoQubitDepolarizing, generalized_amplitude_damping= GeneralizedAmplitudeDamping, multi_qubit_pauli_channel= MultiQubitPauliChannel, measure= Measure, reset= Reset, barrier= Barrier, delay= Delay)
18
-
19
-
20
- abstract type Parametrizable end
21
- struct Parametrized end
22
- struct NonParametrized end
22
+ parameters (:: QuantumOperator ) = FreeParameter[]
23
23
24
24
struct PauliEigenvalues{N}
25
25
coeff:: Float64
26
26
PauliEigenvalues {N} (coeff:: Float64 = 1.0 ) where {N} = new (coeff)
27
27
end
28
28
PauliEigenvalues (:: Val{N} , coeff:: Float64 = 1.0 ) where {N} = PauliEigenvalues {N} (coeff)
29
- Base. length (p:: PauliEigenvalues{N} ) where {N} = 2 ^ N
30
- function Base. iterate (p:: PauliEigenvalues{N} , ix:: Int = 1 ) where {N}
31
- return ix <= length (p) ? (p[ix], ix+ 1 ) : nothing
32
- end
33
-
29
+ Base. length (:: PauliEigenvalues{N} ) where {N} = 2 ^ N
30
+ Base. iterate (p:: PauliEigenvalues{N} , ix:: Int = 1 ) where {N} = ix <= length (p) ? (p[ix], ix+ 1 ) : nothing
34
31
Base. getindex (p:: PauliEigenvalues{1} , i:: Int ):: Float64 = getindex ((p. coeff, - p. coeff), i)
35
32
function Base. getindex (p:: PauliEigenvalues{N} , i:: Int ):: Float64 where N
36
33
i_block = div (i- 1 , 2 )
37
34
split = div (2 ^ (N- 1 )- 1 , 2 )
38
35
if N < 5
39
- total_evs = 2 ^ N
40
36
is_front = ! isodd (mod (i- 1 , 2 ))
41
37
ev = is_front ? p. coeff : - p. coeff
42
38
mi = mod (i_block, 2 )
@@ -57,8 +53,6 @@ function Base.getindex(p::PauliEigenvalues{N}, i::Int)::Float64 where N
57
53
end
58
54
Base. getindex (p:: PauliEigenvalues{N} , ix:: Vector{Int} ) where {N} = [p[i] for i in ix]
59
55
60
- parameters (o:: QuantumOperator ) = FreeParameter[]
61
-
62
56
"""
63
57
Measure(index) <: QuantumOperator
64
58
@@ -68,54 +62,41 @@ struct Measure <: QuantumOperator
68
62
index:: Int
69
63
end
70
64
Measure () = Measure (- 1 )
71
- Parametrizable (m:: Measure ) = NonParametrized ()
72
- qubit_count (:: Type{Measure} ) = 1
73
- qubit_count (m:: Measure ) = qubit_count (Measure)
74
65
StructTypes. constructfrom (:: Type{Measure} , nt) = Measure ()
75
66
76
67
"""
77
- Reset(index ) <: QuantumOperator
68
+ Reset() <: QuantumOperator
78
69
79
- Represents an active reset operation on targeted qubit, stored in the classical register at `index` .
70
+ Represents an active reset operation on targeted qubit.
80
71
For now, this is a no-op.
81
72
"""
82
- struct Reset <: QuantumOperator
83
- index:: Int
84
- end
85
- Reset () = Reset (- 1 )
86
- Parametrizable (m:: Reset ) = NonParametrized ()
87
- qubit_count (:: Type{Reset} ) = 1
88
- qubit_count (m:: Reset ) = qubit_count (Reset)
73
+ struct Reset <: QuantumOperator end
89
74
StructTypes. constructfrom (:: Type{Reset} , nt) = Reset ()
90
75
91
76
"""
92
- Barrier(index ) <: QuantumOperator
77
+ Barrier() <: QuantumOperator
93
78
94
- Represents a barrier operation on targeted qubit, stored in the classical register at `index` .
79
+ Represents a barrier operation on targeted qubit.
95
80
For now, this is a no-op.
96
81
"""
97
- struct Barrier <: QuantumOperator
98
- index:: Int
99
- end
100
- Barrier () = Barrier (- 1 )
101
- Parametrizable (m:: Barrier ) = NonParametrized ()
102
- qubit_count (:: Type{Barrier} ) = 1
103
- qubit_count (m:: Barrier ) = qubit_count (Barrier)
82
+ struct Barrier <: QuantumOperator end
104
83
StructTypes. constructfrom (:: Type{Barrier} , nt) = Barrier ()
105
84
106
85
"""
107
- Delay(index, duration::Time) <: QuantumOperator
86
+ Delay(duration::Time) <: QuantumOperator
108
87
109
- Represents a delay operation for `duration` on targeted qubit,
110
- stored in the classical register at `index`.
88
+ Represents a delay operation for `duration` on targeted qubit.
111
89
For now, this is a no-op.
112
90
"""
113
91
struct Delay <: QuantumOperator
114
- index:: Int
115
92
duration:: Dates.Period
116
93
end
117
- Delay (duration:: Dates.Period ) = Delay (- 1 , duration)
118
- Parametrizable (m:: Delay ) = NonParametrized ()
119
- qubit_count (:: Type{Delay} ) = 1
120
- qubit_count (m:: Delay ) = qubit_count (Delay)
121
94
StructTypes. constructfrom (:: Type{Delay} , nt) = Delay (only (nt. arguments))
95
+
96
+ for T in (:Barrier , :Reset , :Delay , :Measure )
97
+ @eval begin
98
+ qubit_count (:: Type{$T} ) = 1
99
+ qubit_count (o:: $T ) = qubit_count ($ T)
100
+ Parametrizable (:: $T ) = NonParametrized ()
101
+ end
102
+ end
0 commit comments