stanfordLINQS / SQcircuit

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

This solver cannot solve your circuit. #6

Open decod81 opened 2 years ago

decod81 commented 2 years ago

Hi. I was hoping to quickly try out different coupling circuits between two transmons and generate numerical Hamiltonians for the system in order to simulate CZ gate fidelities in time domain, but seems SQcircuit is unable to solve most of my circuits. It just gives ValueError: This solver cannot solve your circuit. I give the simplest example of my code here so one can replicate the problem.

My brief investigation suggests some accuracy check fails in circuit.py. If I remove the check, the code executes, but it sees 4 modes instead of 3 as there should be (easy to verify for example in qucat). I guess SQcircuit needs the number of nodes to correspond to the number of modes, but for arbitrary schematics this is often not the case.

I tried using qucat to generate Hamiltonians as well, but qucat only generates near diagonal H and eliminates the coupling terms I need for my simulations so I was hoping SQcircuit could solve my problem. A quick numerical test I did appeared to suggest SQcircuits might be usable the way I hoped for simple capacitively coupled transmons, but maybe not for more complicated circuits. Perhaps also worth mentioning is that to get correct eigenfrequencies even for capacitively coupled qubits, I had to use relatively high truncation number (maybe 10) which resulted in rather large numerical H compared to what would otherwise suffice if one derives it by hand (3) and while perhaps not an issue as such, it would slow down the numerical simulations quite a bit.

I'm not sure if these are bugs or features, but I just felt it might be worthwhile to bring into your attention what I was hoping for from SQcircuit and how I at least so far failed to reach it. Comments and suggestions are appreciated.

from numpy import *
import SQcircuit as sqc

J = 2.07e-15/2/pi/1e9/6.6e-34
C = 1.6e-19**2/2/1e9/6.6e-34
L = (2.07e-15/2/pi)**2/1e9/6.6e-34

CJ1 = sqc.Capacitor(C/85e-15)
JJ1 = sqc.Junction(J*32e-9*0.999)
Cc1 = sqc.Capacitor(C/40e-20)

Cr2A = sqc.Capacitor(C/117e-15)
Lr2 = sqc.Inductor(L/2.34e-9)
Cr2B = sqc.Capacitor(C/117e-15)

Cc2 = sqc.Capacitor(C/40e-20)
CJ2 = sqc.Capacitor(C/85e-15)
JJ2 = sqc.Junction(J*32e-9/0.999)

circuit = {(0, 1): [CJ1, JJ1],
           (1, 2): [Cc1],
           (0, 2): [Cr2A],
           (2, 3): [Lr2],
           (0, 3): [Cr2B],
           (3, 4): [Cc2],
           (0, 4): [CJ2, JJ2]}

cir = sqc.Circuit(circuit)
cir.description()
taha1373 commented 2 years ago

Hi @decod81,

Thanks for using SQcircuit and sharing your issue with us.

The error that you encountered is an old piece of code (I should have removed it). Basically, SQcircuit should be able to solve your problem. I will take a look at the circuit and I will get back to you. Probably there is a bug that I should fix.

taha1373 commented 2 years ago

Hi @decod81

Let me clarify several points regarding your issue.

decod81 commented 2 years ago

Thank you very much for the quick fix and clarifications.

Upon my quick testing it seems to work now most of the time. It did fail once though in the middle of a bunch of runs with the same message and then worked again with the next runs (working and failed runs were with identical parameters). I guess there is some random factor that causes fail every now and then, but as long as it doesn't become too frequent in some interesting parameter range, I think it's good.

I guess I might run into problems with some of my circuits due to too large Hilbert space for practical simulations, but I suppose that was to be expected. Good to know you're working on it.

taha1373 commented 2 years ago

Hi @decod81, Thanks again for your great feedback. I noticed the problem. It is an issue with Gram–Schmidt process accuracy. I will fix it in the next patch (0.0.15).