Quantum Transport
unitarylab_algorithms.quantum_transport provides NEGFAlgorithm, added in Algorithms library 1.1.13. It uses the non-equilibrium Green’s function (NEGF) method to describe a rectangular square-lattice device connected to left and right semi-infinite leads. The built-in UnitaryLab QSVT solver computes lead-injection responses, from which transmission, local density of states (LDOS), and bond current are calculated.
Installation and Imports
pip install unitarylab unitarylab-algorithms kwantDirect dependencies include NumPy, SciPy, Matplotlib, Kwant, and UnitaryLab. Kwant is imported inside run() and must be available before execution; this page does not guarantee that prebuilt packages are available on every platform.
from unitarylab_algorithms import NEGFAlgorithm
# Equivalent category entry:
from unitarylab_algorithms.quantum_transport import NEGFAlgorithmMinimal Example
from tempfile import TemporaryDirectory
from unitarylab_algorithms import NEGFAlgorithm
with TemporaryDirectory() as output_dir:
result = NEGFAlgorithm(algo_dir=output_dir).run(
L=2, W=2, a=1.0, t=1.0, inverse_tolerance=2e-3,
)
print(result["transmission"])
print(result["injection_residuals"])
print(result["qasm_paths"])The temporary directory is deleted when the block exits; use a persistent directory to retain files. The constructor accepts text_mode="plain" and algo_dir=None, defaulting to results/quantum_transport/negf/ under the current working directory.
The module-level test(L=4, W=4, a=1.0, t=1.0, inverse_tolerance=2e-3) can be imported from unitarylab_algorithms.quantum_transport.negf or its algorithm module. It uses text_mode="legacy" and returns the same result dictionary.
Parameters and Model
| Parameter | Default | Description |
|---|---|---|
L | 4 | Number of scattering-region sites along x; an integer of at least 2, not a boolean |
W | 4 | Number of sites along y and the width of both leads; an integer of at least 2, not a boolean |
a | 1.0 | Lattice constant; a positive value is recommended for this model, without a separate positivity check in the interface |
t | 1.0 | Hopping energy scale (eV); a positive value is recommended for this model, without a separate positivity check in the interface |
inverse_tolerance | 2e-3 | Finite reciprocal-polynomial relative-error tolerance strictly within (0, 1) |
run() accepts only these five algorithm parameters. It does not accept custom energy, a Hamiltonian, backend, device, dtype, or shots. Internally it uses NumPy on CPU with np.complex128, reading simulated state amplitudes rather than finite-shot statistics.
The onsite energy is 4*t, and nearest-neighbor hopping is -t. Injection energy is automatically set to the midpoint of the first two transverse subband thresholds:
Computation and Error
- Kwant constructs the scattering region and leads and provides the device matrix and lead self-energies; broadening matrices are stored only as local interface blocks.
- Assemble and obtain injection vectors by decomposing .
- Convert the solver matrix to a dense array, pad it to a power of two, and construct the QSVT body once. Each channel is executed separately using an actual circuit containing input-state preparation.
- Read the all-zero-ancilla block and restore the right-hand-side norm, scaling, and complex phase to obtain approximate solutions to and .
- Independently compute relative injection-equation residuals, then classically calculate observables:
Bond current retains the expression 2 * imag(H_C[i, j] * vdot(X_L[i], X_L[j])) and follows the directed-bond order of Kwant’s fsyst.graph. It is not a finite-bias current in SI amperes; this implementation does not include bias-window integration, occupation weights, or an SI current prefactor.
inverse_tolerance calibrates the SDK’s internal epsilon once, checking reciprocal-polynomial error on 20001 spectral grid points and the actual singular values. inverse_polynomial_error is the maximum relative error found by this check, not a rigorous continuous-spectrum error proof. Final equation residuals are stored separately in injection_residuals, without asserting failure against the same tolerance. The matrix must be invertible at the current numerical precision; missing propagating channels or failed numerical calibration raise an exception.
Return Fields
The result follows the shared base-class return convention, with status="ok" on success and these fields:
| Field | Description |
|---|---|
circuit_path, circuit | SVG path and object for the first actual injection circuit, including input-state preparation and the QSVT body |
plot | List of generated-file format and filename entries; filenames are relative to the result directory |
circuits, circuit_paths | All actual circuits and SVG paths, ordered by left-lead then right-lead injection channels |
qasm_paths | Paths of successfully exported QASM2 files |
qasm_export_errors | Unsupported-export records, each containing circuit name circuit and exception text reason |
ENERGY | Automatically computed injection energy |
left_channels, right_channels | Retained left/right injection-channel counts |
transmission | Transmission |
injection_residuals | Per-channel norm(A @ x - b) / norm(b) |
epsilon, inverse_polynomial_error | Calibrated SDK parameter and reciprocal-polynomial error |
scaling_factor, rhs_norms | SDK scaling factor and original injection-vector norms |
system_size | Original scattering-region matrix dimension L*W |
ldos | LDOS array in scattering-region site order |
bond_current | Bond-current array in directed-bond order |
The return dictionary includes NumPy arrays and Circuit objects, so it is not directly JSON serializable. status="ok" means the workflow completed; it does not guarantee that residuals meet the specified tolerance or that every circuit was exported to QASM successfully.
Files and Limitations
negf_result.txt: inputs, logs, and result summary.kwant_square_system.png,kwant_square_ldos.png,kwant_square_current.png: device structure, LDOS, and bond-current plots.negf_circuit.svg,negf_circuit_2.svg, etc.: the actual circuit executed for each channel.negf_circuit.qasm,negf_circuit_2.qasm, etc.: generated only when the corresponding circuit is successfully exported to QASM2.
QASM2 export uses to_qasm2(transpile=True). Under the current SDK’s Nagy decomposition size limit, the padded system dimension must satisfy N <= 32 (equivalently L*W <= 32) to meet that export-size requirement; this is not a site-count limit imposed by run(). The default 4×4 device is within this range. Other gate or version limitations can still cause export failure.
A NotImplementedError during export is recorded per channel in qasm_export_errors, and that channel is omitted from qasm_paths. Numerical results, all actual circuits, and SVG files are retained, and the algorithm continues to return success. Other exceptions propagate normally. QASM2 export omits uncontrolled global phases; account for this phase if reconstructing responses from individual complex amplitudes of the exported circuit.
SVG diagrams can be truncated by the SDK’s default drawing-depth limit and cannot establish the full gate count. Although matrix assembly is sparse, the solver path still includes dense linear algebra and full-state simulation. More lattice sites or a tighter tolerance can substantially increase computation and export costs; this does not establish an end-to-end quantum speedup.