-
Notifications
You must be signed in to change notification settings - Fork 4
/
SuperQuantModel.py
1708 lines (1313 loc) · 69.4 KB
/
SuperQuantModel.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
"""
Copyright (c) 2018 and later, Andrey R. Klots. With supervision
of Lev B. Ioffe and with support of
United States Army Research Office (ARO).
All rights reserved
This file is a part of "SuperQuant" package.
Terms of use of this code are provided below (until long horizontal line)
Most up-to-date version of this agreement must always be used. Updates
Are available at github.com/andreyklots/SuperQuantPackage.
Terms used in agreement:
"modification": for purposes of this agreement, the word "modified"
means any modification of the current code that includes not only
changes in original python code, but also translation of
this code (or parts of it) into another programming or script language
or compilation of this code and translation into binary form.
Use of this code:
If this software (in whole or in part) is used as a part of a
published research then need to be cited as "SuperQuant package by
AR Klots" or "github.com/andreyklots/SuperQuantPackage".
This software is free for use for purely research purposes.
However, if research using this code or its derivatives is a part of
development of a commercial or military product then direct permission
of the designer and owner of this code is required.
Modification and redistribution:
Any redistribution of this code, in whole or in part, modified or
unmodified, must reproduce all the terms of the most up-to-date version
of the current license agreement.
Each distribution must explicitly refer to the original
code.
Integration and compilation:
If this code (in whole or in part, modified or unmodified) is
used as a part of another code or software package, then that code
or software package must reproduce all the terms of the most
up-to-date version of the current license agreement
pertaining to those parts of the new code or
software that were derived from the current code.
In order to incorporate the current code (in whole or in part,
modified or unmodified) as a part of software used for commercial
or military purposes, then permission of the owner and designer
of the code is required.
Name of "SuperQuant" package or names of its contributors
cannot be used to promote or endorse any other products, even
if they are derived from this software.
Liability:
No person or organization that owns this code, participated
or contributed to its creation, or holds the copyright, shall
be liable for any damage, loss and all other undesirable and
unexpected consequences, be they direct or indirect, or caused
by or related to this software in any other way. Any user of
the current code or its derivatives acknowledges that this
code may contain errors and no party involved in creation of
this code is not liable for any undesirable consequences.
Exemptions:
As a supporting organization, ARO is exempt from limitations on
use, modification, distribution and integration of this code.
--------------------------------------------------------------------------
"""
import numpy as np
from numpy import linalg as LA
LOGO = """
_________________________________________________
_| | |
/ | |
\_ S U P E R C O N D U C T I N G X __|__
/ | _____
\_ Q U A N T U M X |
/ | ___|___
\_ C I R C U I T X | |
/ | X x
\_ M O D E L X |_______|
| | | | |
|_____| |________\/_______________________|_______|
| | /\ (c) Andrey Klots
| |
"""
print("""
,---CCCCC---X--||------x---------,
| SuperQuant Circuit Model |
_|_ (c) Andrey Klots_|_
""")
# _____________________#
#! USEFUL FUNCTIONS !#
#!____________________!#
# same as dir-function, but does not
#return methods/properties starting with "_"
def dirv(Obj):
return [ a for a in dir(Obj) if a[0]!='_' ]
# Diagonalize matrix A and sort from smaller to larger eigenvalues
def eigsort(A, METHOD = None):
if (METHOD==None)or(METHOD=="A")or(METHOD=="a")or(METHOD=="arbitrary"):
E, u = LA .eig(A)
#sort eigenvalues by their real part
idx = np.argsort(E.real)
E = E[idx]
u = u[:,idx]
# eigenvectors as matrix type
return [np.matrix(E).T, np.matrix(u)]
if (METHOD=="R")or(METHOD=="r")or(METHOD=="real"):
# extract real-symmetric part of the matrix
_A = 0.5*(A+A.H).real
E, u = LA .eigh(_A)
return [np.matrix(E).T, np.matrix(u)]
if (METHOD=="H")or(METHOD=="h")or(METHOD=="hermit")or(METHOD=="Hermit"):
# extract hermitian part of the matrix
_A = 0.5*(A+A.H)
E, u = LA .eigh(_A)
return [np.matrix(E).T, np.matrix(u)]
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" """
""" C L A S S """
""" """
""" T H A T D E S C R I B E S B A S I C """
""" """
""" C I R C U I T P A R A M E T E R S """
""" """
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
class CircuitParameters:
# show properties of the class
def __repr__(self):
return str(dirv(self))
# square root of inverse Maxwell capacitance matrix $C^{-1/2}$
Inv_sqrt_C = np.matrix([None])
# inductor connectivity matrix. Dimensions: (N of inductors) x (N of nodes)
G = np.matrix([None])
# inverse inductance matrix. Dimensions:(N of inductors) x (N of inductors)
Inv_L = np.matrix([None])
# Josephson connectivity matrix. Same as Inductance
# capacitance matrix, but for Josephson junctions
H = np.matrix([None])
# array(vector) of Josephson energies
E_jos = np.matrix([None])
# vector of offset fluxes
Phi = np.matrix([None])
# vector of offset charges
Q = np.matrix([None])
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" """
""" C L A S S """
""" """
""" T H A T C A L C U L A T E S C I R C U I T """
""" """
""" P A R A M E T E R S A N D O P E R A T O R S """
""" """
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
class ModelCalculator:
# show properties of the class
def __repr__(self):
return str(dirv(self))
SMALL = 1E-4
##############################################
# #
# C I R C U I T #
# #
# Class defining properties of a circuit #
# #
##############################################
# create a property in SuperCondModel
Circuit = CircuitParameters()
##############################################
# #
# M A T R I C E S #
# #
# Class and functions defining matrices #
# #
##############################################
class __Matrices:
# show properties of the class
def __repr__(self):
return str(dirv(self))
# unitary matrix for first transformation
U = np.matrix([None])
# array of frequency modes
omega_eigenvalues = np.matrix([None])
# $N^{cyc}$
N_cyc = None
# $N^{osc}$
N_osc = None
# matrix defining values inside cosines of Josephson potentials ($M
# $)
M = np.matrix([None])
# cyclic part of M ($\mathbb{M}^{cyc}$)
M_cyc = np.matrix([None])
# oscillatory part of M ($\mathbb{M}^{osc}$)
M_osc = np.matrix([None])
# largest invertible submatrix of M_cyc ($\mathbb{m}^{cyc}$)
m_cyc = np.matrix([None])
# integer form of M_cyc after transformation ($\mathbb{Z}^{cyc}$).
# Z_cyc=M_cyc/m_cyc
Z_cyc = np.matrix([None])
# transformed flux biases
F = np.matrix([None])
# transformed charge biases
K = np.matrix([None])
# create a property in SuperCondModel
Matrices = __Matrices()
# names of functions below are self-evident: calculate different matrices
def calc_U_omega_eigenvalues(self):
Mat = self.Circuit.Inv_sqrt_C.H * self.Circuit.G.T \
* self.Circuit.Inv_L \
* self.Circuit.G * self.Circuit.Inv_sqrt_C
[omega_eigenvalues_squared, self.Matrices.U] \
= eigsort(Mat, METHOD = "real")
self.Matrices.omega_eigenvalues = \
np.sqrt(np.abs(omega_eigenvalues_squared))
# find number of cyclic coordinates and from there get number of oscill
# atory ones
def calc_N_cyc_osc_tot(self):
self.Matrices.N_cyc, self.Matrices.N_osc \
= self.__calc_N_cyc_osc_tot(
self.Matrices.omega_eigenvalues, self.SMALL )
def calc_M(self):
self.Matrices.M \
= self.Circuit.H * self.Circuit.Inv_sqrt_C * self.Matrices.U
def calc_M_cyc_osc(self):
self.Matrices.M_cyc = self.Matrices.M[ :, 0:self.Matrices.N_cyc ]
self.Matrices.M_osc \
= self.Matrices.M[ :, \
self.Matrices.N_cyc
: (self.Matrices.N_cyc+self.Matrices.N_osc) ]
def calc_m_cyc(self):
self.Matrices.m_cyc \
= self.getMaxInvertibleSubmatrix( \
self.Matrices.M[:,0:self.Matrices.N_cyc], self.SMALL)
# calculate Z-matrix. Choose if we want to force round Z-matrix
def calc_Z_cyc(self, ENFORCE_INT):
# By default ENFORCE_INT is True
if ENFORCE_INT==None: ENFORCE_INT = True
# choose if we want to leave only integer part
if ENFORCE_INT:
self.Matrices.Z_cyc \
= ( self.Matrices.M_cyc*self.Matrices.m_cyc.I
).round().astype(int) \
if np.size(self.Matrices.m_cyc)>0 else np.matrix([[]])
else:
self.Matrices.Z_cyc \
= ( self.Matrices.M_cyc*self.Matrices.m_cyc.I ) if\
np.size(self.Matrices.m_cyc)>0 else np.matrix([[]])
def calc_Transformed_Flux_Charge_Biases(self):
self.Matrices.F, self.Matrices.K = self.__calc_Flux_Charge_Biases(
self.Circuit.Phi, self.Circuit.Q,\
self.Circuit.G, self.Circuit.H,\
self.Matrices.m_cyc, self.Matrices.U,\
self.Circuit.Inv_sqrt_C)
# returns transform 1 matrix -- U^T*C^(1/2) -- transforms original coor
# dinates to new
def getTransform1Matrix(self):
return self.Matrices.U.T*self.Circuit.Inv_sqrt_C.I
# returns transform 2 matrix. Acts on original coordinates.
def getTransform2Matrix(self):
m_cyc = self.Matrices.m_cyc
N_cyc = self.Matrices.N_cyc
Mat = np.matrix(np.identity(N_cyc+self.Matrices.N_osc))
Mat[0:N_cyc,0:N_cyc] = m_cyc
return Mat * self.Matrices.U.T * self.Circuit.Inv_sqrt_C.I
# returns transform 3 matrix
def getTransform3Matrix(self):
m_cyc = self.Matrices.m_cyc
N_cyc = self.Matrices.N_cyc
Mat = np.matrix(np.diag(
# diagonal matrix of omega eigenvalues
np.sqrt(np.array(self.Matrices.omega_eigenvalues.T)[0]) ))
Mat[0:N_cyc,0:N_cyc] = m_cyc
return Mat * self.Matrices.U.T * self.Circuit.Inv_sqrt_C.I
# returns matrices for transformed (3) Hamiltonian: c^-1 and M^III
def getHamiltonianParameters3(self):
m_cyc = self.Matrices.m_cyc
Z_cyc, M_osc = self.Matrices.Z_cyc, self.Matrices.M_osc
# 1d array of sqrt of omega eigenvalues
Sqrt_omega = np.array( np.sqrt(self.Matrices.omega_eigenvalues.T) )[0]
N_cyc, N_osc = self.Matrices.N_cyc, self.Matrices.N_osc
InvCyclicCapacitanceMatrix = m_cyc*m_cyc.T
M_osc3 = M_osc*np.matrix(np.diag(
np.reciprocal(Sqrt_omega[N_cyc:N_cyc+N_osc]) ))
M_3 = np.hstack([Z_cyc, M_osc3])
return (InvCyclicCapacitanceMatrix,Sqrt_omega[N_cyc:N_cyc+N_osc], M_3)
######################################################
# #
# O P E R A T O R S #
# #
# Class and functions defining quantum operators #
# #
######################################################
class __Operators:
# show properties of the class
def __repr__(self):
return str(dirv(self))
# list of unity matrices
I_hat = [None]
# list of number operators
N_hat = [None]
# list of exponential operators
V_hat = [None]
# list of numbers of states for each coordinate.
N_of_states = [None]
# note that for cyclic coordinates number N_of_states=M corresponds
# to 2M+1 states
Hamiltonian = np.matrix([None]);
# create a property in SuperCondModel
Operators = __Operators()
# function that calculates operators. option DISPLAY_PROGRESS determine
# s if user wants to display current progress of calculating V_hat matr
# ices
def obtainOperators(self, DISPLAY_PROGRESS = True):
self.Operators.I_hat, self.Operators.N_hat, self.Operators.V_hat \
= self.__obtainOperators(
self.Matrices.N_cyc, self.Matrices.N_osc,\
self.Operators.N_of_states,\
self.Matrices.Z_cyc.round().astype(int),\
self.Matrices.M_osc, self.Matrices.omega_eigenvalues,\
DISPLAY_PROGRESS)
def obtainHamiltonian(self, DISPLAY_PROGRESS = True):
self.Operators.Hamiltonian \
= self.__obtainHamiltonian(
self.Matrices.N_cyc, self.Matrices.N_osc,\
self.Matrices.m_cyc, self.Matrices.omega_eigenvalues,\
self.Circuit.E_jos, self.Operators.I_hat,\
self.Operators.N_hat, self.Operators.V_hat,\
self.Matrices.F, self.Matrices.K, DISPLAY_PROGRESS)
# calculate total number of quantum states
def getTotal_N_of_states(self):
# this will be total number of states
Tot_N_states = 1
# number of current coordinate
coordNumber = 0
for N in self.Operators.N_of_states[ \
0:(self.Matrices.N_cyc
+self.Matrices.N_osc) ]:
Tot_N_states = Tot_N_states * ( (2*N+1) \
# multiply all N_of_states (depending if it is
# cyclic or not)
if coordNumber<self.Matrices.N_cyc else N )
coordNumber = coordNumber + 1
return Tot_N_states
#\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#
#\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#
#\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#
######################################################
# #
# F U N C T I O N S #
# #
# Define more complicated functions #
# #
######################################################
# ______________________________________________________________#
#! FUNCTION TO FIND LARGEST INVERTIBLE SUBMATRIX OF A MATRIX !#
#!_____________________________________________________________!#
# function that returns largest invertible submatrix of matrix A with p
# recision of TOLERANCE
def getMaxInvertibleSubmatrix(self, A, TOLERANCE=None):
# note that this is an important function and hence is not hidden
if TOLERANCE==None: TOLERANCE = 1E-10
if np.size(A)==0:
return []
if np.max( np.abs( A ) ) <= 2*TOLERANCE:
# if matrix is too small then return error
return "ERROR: matrix elements too small"
# get dimensions of A
N = np.size( A[:,0] )
M = np.size( A[0,:] )
# make A1, a copy of A. Will work with A1
A1 = A
# check if matrix is horizontal. The algorithm finds linearly indep
# endent rows. If horizontal, then will need to transpose
if N < M:
NeedTranspose = True
A1 = A.T
# get dimensions of A transposed
N = np.size( A1[:,0] )
M = np.size( A1[0,:] )
else:
NeedTranspose = False
# initial max invertible submatrix
a = np.matrix([])
# sort rows of A1 from largest absolute value of row-vector to lowest
# so that norm of invertible submatrix is as large as possible
# make sure A2 is matrix (and not just 2D array). Will be needed fo
# r next row
A2 = np.matrix(A1)
# make array of absolute values of rows of A
A1_abs_values = np.array([ (row*row.H)[0,0].real for row in A2 ])
# sort A1 in the order of decreasing absolute values of row-vectors
idx = np.argsort(A1_abs_values)
A1 = A1[idx]
# now row-vectors are sorted in the order of descending row-vector abs
# add one more non-zero row so that if all rows are zero, then erro
# r does not occur when n+1'th row is extracted
A1 = np.vstack( [A1, np.zeros([1,M])] )
# number of non-zero row
n_non_zero = 0
# find first non-zero row
while A1[n_non_zero,:]*A1[n_non_zero,:].H <= 2*TOLERANCE \
and n_non_zero < N:
n_non_zero = n_non_zero + 1
if n_non_zero == N+1:
# if all rows are zero, return error
return "ERROR: matrix elements too small"
else:
# add first nonzero row to a -- our invertible submatrix
a = A1[n_non_zero,:]
# number of rows in array a. Initially 1
rows_in_a = 1
# this will be array of indexes later used for inverse sorting
# (so that linearly-independent rows are in the same order in a
# as in A)
idx_inverse = [ idx[n_non_zero] ]
for n in range( n_non_zero+1, N ):
if np.linalg.matrix_rank(\
np.vstack( [a,A1[n,:]]
# check if n'th row is linearly ind
# ependent from whatever is already
# in a
), TOLERANCE ) > rows_in_a:
# add linearly independent row
a = np.vstack( [a,A1[n,:]] )
# add index of the current row in A
idx_inverse = idx_inverse + [ idx[n] ]
# increase current rank of a
rows_in_a = rows_in_a + 1
# sort indexes in the order as they appear in original array A
idx_for_a_inversion = np.argsort(idx_inverse)
# resort a in such a way that rows in a appear in the same order as
# they appear in A
a = a[idx_for_a_inversion]
if NeedTranspose:
# if needed to transpose original matrix then transpose the res
# ulting one
a=a.T
return a
# ___________________________________#
#! CALCULATE N_cyc, N_osc, N_tot !#
#!__________________________________!#
def __calc_N_cyc_osc_tot( self, omega_eigenvalues, SMALL ):
# get total number of generalized coordinates
N_tot = np.size( omega_eigenvalues )
# initial number of cyclic coordinates
N_cyc = 0
for n in range( 0, N_tot ):
# if mode frequency eigenvalue is small
if omega_eigenvalues[n] < np.sqrt(SMALL):
# then this is a cyclic coordinate and we add it to N_cyc
N_cyc = N_cyc + 1
# get N_osc
N_osc = N_tot - N_cyc
return [N_cyc, N_osc]
# _________________________________________________________#
#! FUNCTION TO GET TRANSFORMED FLUX AND CHARGE BIASES !#
#!________________________________________________________!#
def __calc_Flux_Charge_Biases(self, Phi, Q, G, H, m_cyc, U, Inv_sqrt_C):
# total number of degrees of freedom
N_tot = np.size(Q)
# number of cyclic degrees of freedom
N_cyc = np.size(m_cyc[0,:]) if len(m_cyc)>0 else 0
# make sure that number of inductors is > 0
if np.size(G) > 0:
# calculate equation F = H(G\Phi)
F = H * ( G.I * Phi )
else:
# if no inductors in the circuit, then return empty matrix for
# offsets. Transformed offset charge vector is K = diag(m_cyc^T
# ,1)*U^T*C^(-1/2) Q
F = np.matrix([])
# now calculate diag(m_cyc^T,1)
diag_m_1 = np.matrix(np.identity(N_tot))
# put m_cyc in the top left corner of the identity matrix
diag_m_1[0:N_cyc,0:N_cyc] = m_cyc
# get transformed vector of offset charges
K = diag_m_1.I.T * U.T * Inv_sqrt_C * Q
return [F, K]
# ________________________________________#
#! FUNCTION TO GET QUANTUM OPERATORS !#
#!_______________________________________!#
def __obtainOperators( self, N_cyc, N_osc, N_of_states,\
Z_cyc, M_osc, omega_eigenvalues,\
DISPLAY_PROGRESS ):
# if DISPLAY_PROGRESS is not set, then it is by default False
if type(DISPLAY_PROGRESS)==None: DISPLAY_PROGRESS = False
# get total number of coordinates
N_tot = N_cyc + N_osc
# list of identity operators
I = [0 for _i in range(N_tot)]
# list of number operators
N = [0 for _i in range(N_tot)]
# initialize an empty (N_Jos x N_tot) list for V-operators -- 2D l
# ist of V-matrices $V^{(J,j)}$. J -- first index. j -- second inde
# x
V = [[0 for _i in range(N_tot)] for _j in range(np.size(M_osc[:,0]))]
# NOTE: here for simplicity we omit "hats" so instead of N_hat,
# V_hat we write N, V,...
# Generate identity and number operators
for n_coord in range(0, N_tot):
# N of states for n-th coordinate
_ns = N_of_states[n_coord]
# create identity operators
if n_coord < N_cyc:
# create identity matrix for cyclic coordinate
I[n_coord] = np.matrix(np.identity( 2*_ns+1 ))
# create charge number operator
N[n_coord] = np.matrix(np.diag(range(-_ns,_ns+1)))
else:
# create identity matrix for oscillatory coordinate
I[n_coord] = np.matrix(np.identity( _ns ))
# create oscillator number operator
N[n_coord] = np.matrix(np.diag(range(0,_ns)))
# this string will contain progress in calculating V_hat- matrices
_Progress_String = ""
# get number of Josephson junctions
N_jos = np.size(M_osc[:,0])
# scan over Josephson junctions
for n_jos in range(0,N_jos):
# scan over coordinates
for n_coord in range(0, N_tot):
# N of states for n-th coordinate
_ns = N_of_states[n_coord]
# if user chooses to display the progress
if DISPLAY_PROGRESS:
# this string will contain message showing current progress
_Progress_String = "...computing V_hat(n_jos = "\
+str(n_jos+1)+"/"+str(np.size(M_osc[:,0]))\
+", n_coord = "+str(n_coord+1)\
+"/"+str(N_tot)+")..."
print(_Progress_String)
# calculate V for cyclic coordinates
if n_coord < N_cyc:
# make empty matrix for V. Elements will be filled late
# r
currentV = np.matrix(np.zeros([2*_ns+1 ,2*_ns+1]))
# fill V- matrix element-by-element
for m1 in range(0,2*_ns+1):
for m2 in range(0,2*_ns+1):
if (m1-m2) == Z_cyc[n_jos,n_coord]:
# put 1 into element [m1,m2] if m1-m2=0. Ot
# herwise leave 0
currentV[m1,m2] = 1
# calculate V for oscillatory coordinates
if n_coord >= N_cyc:
# make empty matrix for V. Elements will be filled late
# r
currentV = np.matrix(np.zeros([_ns,_ns]))
# fill V- matrix element-by-element
for m1 in range(0,_ns):
for m2 in range(0,_ns):
# Now calculate current matrix element
Q = M_osc[n_jos, n_coord-N_cyc]/np.sqrt(
omega_eigenvalues[n_coord])
Sum = 0
for l in range(0,min(m1+1,m2+1)):
Sum = Sum + (-1)**l\
* np.sqrt(1.*np.math.factorial(m1) \
/np.math.factorial(l))\
* np.sqrt(1.*np.math.factorial(m2) \
/np.math.factorial(l))\
* np.math.factorial(m1-l)**(-1)\
* np.math.factorial(m2-l)**(-1)\
* (Q/np.sqrt(2.)) ** (m1+m2-2*l)
currentV[m1,m2] = ((-1)**m2) \
* np.exp(-Q**2 / 4) * Sum
# add the calculated V-matrix to the list
V[n_jos][n_coord] = currentV
# return obtained matrices
return [I, N, V]
# __________________________________#
#! FUNCTION TO GET HAMILTONIAN !#
#!_________________________________!#
def __obtainHamiltonian(self, N_cyc, N_osc, m_cyc, \
omega_eigenvalues, E_jos, I, N, V,\
F, K, DISPLAY_PROGRESS):
# if DISPLAY_PROGRESS is not set, then it is by default False
# # First we want to construct identity (
# I) and number (N) operators that all have greatest dimension (per
# form Kroneker-multiplication of all identity and number operators
# )
if DISPLAY_PROGRESS==None: DISPLAY_PROGRESS = False
# this will be an array of number operators, but all brought to sam
# e dimension. While arrays N_hat, I_hat each have dimensions of co
# rresponding N_of_states. Replace N0,N1,N2,N3,... --> N0 x I1 x I2
# x ..., I0 x N1 x I2 x ..., I0 x I1 x N2 x ..., ....
_N = [0 for n in range(0,len(N))]
# NOTE: here for simplicity we omit "hats" so instead of
# N_hat, V_hat,.. we write N, V,...
# now want to get identity operator of total dimension ...
_I = 1
# will count identity operators
current_I_index = -1
for I_current in I:
current_I_index=current_I_index+1
# ... by Kronecker-multiplying all identity operators
_I = np.kron(_I, I_current)
# if user chooses to display the progress
if DISPLAY_PROGRESS:
# this string will contain message that shows current progress
# in getting Identity matrix
_Progress_String = "calc. direct product of identity "\
"matrices: I:=IxI_" \
+str(current_I_index + 1) \
+ "/" +str(N_cyc+N_osc) + "."
print(_Progress_String)
# counts index of the N-operator
current_N_index = -1
# scan over N-operators
for N_current in N:
current_N_index = current_N_index + 1
# index that will count identity operators
current_I_index = -1
# current total operator (i.e. of form I0 x N1 x I2 x ...)
current_N_tot = 1
# scan over identity operators
for I_current in I:
current_I_index = current_I_index + 1
if current_I_index == current_N_index:
# in Kronecker product in space current_N_index put N-o
# perator and not I-operator
current_N_tot = np.kron(current_N_tot, N_current)
else:
# everywhere else put I-operator of corresponding dimen
# sions
current_N_tot = np.kron(current_N_tot, I_current)
# add calculated operator to the list _N
_N[current_N_index] = current_N_tot
# Get cyclic part of the Hamiltonian
Hamilt_cyc=0*_I
# effectively (1/2)* Capacitance matrix for cyclic degrees of freed
# om
m2 = 0.5*m_cyc*m_cyc.T if len(m_cyc)>0 else 0
for m in range(0,N_cyc):
for n in range(0,N_cyc):
# get cyclic part of the Hamiltonian
Hamilt_cyc = Hamilt_cyc \
+ ( _N[m] - np.kron(K[m],_I) ) \
* m2[m,n] * ( _N[n] - np.kron(K[n],_I) )
# Get oscillatory part of the Hamiltonian
Hamilt_osc = 0*_I
for m in range(N_cyc, N_cyc+N_osc):
# get oscillatory Hamiltonian
Hamilt_osc = Hamilt_osc \
+ np.kron( omega_eigenvalues[m], (_N[m] + 0.5*_I) )
# Get Josephson Hamiltonian
Hamilt_Jos_exp=0*_I;
N_Jos = np.size(E_jos)
for m in range(0,N_Jos):
_row_product = 1
# if user chooses to display the progress
if DISPLAY_PROGRESS:
# this string will contain message that shows current
# progress in calculating Josephson Hamiltonian
_Progress_String = "calc. Hamilt. of Jos. junction #: "\
+str(m+1)+"/"+str(N_Jos)+"..."
print(_Progress_String)
for n in range(0,N_cyc+N_osc):
_row_product=np.kron(_row_product,V[m][n])
# get sum of products of V-operators
Hamilt_Jos_exp = Hamilt_Jos_exp \
+ np.kron(np.exp(-1j*F[m,0])*E_jos[m],_row_product)
# get hermitian part of the Hamiltonian
Hamilt_Jos_exp = ( Hamilt_Jos_exp + Hamilt_Jos_exp.H )/2.
return Hamilt_cyc + Hamilt_osc - Hamilt_Jos_exp
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" """
""" C L A S S """
""" """
""" T H A T D E F I N E S T H E C I R C U I T """
""" """
""" A N D I T S P A R A M E T E R S """
""" """
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
class CircuitBuilder:
# show properties of the class
def __repr__(self):
return str(dirv(self))
# threshold under which numbers are considered small
SMALL = 1E-4
##################################################
# #
# C I R C U I T #
# #
# Class containing code that defines circuit #
# #
##################################################
class __Circuit:
# show properties of the class
def __repr__(self):
return str(dirv(self))
Code = [None]
MutualInductanceCode = []
C = np.matrix([None])
L = np.matrix([None])
E_jos = np.matrix([None])
# from CircuitCode extract only lines corresponding to element Elem
# entType(1-character variable: 'L', 'C' or 'J')
def extract(self, ElementType):
return [Line for Line in self.Code if Line[2][0]==ElementType]
# get number of elements in the circuit (number of lines in Circuit
# .Code)
def nElements(self):
return len(self.Code)
# number of nodes in the circuit
def size(self):
return np.amax( [a[0:2] for a in self.Code] )
# find number of the element of type "ElementType" connecting nodes
# Node1 and Node2
def findElementNumber(self, Node1,Node2, ElementType):
# extract subcircuit of inductors
SubCircuit = self.extract(ElementType)
# get number of elements of our type in the circuit
N_of_Elements_of_Type = len(SubCircuit)
# default number of the element we are looking for. Initially n
# ot found returns -1
ElementNumber = -1
# scan over all elements of our type
for n in range(0,N_of_Elements_of_Type):
# if element with given terminals is found
if SubCircuit[n][0:2] == [Node1, Node2]:
ElementNumber = n
# then return it
return ElementNumber
Circuit = __Circuit()
def setCapacitanceMatrix(self):
# set capacitance matrix in Circuit.C
self.Circuit.C = self.__obtainCapacitanceMatrix(self.Circuit)
# set inductance matrix in Circuit.L
def setInductanceMatrix(self):
self.Circuit.L = self.__obtainInductanceMatrix(self.Circuit)
self.Circuit.L = self.__obtainMutualInductances(self.Circuit)
def setJosephsonEnergies(self):
self.Circuit.E_jos = np.matrix([Line[3]
# extract Josephson energies from Circuit.Code
for Line in self.Circuit.Code if Line[2][0]=='J']).T
def getInductorConnectivityMatrixG(self):
return self.obtainConnectivityMatrix(self.Circuit, 'L')
def getJosephsonConnectivityMatrixH(self):
return self.obtainConnectivityMatrix(self.Circuit, 'J')
def getFluxBiasVector(self, FluxBiasCode):
return self.__getFluxBiasVector(self.Circuit, FluxBiasCode)
def getChargeBiasVector(self, ChargeBiasCode):