core physics package

colder.core.physics module

class colder.core.physics.hamiltonian(operator: str, targets: list, coeff: str, coeff_function: callable | None = None, target_coeffs: ndarray | None | int | float = None)[source]

Bases: object

__init__(operator: str, targets: list, coeff: str, coeff_function: callable | None = None, target_coeffs: ndarray | None | int | float = None) None[source]

Hamiltonian object.

Parameters:
  • operator (str) – String defining the Pauli operators to apply.

  • targets (list) – List of spin targets to apply the operators. The length of the tuples has to match the length of operator string.

  • coeff (str) – Coefficient symbol.

  • coeff_function (callable, optional) – Function to associate to coefficient. To use COLD simulation, this argument has to be provided. Defaults to None.

  • target_coeffs (Union[np.ndarray,None,int,float], optional) – Coefficients to associate to the target spins. Defaults to None.

Raises:

Exception – First argument of coeff_function, if provided, must be t (time dependence).

expression(sum_symbol: str = 'i', weight_symbol: str = 'w', operator_symbol: str = 'sigma_')[source]

Print a dummy expression for current hamiltonian.

Parameters:
  • sum_symbol (str, optional) – Symbol to use in the sum. Defaults to i.

  • weight_symbol (str, optional) – Placeholder letter for symbols. Defaults to w.

  • operator_symbol (str, optional) – Spin operator symbol. Defaults to sigma_.

get_strings(total_sites: int) dict[str, complex][source]

Returns full strings with coefficients from current hamiltonian.

Parameters:

total_sites (int) – Number of total spin sites.

Returns:

Dictionary of expressions and coefficients.

Return type:

dict[str, complex]

get_coeff() str[source]

Get the coefficient of this hamiltonian.

Returns:

Coefficient string.

Return type:

str

get_coeff_function_arguments(exception_if_none: bool = True) List[str][source]

Get the argument name for the coefficient function.

Parameters:

exception_if_none (bool, optional) – If True, raises an exception if there exist no function coefficient. Else, returns an empty list. Defaults to True.

Raises:

Exception – If exception_if_none, the exception is raised if no coefficient function is provided.

Returns:

List of arguments for the coefficient function.

Return type:

List[str]

make_coefficient_interpolation(trange: tuple, fargs: dict, n_interp_points: int = 50, **kwargs) interpolator1D[source]

Interpolates the coefficient function in time range trange.

Parameters:
  • trange (tuple) – Range of time to interpolate.

  • fargs (dict) – Arguments to be passed to the coefficient function.

  • n_interp_points (int, optional) – Number of points to interpolate. Defaults to 50.

Raises:

Exception – Coefficient function must be provided to use this feature.

Returns:

Numerical spline interpolator for coefficient function.

Return type:

cnum.interpolator1D

class colder.core.physics.hamiltonian_collection(*args)[source]

Bases: object

This class creates collection of hamiltonian object that have to be summed.

Example


import colder.core.physics as cphys

H_Z = cphys.hamiltonian(‘Z’, [(0,) , (1,)], coeff = ‘Z’) H_X = cphys.hamiltonian(‘X’, [(0,) , (1,)], coeff = ‘X’)

H = H_Z + H_X # this is a collection (type: cphys.hamiltonian_collection)

__init__(*args)[source]

Creates an hamiltonian collection “summing” instances of hamiltonians.

get_coeffs() List[str][source]
get_unique_coeffs() List[str][source]
get_strings(total_sites: int) List[dict[str, complex]][source]
expression(group_coefficients: bool = True)[source]

Print a dummy expression for current hamiltonian.

Parameters:

group_coefficients (bool, optional) – If True, coefficients are grouped, if needed. Defaults to True.

make_symbolic_expression(total_sites: int)[source]

Returns the symbolic expression for this hamiltonian collection.

Parameters:

total_sites (int) – Total number of spin sites.

make_coefficients_interpolation(trange: tuple, fargs: dict, make_unique: bool = True, **kwargs) dict[str, interpolator1D][source]

Interpolates the coefficient function in time range trange for each unique coefficient of hamiltonian collection.

Parameters:
  • trange (tuple) – Range of time to interpolate.

  • fargs (dict) – Arguments to be passed to the coefficient function.

  • make_unique (bool, optional) – If True, uses unique coefficients to avoid multiple computation of the same interpolation. Defaults to True.

Returns:

Dictionary of interpolated functions.

Return type:

dict[str, cnum.interpolator1D]

class colder.core.physics.empty_hamiltonian[source]

Bases: object

Empty hamiltonian class. The purpuse of this dummy class is to provide a custom empty object to be summed with hamiltonians.

Example

import colder.core.physics as cphys

H = cphys.empty_hamiltonian()

# just a terrible example:
for i in range(3):
    H += cphys.hamiltonian('XX', [(i,i+1)], coeff = 'J', coeff_function=Jf, target_coeffs= 1/(i+1) )