For Developers

The following classes are mainly of interest for developers.

Qubit base classes

class scqubits.core.qubit_base.QubitBaseClass(*args, **kwargs)[source]

Base class for superconducting qubit objects. Provide general mechanisms and routines for plotting spectra, matrix elements, and writing data to files

broadcast(event, **kwargs)

Request a broadcast from CENTRAL_DISPATCH reporting event.

Parameters
  • event (str) – event name from EVENTS

  • **kwargs

Return type

None

classmethod create()

Use ipywidgets to create a new class instance

Return type

QuantumSystem

abstract static default_params()

Return dictionary with default parameter values for initialization of class instance

eigensys(evals_count=6, filename=None, return_spectrumdata=False)[source]

Calculates eigenvalues and corresponding eigenvectors using scipy.linalg.eigh. Returns two numpy arrays containing the eigenvalues and eigenvectors, respectively.

Parameters
  • evals_count (int) – number of desired eigenvalues/eigenstates (default value = 6)

  • filename (Optional[str]) – path and filename without suffix, if file output desired (default value = None)

  • return_spectrumdata (bool) – if set to true, the returned data is provided as a SpectrumData object (default value = False)

Return type

Tuple[ndarray, ndarray]

Returns

eigenvalues, eigenvectors as numpy arrays or in form of a SpectrumData object

eigenvals(evals_count=6, filename=None, return_spectrumdata=False)[source]

Calculates eigenvalues using scipy.linalg.eigh, returns numpy array of eigenvalues.

Parameters
  • evals_count (int) – number of desired eigenvalues/eigenstates (default value = 6)

  • filename (Optional[str]) – path and filename without suffix, if file output desired (default value = None)

  • return_spectrumdata (bool) – if set to true, the returned data is provided as a SpectrumData object (default value = False)

Return type

ndarray

Returns

eigenvalues as ndarray or in form of a SpectrumData object

get_dispersion_vs_paramvals(dispersion_name, param_name, param_vals, ref_param=None, transitions=(0, 1), levels=None, point_count=50, num_cpus=None)[source]

Calculates eigenvalues/eigenstates for a varying system parameter, given an array of parameter values. Returns a SpectrumData object with energy_data[n] containing eigenvalues calculated for parameter value param_vals[n].

Parameters
  • dispersion_name (str) – parameter inducing the dispersion, typically ‘ng’ or ‘flux’ (will be scanned over range from 0 to 1)

  • param_name (str) – name of parameter to be varied

  • param_vals (ndarray) – parameter values to be plugged in

  • ref_param (Optional[str]) – optional, name of parameter to use as reference for the parameter value; e.g., to compute charge dispersion vs. EJ/EC, use EJ as param_name and EC as ref_param

  • transitions (Union[Tuple[int], Tuple[Tuple[int], ...]]) – integer tuple or tuples specifying for which transitions dispersion is to be calculated (default: = (0,1))

  • levels (Union[int, Tuple[int], None]) – tuple specifying levels (rather than transitions) for which dispersion should be plotted; overrides transitions parameter when given

  • point_count (int) – number of points scanned for the dispersion parameter for determining min and max values of transition energies (default: 50)

  • num_cpus (Optional[int]) – number of cores to be used for computation (default value: settings.NUM_CPUS)

Return type

SpectrumData

get_initdata()

Returns dict appropriate for creating/initializing a new Serializable object.

Return type

Dict[str, Any]

get_matelements_vs_paramvals(operator, param_name, param_vals, evals_count=6, num_cpus=None)[source]

Calculates matrix elements for a varying system parameter, given an array of parameter values. Returns a SpectrumData object containing matrix element data, eigenvalue data, and eigenstate data..

Parameters
  • operator (str) – name of class method in string form, returning operator matrix

  • param_name (str) – name of parameter to be varied

  • param_vals (ndarray) – parameter values to be plugged in

  • evals_count (int) – number of desired eigenvalues (sorted from smallest to largest) (default value = 6)

  • num_cpus (Optional[int]) – number of cores to be used for computation (default value: settings.NUM_CPUS)

Return type

SpectrumData

get_spectrum_vs_paramvals(param_name, param_vals, evals_count=6, subtract_ground=False, get_eigenstates=False, filename=None, num_cpus=None)[source]

Calculates eigenvalues/eigenstates for a varying system parameter, given an array of parameter values. Returns a SpectrumData object with energy_data[n] containing eigenvalues calculated for parameter value param_vals[n].

Parameters
  • param_name (str) – name of parameter to be varied

  • param_vals (ndarray) – parameter values to be plugged in

  • evals_count (int) – number of desired eigenvalues (sorted from smallest to largest) (default value = 6)

  • subtract_ground (bool) – if True, eigenvalues are returned relative to the ground state eigenvalue (default value = False)

  • get_eigenstates (bool) – return eigenstates along with eigenvalues (default value = False)

  • filename (Optional[str]) – file name if direct output to disk is wanted

  • num_cpus (Optional[int]) – number of cores to be used for computation (default value: settings.NUM_CPUS)

Return type

SpectrumData

abstract hamiltonian()[source]

Returns the Hamiltonian

abstract hilbertdim()

Returns dimension of Hilbert space

Return type

int

matrixelement_table(operator, evecs=None, evals_count=6, filename=None, return_datastore=False)[source]

Returns table of matrix elements for operator with respect to the eigenstates of the qubit. The operator is given as a string matching a class method returning an operator matrix. E.g., for an instance trm of Transmon, the matrix element table for the charge operator is given by trm.op_matrixelement_table(‘n_operator’). When esys is set to None, the eigensystem is calculated on-the-fly.

Parameters
  • operator (str) – name of class method in string form, returning operator matrix in qubit-internal basis.

  • evecs (Optional[ndarray]) – if not provided, then the necessary eigenstates are calculated on the fly

  • evals_count (int) – number of desired matrix elements, starting with ground state (default value = 6)

  • filename (Optional[str]) – output file name

  • return_datastore (bool) – if set to true, the returned data is provided as a DataStore object (default value = False)

Return type

ndarray

plot_dispersion_vs_paramvals(dispersion_name, param_name, param_vals, ref_param=None, transitions=(0, 1), levels=None, point_count=50, num_cpus=None, **kwargs)[source]

Generates a simple plot of a set of curves representing the charge or flux dispersion of transition energies.

Parameters
  • dispersion_name (str) – parameter inducing the dispersion, typically ‘ng’ or ‘flux’ (will be scanned over range from 0 to 1)

  • param_name (str) – name of parameter to be varied

  • param_vals (ndarray) – parameter values to be plugged in

  • ref_param (Optional[str]) – optional, name of parameter to use as reference for the parameter value; e.g., to compute charge dispersion vs. EJ/EC, use EJ as param_name and EC as ref_param

  • transitions (Union[Tuple[int], Tuple[Tuple[int], ...]]) – integer tuple or tuples specifying for which transitions dispersion is to be calculated (default: = (0,1))

  • levels (Union[int, Tuple[int], None]) – int or tuple specifying level(s) (rather than transitions) for which dispersion should be plotted; overrides transitions parameter when given

  • point_count (int) – number of points scanned for the dispersion parameter for determining min and max values of transition energies (default: 50)

  • num_cpus (Optional[int]) – number of cores to be used for computation (default value: settings.NUM_CPUS)

  • **kwargs – standard plotting option (see separate documentation)

Return type

Tuple[Figure, Axes]

plot_evals_vs_paramvals(param_name, param_vals, evals_count=6, subtract_ground=False, num_cpus=None, **kwargs)[source]

Generates a simple plot of a set of eigenvalues as a function of one parameter. The individual points correspond to the a provided array of parameter values.

Parameters
  • param_name (str) – name of parameter to be varied

  • param_vals (ndarray) – parameter values to be plugged in

  • evals_count (int) – number of desired eigenvalues (sorted from smallest to largest) (default value = 6)

  • subtract_ground (bool) – whether to subtract ground state energy from all eigenvalues (default value = False)

  • num_cpus (Optional[int]) – number of cores to be used for computation (default value: settings.NUM_CPUS)

  • **kwargs – standard plotting option (see separate documentation)

Return type

Tuple[Figure, Axes]

plot_matelem_vs_paramvals(operator, param_name, param_vals, select_elems=4, mode='abs', num_cpus=None, **kwargs)[source]

Generates a simple plot of a set of eigenvalues as a function of one parameter. The individual points correspond to the a provided array of parameter values.

Parameters
  • operator (str) – name of class method in string form, returning operator matrix

  • param_name (str) – name of parameter to be varied

  • param_vals (ndarray) – parameter values to be plugged in

  • select_elems (Union[int, List[Tuple[int, int]]]) – either maximum index of desired matrix elements, or list [(i1, i2), (i3, i4), …] of index tuples for specific desired matrix elements (default value = 4)

  • mode (str) – idx_entry from MODE_FUNC_DICTIONARY, e.g., ‘abs’ for absolute value (default value = ‘abs’)

  • num_cpus (Optional[int]) – number of cores to be used for computation (default value: settings.NUM_CPUS)

  • **kwargs – standard plotting option (see separate documentation)

Return type

Tuple[Figure, Axes]

plot_matrixelements(operator, evecs=None, evals_count=6, mode='abs', show_numbers=False, show3d=True, **kwargs)[source]

Plots matrix elements for operator, given as a string referring to a class method that returns an operator matrix. E.g., for instance trm of Transmon, the matrix element plot for the charge operator n is obtained by trm.plot_matrixelements(‘n’). When esys is set to None, the eigensystem with which eigenvectors is calculated.

Parameters
  • operator (str) – name of class method in string form, returning operator matrix

  • evecs (Optional[ndarray]) – eigensystem data of evals, evecs; eigensystem will be calculated if set to None (default value = None)

  • evals_count (int) – number of desired matrix elements, starting with ground state (default value = 6)

  • mode (str) – idx_entry from MODE_FUNC_DICTIONARY, e.g., ‘abs’ for absolute value (default)

  • show_numbers (bool) – determines whether matrix element values are printed on top of the plot (default: False)

  • show3d (bool) – whether to show a 3d skyscraper plot of the matrix alongside the 2d plot (default: True)

  • **kwargs – standard plotting option (see separate documentation)

Return type

Union[Tuple[Figure, Tuple[Axes, Axes]], Tuple[Figure, Axes]]

receive(event, sender, **kwargs)

Receive a message from CENTRAL_DISPATCH and initiate action on it.

Parameters
  • event (str) – event name from EVENTS

  • sender (DispatchClient) – original sender reporting the event

  • **kwargs

Return type

None

set_and_return(attr_name, value)[source]

Allows to set an attribute after which self is returned. This is useful for doing something like example:

qubit.set_and_return('flux', 0.23).some_method()

instead of example:

qubit.flux=0.23
qubit.some_method()
Parameters
  • attr_name (str) – name of class attribute in string form

  • value (Any) – value that the attribute is to be set to

Return type

QubitBaseClass

Returns

self

set_params(**kwargs)

Set new parameters through the provided dictionary.

supported_noise_channels()

Returns a list of noise channels this QuantumSystem supports. If none, return an empty list.

Return type

List

widget(params=None)

Use ipywidgets to modify parameters of class instance

class scqubits.core.qubit_base.QubitBaseClass1d(*args, **kwargs)[source]

Base class for superconducting qubit objects with one degree of freedom. Provide general mechanisms and routines for plotting spectra, matrix elements, and writing data to files.

broadcast(event, **kwargs)

Request a broadcast from CENTRAL_DISPATCH reporting event.

Parameters
  • event (str) – event name from EVENTS

  • **kwargs

Return type

None

classmethod create()

Use ipywidgets to create a new class instance

Return type

QuantumSystem

abstract static default_params()

Return dictionary with default parameter values for initialization of class instance

eigensys(evals_count=6, filename=None, return_spectrumdata=False)

Calculates eigenvalues and corresponding eigenvectors using scipy.linalg.eigh. Returns two numpy arrays containing the eigenvalues and eigenvectors, respectively.

Parameters
  • evals_count (int) – number of desired eigenvalues/eigenstates (default value = 6)

  • filename (Optional[str]) – path and filename without suffix, if file output desired (default value = None)

  • return_spectrumdata (bool) – if set to true, the returned data is provided as a SpectrumData object (default value = False)

Return type

Tuple[ndarray, ndarray]

Returns

eigenvalues, eigenvectors as numpy arrays or in form of a SpectrumData object

eigenvals(evals_count=6, filename=None, return_spectrumdata=False)

Calculates eigenvalues using scipy.linalg.eigh, returns numpy array of eigenvalues.

Parameters
  • evals_count (int) – number of desired eigenvalues/eigenstates (default value = 6)

  • filename (Optional[str]) – path and filename without suffix, if file output desired (default value = None)

  • return_spectrumdata (bool) – if set to true, the returned data is provided as a SpectrumData object (default value = False)

Return type

ndarray

Returns

eigenvalues as ndarray or in form of a SpectrumData object

get_dispersion_vs_paramvals(dispersion_name, param_name, param_vals, ref_param=None, transitions=(0, 1), levels=None, point_count=50, num_cpus=None)

Calculates eigenvalues/eigenstates for a varying system parameter, given an array of parameter values. Returns a SpectrumData object with energy_data[n] containing eigenvalues calculated for parameter value param_vals[n].

Parameters
  • dispersion_name (str) – parameter inducing the dispersion, typically ‘ng’ or ‘flux’ (will be scanned over range from 0 to 1)

  • param_name (str) – name of parameter to be varied

  • param_vals (ndarray) – parameter values to be plugged in

  • ref_param (Optional[str]) – optional, name of parameter to use as reference for the parameter value; e.g., to compute charge dispersion vs. EJ/EC, use EJ as param_name and EC as ref_param

  • transitions (Union[Tuple[int], Tuple[Tuple[int], ...]]) – integer tuple or tuples specifying for which transitions dispersion is to be calculated (default: = (0,1))

  • levels (Union[int, Tuple[int], None]) – tuple specifying levels (rather than transitions) for which dispersion should be plotted; overrides transitions parameter when given

  • point_count (int) – number of points scanned for the dispersion parameter for determining min and max values of transition energies (default: 50)

  • num_cpus (Optional[int]) – number of cores to be used for computation (default value: settings.NUM_CPUS)

Return type

SpectrumData

get_initdata()

Returns dict appropriate for creating/initializing a new Serializable object.

Return type

Dict[str, Any]

get_matelements_vs_paramvals(operator, param_name, param_vals, evals_count=6, num_cpus=None)

Calculates matrix elements for a varying system parameter, given an array of parameter values. Returns a SpectrumData object containing matrix element data, eigenvalue data, and eigenstate data..

Parameters
  • operator (str) – name of class method in string form, returning operator matrix

  • param_name (str) – name of parameter to be varied

  • param_vals (ndarray) – parameter values to be plugged in

  • evals_count (int) – number of desired eigenvalues (sorted from smallest to largest) (default value = 6)

  • num_cpus (Optional[int]) – number of cores to be used for computation (default value: settings.NUM_CPUS)

Return type

SpectrumData

get_spectrum_vs_paramvals(param_name, param_vals, evals_count=6, subtract_ground=False, get_eigenstates=False, filename=None, num_cpus=None)

Calculates eigenvalues/eigenstates for a varying system parameter, given an array of parameter values. Returns a SpectrumData object with energy_data[n] containing eigenvalues calculated for parameter value param_vals[n].

Parameters
  • param_name (str) – name of parameter to be varied

  • param_vals (ndarray) – parameter values to be plugged in

  • evals_count (int) – number of desired eigenvalues (sorted from smallest to largest) (default value = 6)

  • subtract_ground (bool) – if True, eigenvalues are returned relative to the ground state eigenvalue (default value = False)

  • get_eigenstates (bool) – return eigenstates along with eigenvalues (default value = False)

  • filename (Optional[str]) – file name if direct output to disk is wanted

  • num_cpus (Optional[int]) – number of cores to be used for computation (default value: settings.NUM_CPUS)

Return type

SpectrumData

abstract hamiltonian()

Returns the Hamiltonian

abstract hilbertdim()

Returns dimension of Hilbert space

Return type

int

matrixelement_table(operator, evecs=None, evals_count=6, filename=None, return_datastore=False)

Returns table of matrix elements for operator with respect to the eigenstates of the qubit. The operator is given as a string matching a class method returning an operator matrix. E.g., for an instance trm of Transmon, the matrix element table for the charge operator is given by trm.op_matrixelement_table(‘n_operator’). When esys is set to None, the eigensystem is calculated on-the-fly.

Parameters
  • operator (str) – name of class method in string form, returning operator matrix in qubit-internal basis.

  • evecs (Optional[ndarray]) – if not provided, then the necessary eigenstates are calculated on the fly

  • evals_count (int) – number of desired matrix elements, starting with ground state (default value = 6)

  • filename (Optional[str]) – output file name

  • return_datastore (bool) – if set to true, the returned data is provided as a DataStore object (default value = False)

Return type

ndarray

plot_dispersion_vs_paramvals(dispersion_name, param_name, param_vals, ref_param=None, transitions=(0, 1), levels=None, point_count=50, num_cpus=None, **kwargs)

Generates a simple plot of a set of curves representing the charge or flux dispersion of transition energies.

Parameters
  • dispersion_name (str) – parameter inducing the dispersion, typically ‘ng’ or ‘flux’ (will be scanned over range from 0 to 1)

  • param_name (str) – name of parameter to be varied

  • param_vals (ndarray) – parameter values to be plugged in

  • ref_param (Optional[str]) – optional, name of parameter to use as reference for the parameter value; e.g., to compute charge dispersion vs. EJ/EC, use EJ as param_name and EC as ref_param

  • transitions (Union[Tuple[int], Tuple[Tuple[int], ...]]) – integer tuple or tuples specifying for which transitions dispersion is to be calculated (default: = (0,1))

  • levels (Union[int, Tuple[int], None]) – int or tuple specifying level(s) (rather than transitions) for which dispersion should be plotted; overrides transitions parameter when given

  • point_count (int) – number of points scanned for the dispersion parameter for determining min and max values of transition energies (default: 50)

  • num_cpus (Optional[int]) – number of cores to be used for computation (default value: settings.NUM_CPUS)

  • **kwargs – standard plotting option (see separate documentation)

Return type

Tuple[Figure, Axes]

plot_evals_vs_paramvals(param_name, param_vals, evals_count=6, subtract_ground=False, num_cpus=None, **kwargs)

Generates a simple plot of a set of eigenvalues as a function of one parameter. The individual points correspond to the a provided array of parameter values.

Parameters
  • param_name (str) – name of parameter to be varied

  • param_vals (ndarray) – parameter values to be plugged in

  • evals_count (int) – number of desired eigenvalues (sorted from smallest to largest) (default value = 6)

  • subtract_ground (bool) – whether to subtract ground state energy from all eigenvalues (default value = False)

  • num_cpus (Optional[int]) – number of cores to be used for computation (default value: settings.NUM_CPUS)

  • **kwargs – standard plotting option (see separate documentation)

Return type

Tuple[Figure, Axes]

plot_matelem_vs_paramvals(operator, param_name, param_vals, select_elems=4, mode='abs', num_cpus=None, **kwargs)

Generates a simple plot of a set of eigenvalues as a function of one parameter. The individual points correspond to the a provided array of parameter values.

Parameters
  • operator (str) – name of class method in string form, returning operator matrix

  • param_name (str) – name of parameter to be varied

  • param_vals (ndarray) – parameter values to be plugged in

  • select_elems (Union[int, List[Tuple[int, int]]]) – either maximum index of desired matrix elements, or list [(i1, i2), (i3, i4), …] of index tuples for specific desired matrix elements (default value = 4)

  • mode (str) – idx_entry from MODE_FUNC_DICTIONARY, e.g., ‘abs’ for absolute value (default value = ‘abs’)

  • num_cpus (Optional[int]) – number of cores to be used for computation (default value: settings.NUM_CPUS)

  • **kwargs – standard plotting option (see separate documentation)

Return type

Tuple[Figure, Axes]

plot_matrixelements(operator, evecs=None, evals_count=6, mode='abs', show_numbers=False, show3d=True, **kwargs)

Plots matrix elements for operator, given as a string referring to a class method that returns an operator matrix. E.g., for instance trm of Transmon, the matrix element plot for the charge operator n is obtained by trm.plot_matrixelements(‘n’). When esys is set to None, the eigensystem with which eigenvectors is calculated.

Parameters
  • operator (str) – name of class method in string form, returning operator matrix

  • evecs (Optional[ndarray]) – eigensystem data of evals, evecs; eigensystem will be calculated if set to None (default value = None)

  • evals_count (int) – number of desired matrix elements, starting with ground state (default value = 6)

  • mode (str) – idx_entry from MODE_FUNC_DICTIONARY, e.g., ‘abs’ for absolute value (default)

  • show_numbers (bool) – determines whether matrix element values are printed on top of the plot (default: False)

  • show3d (bool) – whether to show a 3d skyscraper plot of the matrix alongside the 2d plot (default: True)

  • **kwargs – standard plotting option (see separate documentation)

Return type

Union[Tuple[Figure, Tuple[Axes, Axes]], Tuple[Figure, Axes]]

plot_wavefunction(which=0, mode='real', esys=None, phi_grid=None, scaling=None, **kwargs)[source]

Plot 1d phase-basis wave function(s). Must be overwritten by higher-dimensional qubits like FluxQubits and ZeroPi.

Parameters
  • which (Union[int, Iterable[int]]) – single index or tuple/list of integers indexing the wave function(s) to be plotted. If which is -1, all wavefunctions up to the truncation limit are plotted.

  • mode (str) – choices as specified in constants.MODE_FUNC_DICT (default value = ‘abs_sqr’)

  • esys (Optional[Tuple[ndarray, ndarray]]) – eigenvalues, eigenvectors

  • phi_grid (Optional[Grid1d]) – used for setting a custom grid for phi; if None use self._default_grid

  • scaling (Optional[float]) – custom scaling of wave function amplitude/modulus

  • **kwargs – standard plotting option (see separate documentation)

Return type

Tuple[Figure, Axes]

receive(event, sender, **kwargs)

Receive a message from CENTRAL_DISPATCH and initiate action on it.

Parameters
  • event (str) – event name from EVENTS

  • sender (DispatchClient) – original sender reporting the event

  • **kwargs

Return type

None

set_and_return(attr_name, value)

Allows to set an attribute after which self is returned. This is useful for doing something like example:

qubit.set_and_return('flux', 0.23).some_method()

instead of example:

qubit.flux=0.23
qubit.some_method()
Parameters
  • attr_name (str) – name of class attribute in string form

  • value (Any) – value that the attribute is to be set to

Return type

QubitBaseClass

Returns

self

set_params(**kwargs)

Set new parameters through the provided dictionary.

supported_noise_channels()

Returns a list of noise channels this QuantumSystem supports. If none, return an empty list.

Return type

List

wavefunction1d_defaults(mode, evals, wavefunc_count)[source]

Plot defaults for plotting.wavefunction1d.

Parameters
  • mode (str) – amplitude modifier, needed to give the correct default y label

  • evals (ndarray) – eigenvalues to include in plot

  • wavefunc_count (int) – number of wave functions to be plotted

Return type

Dict[str, Any]

widget(params=None)

Use ipywidgets to modify parameters of class instance

Descriptor classes

WatchedProperty

class scqubits.core.descriptors.WatchedProperty(event, inner_object_name=None, attr_name=None)[source]

Descriptor class for properties that are to be monitored for changes. Upon change of the value, the instance class invokes its broadcast() method to send the appropriate event notification to CentralDispatch

Parameters
  • event (str) – name of event to be triggered when property is changed

  • inner_object_name (Optional[str]) – Used, e.g., in FulLZeroPi where an inner-object property is to be set.

  • attr_name (Optional[str]) – custom attribute name to be used (default: name from defining property in instance class, obtained in __set_name__

ReadOnlyProperty

class scqubits.core.descriptors.ReadOnlyProperty[source]

Descriptor for read-only properties (stored in xxx._name)