4.2. Harmonic Balance
The tunneling current calculation on the previous page needs the voltage across the junction. In practice, the junction is embedded in an RF circuit (the waveguide probe, tuning circuit, IF circuit, etc.), and the voltage across it depends on how much current it draws, which in turn depends on the voltage. Harmonic balance solves for the junction voltage that satisfies both at the same time.
As before, all values are normalized to the gap voltage, gap current, normal-state resistance and gap frequency.
4.2.1. The embedding circuit
The embedding circuit is linear, so at each frequency it can be reduced to a Thevenin equivalent: a voltage source \(V_{T}\) in series with an impedance \(Z_{T}\). QMix uses one Thevenin circuit for every tone \(f\) and harmonic \(p\) (qmix.circuit.EmbeddingCircuit, attributes vt[f, p] and zt[f, p]). A source can be zero: for example, a harmonic of the LO, or the IF of a mixer, is generated by the junction itself, and it develops a voltage only through the embedding impedance at that frequency.
The DC bias is treated as an ideal voltage source, so the DC voltage across the junction is the bias voltage \(V_0\).
4.2.2. The harmonic balance equations
At each frequency, the junction voltage \(V_{J}\) and current \(I_{J}\) must satisfy Kirchhoff’s voltage law around the Thevenin circuit:
for every tone \(f\) and harmonic \(p\). The current at each frequency is calculated with MTSDA from the voltages at all frequencies, \(\mathbf{V}_J\), so these equations are coupled and strongly non-linear. For \(F\) tones with \(P\) harmonics each, there are \(N = F P\) complex unknowns at every bias voltage. The bias voltages are independent of each other, so QMix solves them all at once, as vectors.
The equations are written as an error function that is zero at the solution:
where the products are taken element by element.
4.2.3. Newton’s method
qmix.harmonic_balance.harmonic_balance() finds the root of \(\mathbf{e}\) with Newton’s method. The first guess treats the junction as a fixed impedance \(Z_J\) (zj_guess, 0.67 by default):
Then each iteration linearizes the error around the current estimate and solves for a correction.
The current is not an analytic function of the complex voltage: it depends on the magnitude and phase of each voltage separately, through the Bessel functions. QMix therefore treats the real and imaginary parts of each voltage as separate unknowns. The Jacobian is a real \(2N \times 2N\) matrix, built from \(2 \times 2\) blocks
for every pair of signals \(p, q\). Since \(\mathbf{V}_T\) and \(\mathbf{Z}_T\) are fixed, \(\partial e_p / \partial V_q = -Z_{T,p} \, \partial I_p / \partial V_q - \delta_{pq}\), so the Jacobian follows from the derivatives of the tunneling current. The Newton step is
4.2.4. The Jacobian
By default (jacobian='analytic'), QMix calculates the derivatives of the current analytically (qmix.qtcurrent.qtcurrent_derivatives()). The voltage only enters the tunneling current through the phase factor coefficients of each tone (see Multi-Tone Spectral Domain Analysis). Changing harmonic \(q\) of a tone with frequency \(\omega\) by \(\delta V_q\) adds \(\mathrm{Re}(\delta V_q \, e^{j q \omega t})\) to the voltage, which multiplies the phase factor by \(1 - j \, (\mathrm{Re}\,\delta V_q \sin q \omega t + \mathrm{Im}\,\delta V_q \cos q \omega t) / q \omega\), to first order. This shifts the coefficients by \(\pm q\):
For one harmonic, these are the Bessel function identities \(2 J_n' = J_{n-1} - J_{n+1}\) and \(2 n J_n / \alpha = J_{n-1} + J_{n+1}\). The derivative of the current is then given by the same sum as the current itself (Eqn. (1)), with the pair products \(C_k C^*_{k+a}\) of the perturbed tone replaced by their derivatives, \(\partial C_k \, C^*_{k+a} + C_k \, \partial C^*_{k+a}\). The response function is not differentiated: it is evaluated at the same voltages as for the current. The result is exact, up to the truncation of the sums. With harmonics, the coefficients are calculated with \(B + P\) terms, so the shifted coefficients are available, while the current uses a truncated convolution of the harmonics. The two agree once \(B\) is large enough for the current to be accurate.
All of the derivatives are evaluated together, in one pass over the response function matrix per batch of terms (see Multi-Tone Spectral Domain Analysis). The sum over the innermost tone is the same for the current and for the derivatives with respect to every other tone, so it is formed once and reused. Only the derivatives with respect to the innermost tone need their own sums. A Jacobian therefore costs much less than the \(2N\) tunneling current calculations of finite differences. In the benchmarks, harmonic balance is 1.2-1.5 times faster for one junction (one to four tones) and about 1.9 times faster for two junctions. Since the Jacobian is exact, Newton’s method also converges in some cases where the finite-difference Jacobian needs the line search below.
With jacobian='numerical', the derivatives are calculated with forward differences instead, with steps of \(10^{-3}\) (DV) in the real and imaginary part of each voltage, at a cost of \(2N\) tunneling current calculations. This was the only method before version 1.1.0.
Either way, building the Jacobian is a large part of the run time. QMix therefore keeps the same Jacobian for further iterations as long as each iteration still at least halves the largest relative error (reuse_jacobian=True, JACOBIAN_REUSE_RATIO). Near the solution, Newton’s method converges so quickly that an outdated Jacobian is usually good enough.
4.2.5. Robustness
When the junction loads the embedding circuit strongly (e.g., a large embedding impedance near the gap voltage), the full Newton step can overshoot and the iteration can diverge. QMix guards against this in three ways (line_search=True, the default):
Line search. At each bias voltage, the Newton step is only accepted if it reduces the squared error \(|\mathbf{e}|^2\) enough (the sufficient decrease condition). Otherwise the step is shortened, by backtracking, until it does. The error at the accepted step is also the error for the next iteration, so full steps cost nothing extra.
New Jacobian. If no acceptable step exists with an outdated Jacobian, the voltage at that bias point is kept and a new Jacobian is calculated.
Restart. If no acceptable step exists even with a new Jacobian (the iteration is stuck near a local minimum of the error rather than a root), the bias point is restarted from the solution at the nearest bias voltage that has already converged.
For multi-tone simulations with one strong tone (e.g., an LO with weak signals), warm_start=True first solves the strongest tone on its own, which is cheap, and uses the result as the starting point for that tone. This often cuts the number of multi-tone iterations by 2-3 times, but not always, so it is not the default.
4.2.6. Convergence
The iteration stops when the relative error, \(|e_{fp}| / |V_{J,fp}|\), is below stop_rerror (\(10^{-3}\) by default) for every signal and bias voltage, or after max_it iterations. Bias voltages that have converged keep being updated while the others are still converging, so most of them end up much more accurate than the tolerance (typically \(\sim 10^{-12}\)). The solution can be checked independently with qmix.harmonic_balance.check_hb_error().
The result is the junction voltage vj[f, p, i] for every tone, harmonic and bias voltage. It can be passed to qmix.qtcurrent.qtcurrent() to calculate the currents at any frequency, e.g., the DC current (the pumped I-V curve) or the current at the IF (the output power of a mixer).
4.2.7. Several junctions
With several junctions in one linear network (e.g., a twin-junction tuning circuit or a series array; qmix.circuit.MultiJunctionCircuit), the embedding circuit at each signal is a multi-port Thevenin equivalent: a vector of open-circuit voltages and an impedance matrix. For junctions \(j, l\),
and the unknowns are the voltages of all junctions. The current of each junction only depends on its own voltage, so \(\partial I_{l,fp} / \partial V_{J,j,q} = 0\) for \(j \ne l\), and
The junctions may be different. All values are normalized to one gap voltage \(V_\mathrm{gap}\) and normal-state resistance \(R_n\) (cct.vgap, cct.rn). Junction \(j\) has the normal-state conductance cct.area[j] \(= R_n / R_{n,j}\), the gap voltage cct.gap_voltage[j] \(= r_j = V_{\mathrm{gap},j} / V_\mathrm{gap}\), and its own response function \(\tilde{I}_j\) (a list of response functions), normalized to its own gap voltage and normal-state resistance. In circuit units, its response function is
times area[j] (qmix.respfn.GapScaledRespFn; qmix.circuit.MultiJunctionCircuit.set_junction() sets area and gap_voltage from the physical values). The phase factor coefficients depend only on the ratio of the voltage to the frequency, so this is the same as simulating the junction in its own units, with all voltages and frequencies divided by \(r_j\).
The derivatives of each junction’s current are calculated as for one junction (analytically, or with jacobian='numerical' from the same perturbed voltages, signal \(q\) of every junction at once, at a cost of \(2N\) tunneling current calculations per junction). The Newton step, line search and restarts are the same. By default, each junction is voltage biased (cct.vb[j]; see below for a DC bias network). Each junction can have its own response function (pass a list as resp) and a relative area (cct.area[j], which scales its current), and the result is vj[j, f, p, i]. qmix.network.set_thevenin() sets the Thevenin voltages and impedance matrices from an S-parameter network, with a list of junction ports.
4.2.8. DC bias network
Voltage bias fixes the DC voltage of each junction. In a series array, one source biases several junctions: the DC current is shared, and the bias voltage splits between the junctions according to their (pumped) DC I-V curves. Unless the junctions are identical and identically pumped, the split isn’t known in advance, so the DC voltages \(V_{0,j}\) become unknowns too. A linear DC network adds one equation per junction,
where \(I_{0,l}\) is the DC tunneling current of junction \(l\) (including its area). For example, \(A = 1, B = 0\) is voltage bias, \(A = 1, B = R\) a DC Thevenin circuit, and \(A = 0, B = 1\) current bias. qmix.circuit.MultiJunctionCircuit.set_series_bias() sets up one or several series strings across a bias voltage \(V_\mathrm{bias}\), through a bias resistance \(R_\mathrm{bias}\): for each string, \(\sum_{j \in \mathrm{string}} V_{0,j} + R_\mathrm{bias} I_\mathrm{total} = V_\mathrm{bias}\), plus \(I_{0,j} = I_{0,j+1}\) along the string (set_dc_network() takes \(A\), \(B\) and \(b\) directly).
The DC voltages are appended to the unknowns (as complex numbers with their imaginary parts pinned to zero, so the Newton step, line search and restarts are unchanged). The response function is shifted by the DC voltage (Eqn. 5.25 uses \(\mathrm{resp}(V_0 + k \omega_1 + l \omega_2 + \dots)\)), so it is interpolated again for each error vector. The Jacobian has three new blocks: the derivatives of the DC currents with respect to the signals (analytic, the zero-frequency output of the same sums), and the derivatives of all currents with respect to the DC voltages, which are central differences (step DV_DC), with the DC voltages of all junctions perturbed at once. This costs two more current calculations per Jacobian. The DC equations count as converged when \(|e_{0,r}|\) is below stop_rerror times the largest DC voltage at that bias point (at least DC_VREF).
qmix.harmonic_balance.harmonic_balance() then returns the DC voltages with the junction voltage, vj, vb = harmonic_balance(cct, resp), and cct.vb is only the initial guess (each junction replaced by its normal resistance). Set cct.vb = vb before calculating currents with the solution.
Series arrays are harder for Newton’s method than voltage-biased junctions:
Where the DC I-V curve is flat (below the gap, or on a photon step), the current hardly depends on the voltage, so the split between the junctions is set by the small slope there (e.g., the leakage current). It is ill-conditioned, and undefined for an ideal I-V curve without leakage.
Pumped I-V curves can have several solutions, and the error can have local minima that are not solutions. A bias point whose squared error hasn’t halved in
STALL_ITERATIONS(5) iterations is restarted from the nearest converged bias point.A near-ideal gap (very sharp current rise) makes Newton’s method crawl when junctions of a string sit on the gap. Smearing the I-V curve (
v_smear) helps, as in most simulations.
Typical cases take 15-30 iterations instead of ~5, so the default max_it is 60 with a DC bias network (30 otherwise). Each iteration solves all bias points at once, so this is still fast (1-2 s for a pumped pair over 40-200 bias points). Solving the bias points one at a time along the sweep (continuation, starting each from its neighbor) needs only 4-10 iterations per point, but was 4-8 times slower overall.
4.2.9. Choosing the parameters
num_b: the summation limit for the phase factor coefficients, one value per tone or one for all. It must be larger than the drive level of each tone, \(|V_{J,f1}| / \omega_f\). Tones that are driven hard at a low frequency need many terms, e.g., an IF tone with a large voltage swing. After a first solution,qmix.qtcurrent.suggest_num_b()estimates the limits from the junction voltage. It uses the junction voltage rather thanvt, since tones with no source can still have large voltages.num_p(inqmix.circuit.EmbeddingCircuit): the number of harmonics of each tone. Each harmonic adds unknowns and widens the range of the sums. One or two harmonics are usually enough, since the junction capacitance shorts out the higher harmonics.method: how the sums in the tunneling current are evaluated: directly or with the The Fourier-Shift Method.'auto'picks the Fourier-shift method only when the direct method would need too much memory.