scqubits / scqubits

Superconducting Qubits in Python
BSD 3-Clause "New" or "Revised" License
231 stars 94 forks source link

[Help] Coupled transmons w/ tunable capacitive coupler hanging on construction #148

Closed QuantumWitness closed 2 years ago

QuantumWitness commented 2 years ago

General

I've been trying to implement the circuit found in Fig2a of this paper, but when I attempt to use the from_yaml function it appears to hang. I am not sure why, since I expected a 3 node circuit to be easily constructible, since the custom circuit in the scqubits documentations is a 4-node $0-\pi$ qubit.

I tried this in Spyder and also directly in iPython in the terminal with the same results.

Code

Here's what I used to create the circuit. Note I elide the parasitic capacitor $C_{12}$ for simplicity.

import scqubits as scrub

tcap_coupled_tmon = """# transmon circuit
branches:
- ["JJ", 0, 1, EJ=12,10]
- ["JJ", 1, 0, EJ,10]
- ["C", 1, 0, EC=0.2]
- ["C", 1, 2, E_coup=5]
- ["JJ", 0, 2, EJc=24,10]
- ["JJ", 2, 0, EJc,10]
- ["C", 2, 0, EC2=0.1]
- ["C", 2, 3, E_coup]
- ["JJ", 0, 3, EJ,10]
- ["JJ", 3, 0, EJ,10]
- ["C", 3, 0, EC]
"""

tcap_tmons = scqub.Circuit.from_yaml(tcap_coupled_tmon, from_file=False,
                               ext_basis="discretized")

The Ask

I expected this to work quickly, so I'm not entirely sure why it's not working. Is there some other way I can define this? Or something I'm not understanding about how the circuit I want to make is difficult for the software? Some sort of issue with the variable classification?? I'm just guessing here.

Additional info

image

Versions

OS: macOS 12.1 Python: 3.8 scqubits: 3.0.1

jkochNU commented 2 years ago

@QuantumWitness As far as I can tell, the hang-up occurs on the sympy side when computing the capacitance matrix inverse symbolically. Indeed, I would never want to see the inverse of a generic symbolic 4x4 matrix. That will be a huge expression. The way to go is to work with numerical entries in the capacitance matrix only. Once I change the yaml description to values only, the circuit initialization is fast.

@saipavanc @pacosynthesis

  1. Please confirm that the slowdown is expected in this case.
  2. Consider issuing a warning message of this problem before launching into the sympy inversion. That way the user might get a chance to understand what the problem is.
  3. Revisit the user guide and check that this is suitably documented.
saipavanc commented 2 years ago

@jkochNU That is correct! The slowdown is due to the Sympy symbolic inversion of the capacitance matrix. We did notice this slowdown even for circuits like zero-pi, and so changed the code such that the symbolic inversion is skipped for circuits having number of nodes greater than the threshold of 4. And this circuit falls just short of that threshold, and the circuit initiation continues with symbolic inversion. The resultant expressions are overly long even if just one symbol is used for one of the capacitors. Now, it seems like the threshold can be reduced to just 2 nodes.

@QuantumWitness Thanks for catching the bug. As a workaround, just replace the ground node 0 with another node. Like in this YAML description:

tcap_coupled_tmon = """# transmon circuit
branches:
- ["JJ", 4, 1, EJ=12,10]
- ["JJ", 1, 4, EJ,10]
- ["C", 1, 4, EC=0.2]
- ["C", 1, 2, E_coup=5]
- ["JJ", 4, 2, EJc=24,10]
- ["JJ", 2, 4, EJc,10]
- ["C", 2, 4, EC2=0.1]
- ["C", 2, 3, E_coup]
- ["JJ", 4, 3, EJ,10]
- ["JJ", 3, 4, EJ,10]
- ["C", 3, 4, EC]
"""

For the threshold I mentioned above, I am only considering the number of nodes excluding the ground node. So, removing the ground and adding an extra node pushes it over the threshold. Thus, the symbolic inversion is skipped until the numerical Hamiltonian is constructed and the circuit initiation is quick as expected. In the meanwhile, we will discuss and implement a fix to avoid such hangs in the future.

QuantumWitness commented 2 years ago

Both of these work-arounds worked well for me, thank you!

ZhaoTianPu commented 2 years ago

This issue has been addressed with https://github.com/scqubits/scqubits/commit/17ddb655ad7fbaedcdec2a896b47cd6a43453630 and released with v3.0.2. In the current version, the inversion of capacitance matrix is carried out numerically when the total node number is greater than 3 by default, no matter the circuit is grounded or not. The hang-up will not occur with the original input file in https://github.com/scqubits/scqubits/issues/148#issue-1298371769.