Custom sweepsΒΆ
ParameterSweep generates data commonly needed in a multi-component quantum system. Other quantities of interest can be generated by defining a custom sweep function generating the data and calling <ParameterSweep>.add_sweep(...).
To do so, define a function of the following form:
def custom_func(paramsweep, paramindex_tuple, paramvals_tuple, **kwargs): ... return data
As a toy example, here is a function that returns the 01 charge matrix element for tmon2 at each parameter point:
[2]:
def tmon2_n01(paramsweep, paramindex_tuple, paramvals_tuple, **kwargs):
# We could recalculate matrix elements from scratch, but it is advantageous to use the bare spectral
# data we have already calculated.
bare_evecs = paramsweep["bare_evecs"]["subsys":1][paramindex_tuple]
n_matrix_elements = tmon2.matrixelement_table(
operator="n_operator",
evecs=bare_evecs,
evals_count=tmon2.truncated_dim,
)
return np.abs(n_matrix_elements[0,1])
The add_sweep method takes the callable function one argument, and the name under which the scan should be stored as the second argument:
[3]:
sweep[:].add_sweep(tmon2_n01, "n01")
Pre-slicing is required; here the sweep is to extend over all parameter sets associated with sweep. The resulting data is accessible by dict-like access, and yields a NamedSlotsNdarray:
[4]:
sweep["n01"]
[4]:
NamedSlotsNdarray([[1.30478755, 1.30478755, ..., 1.30478755, 1.30478755],
[1.30446711, 1.30446711, ..., 1.30446711, 1.30446711],
...,
[1.02349545, 1.02349545, ..., 1.02349545, 1.02349545],
[0.99863368, 0.99863367, ..., 0.99863367, 0.99863368]])
We can easily take a slice for fixed flux and plot the result:
[5]:
sweep["n01"]["flux":35].plot()
[5]:
(<Figure size 640x480 with 1 Axes>, <Axes: xlabel='ng'>)