stanfordLINQS / SQcircuit

Superconducting quantum circuit analyzer
BSD 3-Clause "New" or "Revised" License
43 stars 7 forks source link

[Bug report] The code crashes for coupled fluxoniums #2

Open AlesyaSokol opened 2 years ago

AlesyaSokol commented 2 years ago

Hello,

I try to simulate 2 capacitively coupled fluxoniums. I do it using the following code:

import SQcircuit as sq

loop1 = sq.Loop()
loop2 = sq.Loop()

C1 = sq.Capacitor(1, 'GHz')
L1 = sq.Inductor(0.55,'GHz',loops=[loop1])
JJ1 = sq.Junction(4,'GHz',loops=[loop1])

C2 = sq.Capacitor(1.5, 'GHz')
L2 = sq.Inductor(0.5,'GHz',loops=[loop2])
JJ2 = sq.Junction(5,'GHz',loops=[loop2])

Cg = sq.Capacitor(5, 'GHz')

elements = {(0, 1): [JJ1, L1, C1],
            (1, 2): [Cg],
            (2, 3): [JJ2, L2, C2]}

coupled_fl = sq.Circuit(elements)

However, it gives an error:

LinAlgError                               Traceback (most recent call last)
/tmp/ipykernel_522532/4206533622.py in <module>
     16             (2, 3): [JJ2, L2, C2]}
     17 
---> 18 coupled_fl = sq.Circuit(elements)

~/miniconda3/envs/quantum/lib/python3.9/site-packages/SQcircuit/circuit.py in __init__(self, elements, flux_dist, random)
    120 
    121         # get the capacitance matrix, inductance matrix, and w matrix
--> 122         self.C, self.L, self.W = self._get_LCWB()
    123 
    124         # the inverse of transformation of coordinates for charge operators

~/miniconda3/envs/quantum/lib/python3.9/site-packages/SQcircuit/circuit.py in _get_LCWB(self)
    339             Y = np.concatenate((np.zeros((count - numLoop, numLoop)),
    340                                 np.eye(numLoop)), axis=0)
--> 341             self.K2 = np.linalg.inv(X) @ Y
    342             self.K2 = np.around(self.K2, 5)
    343 

<__array_function__ internals> in inv(*args, **kwargs)

~/miniconda3/envs/quantum/lib/python3.9/site-packages/numpy/linalg/linalg.py in inv(a)
    538     a, wrap = _makearray(a)
    539     _assert_stacked_2d(a)
--> 540     _assert_stacked_square(a)
    541     t, result_t = _commonType(a)
    542 

~/miniconda3/envs/quantum/lib/python3.9/site-packages/numpy/linalg/linalg.py in _assert_stacked_square(*arrays)
    201         m, n = a.shape[-2:]
    202         if m != n:
--> 203             raise LinAlgError('Last 2 dimensions of the array must be square')
    204 
    205 def _assert_finite(*arrays):

LinAlgError: Last 2 dimensions of the array must be square

I use SQcircuit version 0.0.10 and python 3.9.12

taha1373 commented 2 years ago

Hi @AlesyaSokol thanks for reporting your issue.

In SQcircuit, the edges that you put in the elements should form a connected graph (the node 3 is not connected to anywhere in your code) . In your circuit, two fluxoniums share a common ground which is 0 node. You should change the elements dictionary as follow (I changed the (2, 3) edge to (0, 2) edge):

elements = {
    (0, 1): [JJ1, L1, C1],
    (1, 2): [Cg],
    (0, 2): [JJ2, L2, C2]
}

Let me know if you have any further questions.