CircuitRoutines#

class scqubits.core.circuit_routines.CircuitRoutines[source]#

Methods

CircuitRoutines.__init__()

CircuitRoutines.cutoffs_dict()

Returns a dictionary, where each variable is associated with its respective cutoff.

CircuitRoutines.default_params()

rtype:

Dict[str, Any]

CircuitRoutines.deserialize(io_data)

CircuitRoutines.discretized_grids_dict_for_vars()

CircuitRoutines.exp_i_operator(var_sym, ...)

Returns the bare operator exp(i* heta*prefactor), without the kron product.

CircuitRoutines.fetch_symbolic_hamiltonian()

Method to fetch the symbolic hamiltonian of an instance.

CircuitRoutines.generate_bare_eigensys()

CircuitRoutines.generate_hamiltonian_sym_for_numerics([...])

Generates a symbolic expression which is ready for numerical evaluation starting from the expression stored in the attribute hamiltonian_symbolic.

CircuitRoutines.generate_subsystems([...])

Generates the subsystems (child instances of Circuit) depending on the attribute self.system_hierarchy

CircuitRoutines.generate_sym_potential()

CircuitRoutines.generate_wf_plot_data([...])

Returns treated wave function of the current Circuit instance for the specified variables.

CircuitRoutines.get_cutoffs()

Method to get the cutoffs for each of the circuit's degree of freedom.

CircuitRoutines.get_eigenstates()

Returns the eigenstates for the SubSystem instance

CircuitRoutines.get_ext_basis()

Get the ext_basis object for the Circuit instance, according to the setting in self.hierarchical_diagonalization

CircuitRoutines.get_operator_by_name(...[, ...])

Returns the operator for the given operator symbol which has the same dimension as the hilbertdim of the instance from which the operator is requested.

CircuitRoutines.get_osc_param(var_index[, ...])

Returns the oscillator parameters based on the oscillator used to diagonalize the Hamiltonian in the harmonic oscillator basis.

CircuitRoutines.get_params()

Method to get the circuit parameters set for all the branches.

CircuitRoutines.get_subsystem_index(var_index)

Returns the subsystem index for the subsystem to which the given var_index belongs.

CircuitRoutines.hamiltonian()

Returns the Hamiltonian of the Circuit.

CircuitRoutines.hamiltonian_for_qutip_dynamics(...)

Returns the Hamiltonian in a format amenable to be forwarded to mesolve in Qutip.

CircuitRoutines.hilbertdim()

Returns the Hilbert dimension of the Circuit instance

CircuitRoutines.identity_wrap_for_hd(...[, ...])

Returns an identity wrapped operator whose size is equal to the self.hilbertdim().

CircuitRoutines.info()

Describes the Circuit instance, its parameters, and the symbolic Hamiltonian.

CircuitRoutines.is_subsystem(instance)

Returns true if the instance is a subsystem of self (regardless of the hierarchy)

CircuitRoutines.offset_charge_transformation()

Prints the variable transformation between offset charges of transformed variables and the node charges.

CircuitRoutines.offset_free_charge_values()

Returns all the offset charges set using the circuit attributes for each of the periodic degree of freedom.

CircuitRoutines.operator_names_in_hamiltonian_symbolic()

Returns a list of the names (strings) of all operators occurring in the symbolic Hamiltonian.

CircuitRoutines.plot_potential(**kwargs)

Returns the plot of the potential for the circuit instance.

CircuitRoutines.plot_wavefunction([which, ...])

Returns the plot of the wavefunction in the requested variables.

CircuitRoutines.potential_energy(**kwargs)

Returns the full potential of the circuit evaluated in a grid of points as chosen by the user or using default variable ranges.

CircuitRoutines.print_expr_in_latex(expr)

Print a sympy expression or a list of equalities in LaTeX

CircuitRoutines.receive(event, sender, **kwargs)

Method to help the CentralDispatch keep track of the sync status in Circuit and SubSystem modules

CircuitRoutines.return_parent_circuit()

Returns the parent Circuit instance.

CircuitRoutines.return_root_child(var_index)

CircuitRoutines.serialize()

rtype:

IOData

CircuitRoutines.set_and_return(attr_name, value)

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

CircuitRoutines.set_bare_eigensys(eigensys)

CircuitRoutines.set_discretized_phi_range(...)

Sets the flux range for discretized phi basis or for plotting

CircuitRoutines.set_operators()

Creates the operator methods <name>_operator for the circuit.

CircuitRoutines.sym_hamiltonian([...])

Prints a user readable symbolic Hamiltonian for the current instance

CircuitRoutines.sym_interaction(...[, ...])

Print the interaction between any set of subsystems for the current instance.

CircuitRoutines.sym_potential([float_round, ...])

Method prints a user readable symbolic potential for the current instance

CircuitRoutines.sync_parameters_with_parent()

Method syncs the parameters of the subsystem with the parent instance.

CircuitRoutines.update([calculate_bare_esys])

Syncs all the parameters of the subsystems with the current instance.

CircuitRoutines.update_interactions([recursive])

Update interactions of the HilbertSpace object for the Circuit instance if hierarchical_diagonalization is set to true.

cutoffs_dict()[source]#

Returns a dictionary, where each variable is associated with its respective cutoff.

Return type:

Dict[int, int]

Returns:

Cutoffs dictionary; {var_index: cutoff}

exp_i_operator(var_sym, prefactor)[source]#

Returns the bare operator exp(i* heta*prefactor), without the kron product. Needs the oscillator lengths to be set in the attribute, osc_lengths, when ext_basis is set to “harmonic”.

Return type:

Union[csc_matrix, ndarray]

Parameters:
  • var_sym (Symbol) –

  • prefactor (float) –

fetch_symbolic_hamiltonian()[source]#

Method to fetch the symbolic hamiltonian of an instance.

generate_hamiltonian_sym_for_numerics(hamiltonian=None, return_exprs=False)[source]#

Generates a symbolic expression which is ready for numerical evaluation starting from the expression stored in the attribute hamiltonian_symbolic. Stores the result in the attribute _hamiltonian_sym_for_numerics.

Parameters:

hamiltonian (Expr | None) –

generate_subsystems(only_update_subsystems=False)[source]#

Generates the subsystems (child instances of Circuit) depending on the attribute self.system_hierarchy

Parameters:

only_update_subsystems (bool) –

generate_wf_plot_data(which=0, mode='abs-sqr', var_indices=(1,), eigensys=None, change_discrete_charge_to_phi=True, grids_dict=None)[source]#

Returns treated wave function of the current Circuit instance for the specified variables.

Parameters:
  • which (int) – integer to choose which wave function to plot

  • mode (str) – “abs”, “real”, “imag”, “abs-sqr” - decides which part of the wave function is plotted.

  • var_indices (Tuple[int]) – A tuple containing the indices of the variables chosen to plot the wave function in. Should not have more than 2 entries.

  • eigensys (Optional[ndarray]) – eigenvalues and eigenstates of the Circuit instance; if not provided, calling this method will perform a diagonalization to obtain these.

  • extended_variable_basis (str) – The basis in which the extended variables are plotted. Can be either “phi” or “charge”.

  • periodic_variable_basis (str) – The basis in which the periodic variables are plotted. Can be either “phi” or “charge”.

  • grids_dict (Optional[Dict[int, Grid1d]]) – A dictionary which pairs var indices with the requested grids used to create the plot.

  • change_discrete_charge_to_phi (bool) –

get_cutoffs()[source]#

Method to get the cutoffs for each of the circuit’s degree of freedom.

Return type:

Dict[str, list]

get_eigenstates()[source]#

Returns the eigenstates for the SubSystem instance

Return type:

ndarray

get_ext_basis()[source]#

Get the ext_basis object for the Circuit instance, according to the setting in self.hierarchical_diagonalization

get_operator_by_name(operator_name, power=None, bare_esys=None)[source]#

Returns the operator for the given operator symbol which has the same dimension as the hilbertdim of the instance from which the operator is requested.

Parameters:
  • operator_name (str) – Name of a sympy Symbol object which should be one among the symbols in the attribute vars

  • power (Optional[int]) – If asking for an operator raised to a certain power. Which wen set to None defaults to 1

Return type:

Qobj

Returns:

operator identified by operator_name

get_osc_param(var_index, which_param='length')[source]#

Returns the oscillator parameters based on the oscillator used to diagonalize the Hamiltonian in the harmonic oscillator basis.

Parameters:
  • var_index (int) – var index whose oscillator parameter needs to be fetched

  • which_param (str) – “length” or “freq” - decides which parameter is returned, by default “length”

Return type:

float

Returns:

returns the float value which is the oscillator length or the frequency of the oscillator corresponding to var_index depending on the string which_param.

get_params()[source]#

Method to get the circuit parameters set for all the branches.

Return type:

List[float]

get_subsystem_index(var_index)[source]#

Returns the subsystem index for the subsystem to which the given var_index belongs.

Parameters:

var_index (int) – variable index in integer starting from 1.

Return type:

int

Returns:

subsystem index which can be used to identify the subsystem index in the list self.subsystems.

hamiltonian()[source]#

Returns the Hamiltonian of the Circuit.

Return type:

Union[csc_matrix, ndarray]

hamiltonian_for_qutip_dynamics(free_var_func_dict, prefactor=1.0, extra_terms=None)[source]#

Returns the Hamiltonian in a format amenable to be forwarded to mesolve in Qutip. Also returns the symbolic expressions of time independent and time dependent terms of the Hamiltonian. free_var_func_dict is a dictionary which has a tuple for every time dependent variable with the follwoing two elements: 1 - time dependent function for the variable 2 - the order to which the Hamiltonian needs to be expanded around the drive amplitude For example, to get the Hamiltonian for a circuit where Φ1 is the time varying parameter and the drive is expanded to second order, this method can be called in the following way:

``` :rtype: Tuple[List[Union[Qobj, Tuple[Qobj, Callable]]], Expr, List[Expr]]

def flux_t(t, args):

return np.sin(t*2)

def EJ_t(t, args):

return (1-np.exp(-t/1))*0.2

free_var_func_dict = {“Φ1”: (flux_t, 2), “EJ”:(EJ_t, 1)}

mesolve_input_H = self.hamiltonian_for_qutip_dynamics(free_var_func_dict) ` :type free_var_func_dict: :sphinx_autodoc_typehints_type:`\:py\:class\:\`\~typing.Dict\`\\ \\\[\:py\:class\:\`str\`\, \:py\:data\:\`\~typing.Callable\`\]` :param free_var_func_dict: Dict, as defined in the description above :type prefactor: :sphinx_autodoc_typehints_type:`\:py\:class\:\`float\ :param prefactor: float, value with which the Hamiltonian and corresponding operators are multiplied with :type extra_terms: Optional[str] :param extra_terms: str, a string which will be converted into sympy expression, containing terms which are not present in the Circuit Hamiltonian. Is useful to define custom drive operators.

Parameters:
  • free_var_func_dict (Dict[str, Callable]) –

  • prefactor (float) –

  • extra_terms (str | None) –

Return type:

Tuple[List[Qobj | Tuple[Qobj, Callable]], Expr, List[Expr]]

hilbertdim()[source]#

Returns the Hilbert dimension of the Circuit instance

identity_wrap_for_hd(operator, child_instance, bare_esys=None)[source]#

Returns an identity wrapped operator whose size is equal to the self.hilbertdim(). Only converts operator which belongs to a specific variable index. For example, operator Q_1 or cos( heta_1). But not, Q1*Q2.

Parameters:
  • operator (Union[csc_matrix, ndarray, None]) – operator in the form of csc_matrix, ndarray

  • instance – The subsystem to which the operator belongs

  • bare_esys (Dict[int, Tuple] | None) –

Return type:

Qobj

Returns:

identity wrapped operator.

info()[source]#

Describes the Circuit instance, its parameters, and the symbolic Hamiltonian.

is_subsystem(instance)[source]#

Returns true if the instance is a subsystem of self (regardless of the hierarchy)

offset_charge_transformation()[source]#

Prints the variable transformation between offset charges of transformed variables and the node charges.

Return type:

None

offset_free_charge_values()[source]#

Returns all the offset charges set using the circuit attributes for each of the periodic degree of freedom.

Return type:

List[float]

operator_names_in_hamiltonian_symbolic()[source]#

Returns a list of the names (strings) of all operators occurring in the symbolic Hamiltonian.

Return type:

List[str]

plot_potential(**kwargs)[source]#

Returns the plot of the potential for the circuit instance. Make sure to not set more than two variables in the instance.potential to a Numpy array, as the the code cannot plot with more than 3 dimensions.

Parameters:

θ<index> – value(s) for the variable \(\theta_i\) occurring in the potential.

Return type:

Tuple[Figure, Axes]

Returns:

Returns a axes and figure for further editing.

plot_wavefunction(which=0, mode='abs-sqr', var_indices=(1,), esys=None, change_discrete_charge_to_phi=True, zero_calibrate=True, grids_dict={}, **kwargs)[source]#

Returns the plot of the wavefunction in the requested variables. At most 2 numbers of variables for wavefunction can be specified as plotting axis. If the number of plotting variables for wave function is smaller than the number of variables in the circuit, the marginal probability distribution of the state with respect to the specified variables is plotted. This means the norm square of the wave function is integrated over the rest of the variables and is then plotted.

Parameters:
  • which – integer to choose which wave function to plot

  • mode (str) – “abs”, “real”, “imag”, “abs-sqr” - decides which part of the wave function is plotted, by default “abs-sqr”

  • var_indices (Tuple[int]) – A tuple containing the indices of the variables chosen to plot the wave function in. It should not have more than 2 entries.

  • esys (Optional[Tuple[ndarray, ndarray]]) – The object returned by the method .eigensys, is used to avoid the re-evaluation of the eigen systems if already evaluated.

  • change_discrete_charge_to_phi (bool) – If True, the wave function is plotted in the phi basis for the periodic variables. If False, the wave function is plotted in the charge basis for the periodic variables.

  • zero_calibrate (bool, optional) – if True, colors are adjusted to use zero wavefunction amplitude as the neutral color in the palette

  • grids_dict (Dict[int, Grid1d]) – A dictionary which pairs var indices with the grids used to create the plot. The way to specify the grids is as follows: 1. For extended variables, the grids should be of type discretization.Grid1d. 2. When the discretized phi basis is used for the extended variable, the grids used in the diagonalization is used to plot the wave function instead of the grids specified here. 3. For periodic variables, only if change_discrete_charge_to_phi is True, the grid specified here will used for plotting. The grid is specified as an integer which is the number of points in the grid. The grid has a minimum and maximum value of -pi and pi respectively. 4. If the grid is not specified for a variable that requires a grid for plotting (i.e. extended variable with harmonic oscillator basis, or periodic variable with change_discrete_charge_to_phi set to True), the default grid is used.

  • **kwargs – plotting parameters

Return type:

Tuple[Figure, Axes]

Returns:

Returns a axes and figure for further editing.

potential_energy(**kwargs)[source]#

Returns the full potential of the circuit evaluated in a grid of points as chosen by the user or using default variable ranges.

Parameters:

θ<index> – value(s) for variable :math:` heta_i` in the potential.

Return type:

ndarray

static print_expr_in_latex(expr)[source]#

Print a sympy expression or a list of equalities in LaTeX

Parameters:

expr (Union[Expr, List[Equality]]) – a sympy expressions or a list of equalities

Return type:

None

receive(event, sender, **kwargs)[source]#

Method to help the CentralDispatch keep track of the sync status in Circuit and SubSystem modules

Return type:

None

Parameters:
  • event (str) –

  • sender (object) –

return_parent_circuit()[source]#

Returns the parent Circuit instance.

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_discretized_phi_range(var_indices, phi_range)[source]#

Sets the flux range for discretized phi basis or for plotting

Parameters:
  • var_indices (Tuple[int]) – list of var_indices whose range needs to be changed

  • phi_range (Tuple[float]) – The desired range for each of the discretized phi variables

Return type:

None

set_operators()[source]#

Creates the operator methods <name>_operator for the circuit.

Return type:

Dict[str, Callable]

sym_hamiltonian(subsystem_index=None, float_round=6, print_latex=False, return_expr=False)[source]#

Prints a user readable symbolic Hamiltonian for the current instance

Parameters:
  • subsystem_index (Optional[int]) – when set to an index, the Hamiltonian for the corresponding subsystem is returned.

  • float_round (int) – Number of digits after the decimal to which floats are rounded

  • print_latex (bool) – if set to True, the expression is additionally printed as LaTeX code

  • return_expr (bool) – if set to True, all printing is suppressed and the function will silently return the sympy expression

Return type:

Optional[Expr]

sym_interaction(subsystem_indices, float_round=6, print_latex=False, return_expr=False)[source]#

Print the interaction between any set of subsystems for the current instance. It would print the interaction terms having operators from all the subsystems mentioned in the tuple.

Parameters:
  • subsystem_indices (Tuple[int]) – Tuple of subsystem indices

  • float_round (int) – Number of digits after the decimal to which floats are rounded

  • print_latex (bool) – if set to True, the expression is additionally printed as LaTeX code

  • return_expr (bool) – if set to True, all printing is suppressed and the function will silently return the sympy expression

Return type:

Optional[Expr]

sym_potential(float_round=6, print_latex=False, return_expr=False)[source]#

Method prints a user readable symbolic potential for the current instance

Parameters:
  • float_round (int) – Number of digits after the decimal to which floats are rounded

  • print_latex (bool) – if set to True, the expression is additionally printed as LaTeX code

  • return_expr (bool) – if set to True, all printing is suppressed and the function will silently return the sympy expression

Return type:

Optional[Expr]

sync_parameters_with_parent()[source]#

Method syncs the parameters of the subsystem with the parent instance.

update(calculate_bare_esys=True)[source]#

Syncs all the parameters of the subsystems with the current instance.

Parameters:

calculate_bare_esys (bool) –

update_interactions(recursive=False)[source]#

Update interactions of the HilbertSpace object for the Circuit instance if hierarchical_diagonalization is set to true.

Return type:

None