/
gaugegroup.py
1018 lines (818 loc) · 31.1 KB
/
gaugegroup.py
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
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
GaugeGroup and derived objects, used primarily in gauge optimization
"""
#***************************************************************************************************
# Copyright 2015, 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
# Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains certain rights
# in this software.
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0 or in the LICENSE file in the root pyGSTi directory.
#***************************************************************************************************
import numpy as _np
from pygsti.modelmembers import operations as _op
class GaugeGroup(object):
"""
A parameterized set (ideally a group) of gauge transformations.
Specifies the "optimization space" explored by gauge optimization
algorithms. This base class is used to define the common interface of all
types of gauge "groups" (even though they need not be groups in the
mathematical sense).
Parameters
----------
name : str
A name for this group - used for reporting what type of
gauge optimization was performed.
"""
def __init__(self, name):
"""
Creates a new gauge group object
Parameters
----------
name : str
A name for this group - used for reporting what type of
gauge optimization was performed.
"""
self.name = name
@property
def num_params(self):
"""
Return the number of parameters (degrees of freedom) of this gauge group..
Returns
-------
int
"""
return 0
def compute_element(self, param_vec):
"""
Retrieve the element of this group corresponding to `param_vec`
Parameters
----------
param_vec : numpy.ndarray
A 1D array of length :method:`num_params`.
Returns
-------
GaugeGroupElement
"""
return GaugeGroupElement()
@property
def initial_params(self):
"""
Return a good (or standard) starting parameter vector, used to initialize a gauge optimization.
Returns
-------
numpy.ndarray
A 1D array of length :method:`num_params`.
"""
return _np.array([], 'd')
class GaugeGroupElement(object):
"""
The element of a :class:`GaugeGroup`, which represents a single gauge transformation.
"""
def __init__(self):
"""Creates a new GaugeGroupElement"""
pass
@property
def transform_matrix(self):
"""
The gauge-transform matrix.
Returns
-------
numpy.ndarray
"""
return None
@property
def transform_matrix_inverse(self):
"""
The inverse of the gauge-transform matrix.
Returns
-------
numpy.ndarray
"""
return None
def deriv_wrt_params(self, wrt_filter=None):
"""
Computes the derivative of the gauge group at this element.
That is, the derivative of a general element with respect to the gauge
group's parameters, evaluated at this element.
Parameters
----------
wrt_filter : list or numpy.ndarray, optional
Indices of the gauge group parameters to differentiate with respect to.
If None, differentiation is performed with respect to all the group's parameters.
Returns
-------
numpy.ndarray
"""
return None
def to_vector(self):
"""
Get the parameter vector corresponding to this transform.
Returns
-------
numpy.ndarray
"""
return _np.array([], 'd')
def from_vector(self, v):
"""
Reinitialize this `GaugeGroupElement` using the the parameter vector `v`.
Parameters
----------
v : numpy.ndarray
A 1D array of length :method:`num_params`
Returns
-------
None
"""
pass
@property
def num_params(self):
"""
Return the number of parameters of this gauge group element.
(This is equivalent to the number of parameters of the parent gauge group.)
Returns
-------
int
"""
return 0
def inverse(self):
"""
Creates a gauge group element that performs the inverse of this element.
Returns
-------
InverseGaugeGroupElement
"""
return InverseGaugeGroupElement(self)
class InverseGaugeGroupElement(GaugeGroupElement):
"""
A gauge group element that represents the inverse action of another element.
Parameters
----------
gauge_group_el : GaugeGroupElement
The element to invert.
"""
def __init__(self, gauge_group_el):
self.inverse_element = gauge_group_el
@property
def transform_matrix(self):
"""
The gauge-transform matrix.
Returns
-------
numpy.ndarray
"""
return self.inverse_element.transform_matrix_inverse
@property
def transform_matrix_inverse(self):
"""
The inverse of the gauge-transform matrix.
Returns
-------
numpy.ndarray
"""
return self.inverse_element.transform_matrix
def deriv_wrt_params(self, wrt_filter=None):
"""
Computes the derivative of the gauge group at this element.
That is, the derivative of a general element with respect to the gauge
group's parameters, evaluated at this element.
Parameters
----------
wrt_filter : list or numpy.ndarray, optional
Indices of the gauge group parameters to differentiate with respect to.
If None, differentiation is performed with respect to all the group's parameters.
Returns
-------
numpy.ndarray
"""
#Derivative of inv(M): d(inv_M) = inv_M * dM * inv_M
Tinv = self.transform_matrix # inverse of *original* transform
dT = self.inverse_element.deriv_wrt_params(wrt_filter) # shape (d*d, n)
d, n = int(round(_np.sqrt(dT.shape[0]))), dT.shape[1]
dT.shape = (d, d, n) # call it (d1,d2,n)
dT = _np.rollaxis(dT, 2) # shape (n, d1, d2)
deriv = -_np.dot(Tinv, _np.dot(dT, Tinv)) # d,d * (n,d,d * d,d) => d,d * n,d,d => d,n,d
return _np.swapaxes(deriv, 1, 2).reshape(d * d, n) # d,n,d => d,d,n => (d*d, n)
def to_vector(self):
"""
Get the parameter vector corresponding to this transform.
Returns
-------
numpy.ndarray
"""
return self.inverse_element.to_vector()
def from_vector(self, v):
"""
Reinitialize this `GaugeGroupElement` using the the parameter vector `v`.
Parameters
----------
v : numpy.ndarray
A 1D array of length :method:`num_params`
Returns
-------
None
"""
return self.inverse_element.from_vector()
@property
def num_params(self):
"""
Return the number of parameters of this gauge group element.
(This is equivalent to the number of parameters of the parent gauge group.)
Returns
-------
int
"""
return self.inverse_element.num_params
def inverse(self):
"""
Creates a gauge group element that performs the inverse of this element.
Returns
-------
GaugeGroupElement
"""
return self.inverse_element # inverting an inverse => back to original
class OpGaugeGroup(GaugeGroup):
"""
A gauge group based on the parameterization of a single `LinearOperator`.
The parameterization of this linear operator is used to parameterize the
gauge-transform matrix. This class is used as the base class for sevearl
other of gauge group classes.
Parameters
----------
operation : LinearOperator
The LinearOperator to base this Gauge group on.
elementcls : class
The element class to use when implementing the `element` method.
name : str
A name for this group - used for reporting what type of
gauge optimization was performed.
"""
def __init__(self, operation, elementcls, name):
"""
Create a new `OpGaugeGroup`.
Parameters
----------
operation : LinearOperator
The LinearOperator to base this Gauge group on.
elementcls : class
The element class to use when implementing the `compute_element` method.
name : str
A name for this group - used for reporting what type of
gauge optimization was performed.
"""
if not isinstance(operation, _op.LinearOperator):
operation = _op.StaticArbitraryOp(operation, evotype='default', state_space=None)
self._operation = operation
self.element = elementcls
GaugeGroup.__init__(self, name)
@property
def num_params(self):
"""
Return the number of parameters (degrees of freedom) of this gauge group.
Returns
-------
int
"""
return self._operation.num_params
def compute_element(self, param_vec):
"""
Retrieve the element of this group corresponding to `param_vec`
Parameters
----------
param_vec : numpy.ndarray
A 1D array of length :method:`num_params`.
Returns
-------
GaugeGroupElement
"""
elgate = self._operation.copy()
elgate.from_vector(param_vec)
return self.element(elgate)
@property
def initial_params(self):
"""
Return a good (or standard) starting parameter vector, used to initialize a gauge optimization.
Returns
-------
numpy.ndarray
A 1D array of length :method:`num_params`.
"""
return self._operation.to_vector()
class OpGaugeGroupElement(GaugeGroupElement):
"""
The element type for `OpGaugeGroup`-derived gauge groups
Parameters
----------
operation : LinearOperator
The operation to base this element on. It provides both parameterization
information and the gauge transformation matrix itself.
"""
def __init__(self, operation):
"""
Create a new element based on `operation`
Parameters
----------
operation : LinearOperator
The operation to base this element on. It provides both parameterization
information and the gauge transformation matrix itself.
"""
if not isinstance(operation, _op.LinearOperator):
operation = _op.StaticArbitraryOp(operation, evotype='default', state_space=None)
self._operation = operation
self._inv_matrix = None
GaugeGroupElement.__init__(self)
@property
def transform_matrix(self):
"""
The gauge-transform matrix.
Returns
-------
numpy.ndarray
"""
return self._operation.to_dense(on_space='minimal')
@property
def transform_matrix_inverse(self):
"""
The inverse of the gauge-transform matrix.
Returns
-------
numpy.ndarray
"""
if self._inv_matrix is None:
self._inv_matrix = _np.linalg.inv(self._operation.to_dense(on_space='minimal'))
return self._inv_matrix
def deriv_wrt_params(self, wrt_filter=None):
"""
Computes the derivative of the gauge group at this element.
That is, the derivative of a general element with respect to the gauge
group's parameters, evaluated at this element.
Parameters
----------
wrt_filter : list or numpy.ndarray, optional
Indices of the gauge group parameters to differentiate with respect to.
If None, differentiation is performed with respect to all the group's parameters.
Returns
-------
numpy.ndarray
"""
return self._operation.deriv_wrt_params(wrt_filter)
def to_vector(self):
"""
Get the parameter vector corresponding to this transform.
Returns
-------
numpy.ndarray
"""
return self._operation.to_vector()
def from_vector(self, v):
"""
Reinitialize this `GaugeGroupElement` using the the parameter vector `v`.
Parameters
----------
v : numpy.ndarray
A 1D array of length :method:`num_params`
Returns
-------
None
"""
self._operation.from_vector(v)
self._inv_matrix = None
@property
def num_params(self):
"""
Return the number of parameters (degrees of freedom) of this element.
Returns
-------
int
"""
return self._operation.num_params
class FullGaugeGroup(OpGaugeGroup):
"""
A fully-parameterized gauge group.
Every element of the gauge transformation matrix is an independent parameter.
Parameters
----------
state_space : StateSpace
The state space for this gauge group. This is the state space that
elements of the gauge group act on. This should be the same as `mdl.state_space`
where `mdl` is a :class:`Model` you want to gauge-transform.
evotype : Evotype or str, optional
The evolution type. The special value `"default"` is equivalent
to specifying the value of `pygsti.evotypes.Evotype.default_evotype`.
"""
def __init__(self, state_space, evotype='default'):
operation = _op.FullArbitraryOp(_np.identity(state_space.dim, 'd'), evotype, state_space)
OpGaugeGroup.__init__(self, operation, FullGaugeGroupElement, "Full")
class FullGaugeGroupElement(OpGaugeGroupElement):
"""
Element of a :class:`FullGaugeGroup`
Parameters
----------
operation : LinearOperator
The operation to base this element on. It provides both parameterization
information and the gauge transformation matrix itself.
"""
def __init__(self, operation):
"""
Creates a new gauge group element based on `operation`, which
is assumed to have the correct parameterization.
"""
OpGaugeGroupElement.__init__(self, operation)
class TPGaugeGroup(OpGaugeGroup):
"""
A gauge group spanning all trace-preserving (TP) gauge transformations.
Implemented as a gauge transformation matrix whose first row is locked
as `[1,0,0...0]` and where every other element is an independent parameter.
Parameters
----------
state_space : StateSpace
The state space for this gauge group. This is the state space that
elements of the gauge group act on. This should be the same as `mdl.state_space`
where `mdl` is a :class:`Model` you want to gauge-transform.
evotype : Evotype or str, optional
The evolution type. The special value `"default"` is equivalent
to specifying the value of `pygsti.evotypes.Evotype.default_evotype`.
"""
def __init__(self, state_space, evotype='default'):
operation = _op.FullTPOp(_np.identity(state_space.dim, 'd'), evotype, state_space)
OpGaugeGroup.__init__(self, operation, TPGaugeGroupElement, "TP")
class TPGaugeGroupElement(OpGaugeGroupElement):
"""
Element of a :class:`TPGaugeGroup`
Parameters
----------
operation : LinearOperator
The operation to base this element on. It provides both parameterization
information and the gauge transformation matrix itself.
"""
def __init__(self, operation):
"""
Creates a new gauge group element based on `operation`, which
is assumed to have the correct parameterization.
"""
OpGaugeGroupElement.__init__(self, operation)
@property
def transform_matrix_inverse(self):
"""
The inverse of the gauge-transform matrix.
Returns
-------
numpy.ndarray
"""
if self._inv_matrix is None:
self._inv_matrix = _np.linalg.inv(self._operation.to_dense())
self._inv_matrix[0, :] = 0.0 # ensure invers is *exactly* TP
self._inv_matrix[0, 0] = 1.0 # as otherwise small variations can get amplified
return self._inv_matrix
class DiagGaugeGroup(OpGaugeGroup):
"""
A gauge group consisting of just diagonal gauge-transform matrices.
(Each diagonal element is a separate parameter.)
Parameters
----------
state_space : StateSpace
The state space for this gauge group. This is the state space that
elements of the gauge group act on. This should be the same as `mdl.state_space`
where `mdl` is a :class:`Model` you want to gauge-transform.
evotype : Evotype or str, optional
The evolution type. The special value `"default"` is equivalent
to specifying the value of `pygsti.evotypes.Evotype.default_evotype`.
"""
def __init__(self, state_space, evotype='default'):
dim = state_space.dim
ltrans = _np.identity(dim, 'd')
rtrans = _np.identity(dim, 'd')
baseMx = _np.identity(dim, 'd')
parameterArray = _np.zeros(dim, 'd')
parameterToBaseIndicesMap = {i: [(i, i)] for i in range(dim)}
operation = _op.LinearlyParamArbitraryOp(baseMx, parameterArray,
parameterToBaseIndicesMap,
ltrans, rtrans, real=True,
evotype=evotype, state_space=state_space)
OpGaugeGroup.__init__(self, operation, DiagGaugeGroupElement, "Diagonal")
class DiagGaugeGroupElement(OpGaugeGroupElement):
"""
Element of a :class:`DiagGaugeGroup`
Parameters
----------
operation : LinearOperator
The operation to base this element on. It provides both parameterization
information and the gauge transformation matrix itself.
"""
def __init__(self, operation):
"""
Creates a new gauge group element based on `operation`, which
is assumed to have the correct parameterization.
"""
OpGaugeGroupElement.__init__(self, operation)
class TPDiagGaugeGroup(TPGaugeGroup):
"""
A gauge group consisting of just trace-preserving (TP) diagonal gauge-transform matrices.
That is, where the first (`[0,0]`) element is fixed at 1.0,
and each subsequent diagonal element is a separate parameter.
Parameters
----------
state_space : StateSpace
The state space for this gauge group. This is the state space that
elements of the gauge group act on. This should be the same as `mdl.state_space`
where `mdl` is a :class:`Model` you want to gauge-transform.
evotype : Evotype or str, optional
The evolution type. The special value `"default"` is equivalent
to specifying the value of `pygsti.evotypes.Evotype.default_evotype`.
"""
def __init__(self, state_space, evotype='default'):
"""
Create a new gauge group with gauge-transform dimension `dim`, which
should be the same as `mdl.dim` where `mdl` is a :class:`Model` you
might gauge-transform.
"""
dim = state_space.dim
ltrans = _np.identity(dim, 'd')
rtrans = _np.identity(dim, 'd')
baseMx = _np.identity(dim, 'd')
parameterArray = _np.zeros(dim - 1, 'd')
parameterToBaseIndicesMap = {i: [(i + 1, i + 1)] for i in range(dim - 1)}
operation = _op.LinearlyParamArbitraryOp(baseMx, parameterArray,
parameterToBaseIndicesMap,
ltrans, rtrans, real=True,
evotype=evotype, state_space=state_space)
OpGaugeGroup.__init__(self, operation, TPDiagGaugeGroupElement, "TP Diagonal")
class TPDiagGaugeGroupElement(TPGaugeGroupElement):
"""
Element of a :class:`TPDiagGaugeGroup`
Parameters
----------
operation : LinearOperator
The operation to base this element on. It provides both parameterization
information and the gauge transformation matrix itself.
"""
def __init__(self, operation):
"""
Creates a new gauge group element based on `operation`, which
is assumed to have the correct parameterization.
"""
TPGaugeGroupElement.__init__(self, operation)
class UnitaryGaugeGroup(OpGaugeGroup):
"""
A gauge group consisting of unitary gauge-transform matrices.
This group includes those (superoperator) transformation matrices that
correspond to unitary evolution. Parameterization is performed via a
Lindblad parametrizaton with only Hamiltonian terms.
Parameters
----------
state_space : StateSpace
The state space for this gauge group. This is the state space that
elements of the gauge group act on. This should be the same as `mdl.state_space`
where `mdl` is a :class:`Model` you want to gauge-transform.
basis : Basis or {"pp", "gm", "std"}
The basis to use when parameterizing the Hamiltonian Lindblad terms.
evotype : Evotype or str, optional
The evolution type. The special value `"default"` is equivalent
to specifying the value of `pygsti.evotypes.Evotype.default_evotype`.
"""
def __init__(self, state_space, basis, evotype='default'):
errgen = _op.LindbladErrorgen.from_operation_matrix(
_np.identity(state_space.dim, 'd'), "H", basis, mx_basis=basis, evotype=evotype)
operation = _op.ExpErrorgenOp(errgen)
OpGaugeGroup.__init__(self, operation, UnitaryGaugeGroupElement, "Unitary")
class UnitaryGaugeGroupElement(OpGaugeGroupElement):
"""
Element of a :class:`UnitaryGaugeGroup`
Parameters
----------
operation : LinearOperator
The operation to base this element on. It provides both parameterization
information and the gauge transformation matrix itself.
"""
def __init__(self, operation):
"""
Creates a new gauge group element based on `operation`, which
is assumed to have the correct parameterization.
"""
OpGaugeGroupElement.__init__(self, operation)
class SpamGaugeGroup(OpGaugeGroup):
"""
Gauge transformations which scale the SPAM and non-unital portions of the gates in a gate set.
A 2-dimensional gauge group spanning transform matrices of the form:
[ [ a 0 ... 0] where a and b are the 2 parameters. These diagonal
[ 0 b ... 0] transform matrices do not affect the SPAM operations
[ . . ... .] much more than typical near-unital and TP operations, and
[ 0 0 ... b] ] so we call this group of transformations the "SPAM gauge".
Parameters
----------
state_space : StateSpace
The state space for this gauge group. This is the state space that
elements of the gauge group act on. This should be the same as `mdl.state_space`
where `mdl` is a :class:`Model` you want to gauge-transform.
evotype : Evotype or str, optional
The evolution type. The special value `"default"` is equivalent
to specifying the value of `pygsti.evotypes.Evotype.default_evotype`.
"""
def __init__(self, state_space, evotype='default'):
"""
Create a new gauge group with gauge-transform dimension `dim`, which
should be the same as `mdl.dim` where `mdl` is a :class:`Model` you
might gauge-transform.
"""
dim = state_space.dim
ltrans = _np.identity(dim, 'd')
rtrans = _np.identity(dim, 'd')
baseMx = _np.identity(dim, 'd')
parameterArray = _np.zeros(2, 'd')
parameterToBaseIndicesMap = {0: [(0, 0)],
1: [(i, i) for i in range(1, dim)]}
operation = _op.LinearlyParamArbitraryOp(baseMx, parameterArray,
parameterToBaseIndicesMap,
ltrans, rtrans, real=True,
evotype=evotype, state_space=state_space)
OpGaugeGroup.__init__(self, operation, SpamGaugeGroupElement, "Spam")
class SpamGaugeGroupElement(OpGaugeGroupElement):
"""
Element of a :class:`SpamGaugeGroup`
Parameters
----------
operation : LinearOperator
The operation to base this element on. It provides both parameterization
information and the gauge transformation matrix itself.
"""
def __init__(self, operation):
"""
Creates a new gauge group element based on `operation`, which
is assumed to have the correct parameterization.
"""
OpGaugeGroupElement.__init__(self, operation)
class TPSpamGaugeGroup(OpGaugeGroup):
"""
Similar to :class:`SpamGaugeGroup` except with TP constrains.
This means the `[0,0]` element of each transform matrix is fixed at 1.0
(so all gauge transforms are trace preserving), leaving just a single degree
of freedom.
Parameters
----------
state_space : StateSpace
The state space for this gauge group. This is the state space that
elements of the gauge group act on. This should be the same as `mdl.state_space`
where `mdl` is a :class:`Model` you want to gauge-transform.
evotype : Evotype or str, optional
The evolution type. The special value `"default"` is equivalent
to specifying the value of `pygsti.evotypes.Evotype.default_evotype`.
"""
def __init__(self, state_space, evotype='default'):
"""
Create a new gauge group with gauge-transform dimension `dim`, which
should be the same as `mdl.dim` where `mdl` is a :class:`Model` you
might gauge-transform.
"""
dim = state_space.dim
ltrans = _np.identity(dim, 'd')
rtrans = _np.identity(dim, 'd')
baseMx = _np.identity(dim, 'd')
parameterArray = _np.zeros(1, 'd')
parameterToBaseIndicesMap = {0: [(i, i) for i in range(1, dim)]}
operation = _op.LinearlyParamArbitraryOp(baseMx, parameterArray,
parameterToBaseIndicesMap,
ltrans, rtrans, real=True,
evotype=evotype, state_space=state_space)
OpGaugeGroup.__init__(self, operation, TPSpamGaugeGroupElement, "TP Spam")
class TPSpamGaugeGroupElement(OpGaugeGroupElement):
"""
Element of :class:`TPSpamGaugeGroup`
Parameters
----------
operation : LinearOperator
The operation to base this element on. It provides both parameterization
information and the gauge transformation matrix itself.
"""
def __init__(self, operation):
"""
Creates a new gauge group element based on `operation`, which
is assumed to have the correct parameterization.
"""
OpGaugeGroupElement.__init__(self, operation)
class TrivialGaugeGroup(GaugeGroup):
"""
A trivial gauge group with no degrees of freedom.
Useful for telling pyGSTi that you don't want to do any gauge optimization
within the framework common to the other gauge groups. Using a
`TrivialGaugeGroup` instead of `None` in gauge optimization will prevent
pyGSTi from wondering if you meant to not-gauge-optimize and displaying
warning messages.
Parameters
----------
state_space : StateSpace
The state space for this gauge group. This is the state space that
elements of the gauge group act on. This should be the same as `mdl.state_space`
where `mdl` is a :class:`Model` you want to gauge-transform.
"""
def __init__(self, state_space):
self.state_space = state_space
GaugeGroup.__init__(self, "Trivial")
@property
def num_params(self):
"""
Return the number of parameters (degrees of freedom) of this gauge group.
Returns
-------
int
"""
return 0
def compute_element(self, param_vec):
"""
Retrieve the element of this group corresponding to `param_vec`
Parameters
----------
param_vec : numpy.ndarray
A 1D array of length :method:`num_params`.
Returns
-------
TrivialGaugeGroupElement
"""
assert(len(param_vec) == 0)
return TrivialGaugeGroupElement(self.state_space.dim)
@property
def initial_params(self):
"""
Return a good (or standard) starting parameter vector, used to initialize a gauge optimization.
Returns
-------
numpy.ndarray
A 1D array of length :method:`num_params`.
"""
return _np.empty(0, 'd')
class TrivialGaugeGroupElement(GaugeGroupElement):
"""
Element of :class:`TrivialGaugeGroup`
Parameters
----------
dim : int
The Hilbert-Schmidt space dimension of the gauge group.
"""
def __init__(self, dim):
"""
Creates a new trivial gauge group element of dimension `dim`.
(so transform matirx is a `dim` by `dim` identity matrix).
"""
self._matrix = _np.identity(dim, 'd')
GaugeGroupElement.__init__(self)
@property
def transform_matrix(self):
"""
The gauge-transform matrix.
Returns
-------
numpy.ndarray
"""
return self._matrix
@property
def transform_matrix_inverse(self):
"""
The inverse of the gauge-transform matrix.
Returns
-------
numpy.ndarray
"""
return self._matrix # inverse of identity is itself!
def deriv_wrt_params(self, wrt_filter=None):
"""
Computes the derivative of the gauge group at this element.
That is, the derivative of a general element with respect to the gauge
group's parameters, evaluated at this element.
Parameters
----------
wrt_filter : list or numpy.ndarray, optional
Indices of the gauge group parameters to differentiate with respect to.
If None, differentiation is performed with respect to all the group's parameters.
Returns
-------
numpy.ndarray
"""
return _np.empty(0, 'd')
def to_vector(self):
"""
Get the parameter vector corresponding to this transform.
Returns
-------
numpy.ndarray
"""
return _np.empty(0, 'd')
def from_vector(self, v):
"""
Reinitialize this `GaugeGroupElement` using the the parameter vector `v`.
Parameters
----------
v : numpy.ndarray