stanfordLINQS / SQcircuit

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

Incorrectly getting "The edge list does not specify a connected graph or all inductive loops of the circuit are not specified" error #32

Open eliweissler opened 2 months ago

eliweissler commented 2 months ago

In trying to analyze this circuit, I get the "The edge list does not specify a connected graph or all inductive loops of the circuit are not specified" error. As far as I can tell, both of those things are true:

Screenshot 2024-07-12 at 4 50 40 PM

Code to reproduce the error:

import SQcircuit as sq

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

ec = 1
ecj = 3
ej = 5
el = 0.5

circuit_dict = {}
circuit_dict[(0, 1)] = [sq.Capacitor(ec, "GHz", id_str="C01")]
circuit_dict[(0, 2)] = [sq.Capacitor(ec, "GHz", id_str="C02")]
circuit_dict[(0, 3)] = [sq.Capacitor(ec, "GHz", id_str="C03")]
circuit_dict[(1, 2)] = [sq.Junction(ej, "GHz", id_str="J12", loops=[loop1],
                                   cap = sq.Capacitor(ecj, "GHz", id_str="JC12"))]
circuit_dict[(1, 3)] = [sq.Junction(ej, "GHz", id_str="J13", loops=[loop1],
                                   cap = sq.Capacitor(ecj, "GHz", id_str="JC13"))]
circuit_dict[(2, 3)] = [sq.Junction(ej, "GHz", id_str="J23", loops=[loop1, loop2],
                                   cap = sq.Capacitor(ecj, "GHz", id_str="JC23")),
                                   sq.Inductor(el, "GHz", id_str="J23", loops=[loop2])]

sq.Circuit(circuit_dict, flux_dist="junctions")

I think the error stems from the matrix inversion on line 395 of circuit.py. Requiring X to be square requires the number of inductive elements in the circuit to be equal to the number of non-ground nodes plus the number of loops. I think the "if" statement on line 380 catches all cases where this isn't true for 2 & 3 node circuits, but it misses some like this that are 4 nodes.

Could a possible fix could be to extend the "if" statement on line 380 to remove as many columns from K1 as is necessary to end up with a square X? I'm not sure if this would have some unexpected weirdness with assigning fluxes.

Thank you for your time and for developing SQcircuit! I've really enjoyed using the package and reading about the methods behind it!

taha1373 commented 2 months ago

Hi @eliweissler,

Thank you for your interest in SQcircuit and its paper. I really appreciate your feedback. I believe your suggestion could solve the problem. I will take a deeper look at the circuit as soon as possible and update you accordingly.