Libraries package

Libraries contain a collection of functions that all share a signature to be used interchangably. One entry of a library is selected in the corresponding config file.

Algorithms module

Collection of (optimization) algorithms. All entries share a common signature with optional arguments.

c3.libraries.algorithms.adaptive_scan(x_init, fun=None, fun_grad=None, grad_lookup=None, options={})[source]

One dimensional scan of the function values around the initial point, using adaptive sampling

Parameters
  • x_init (float) – Initial point

  • fun (callable) – Goal function

  • fun_grad (callable) – Function that computes the gradient of the goal function

  • grad_lookup (callable) – Lookup a previously computed gradient

  • options (dict) –

    Options include

    accuracy_goal: float

    Targeted accuracy for the sampling algorithm

    probe_listlist

    Points to definitely include in the sampling

    init_pointboolean

    Include the initial point in the sampling

c3.libraries.algorithms.algo_reg_deco(func)[source]

Decorator for making registry of functions

c3.libraries.algorithms.cma_pre_lbfgs(x_init, fun=None, fun_grad=None, grad_lookup=None, options={})[source]

Performs a CMA-Es optimization and feeds the result into LBFG-S for further refinement.

c3.libraries.algorithms.cmaes(x_init, fun=None, fun_grad=None, grad_lookup=None, options={})[source]

Wrapper for the pycma implementation of CMA-Es. See also:

http://cma.gforge.inria.fr/apidocs-pycma/

Parameters
  • x_init (float) – Initial point.

  • fun (callable) – Goal function.

  • fun_grad (callable) – Function that computes the gradient of the goal function.

  • grad_lookup (callable) – Lookup a previously computed gradient.

  • options (dict) –

    Options of pycma and the following custom options.

    noisefloat

    Artificial noise added to a function evaluation.

    init_pointboolean

    Force the use of the initial point in the first generation.

    spreadfloat

    Adjust the parameter spread of the first generation cloud.

    stop_at_convergenceint

    Custom stopping condition. Stop if the cloud shrunk for this number of generations.

    stop_at_sigmafloat

    Custom stopping condition. Stop if the cloud shrunk to this standard deviation.

Returns

Parameters of the best point.

Return type

np.ndarray

c3.libraries.algorithms.gcmaes(x_init, fun=None, fun_grad=None, grad_lookup=None, options={})[source]

EXPERIMENTAL CMA-Es where every point in the cloud is optimized with LBFG-S and the resulting cloud and results are used for the CMA update.

c3.libraries.algorithms.grid2D(x_init, fun=None, fun_grad=None, grad_lookup=None, options={})[source]

Two dimensional scan of the function values around the initial point.

Parameters
  • x_init (float) – Initial point

  • fun (callable) – Goal function

  • fun_grad (callable) – Function that computes the gradient of the goal function

  • grad_lookup (callable) – Lookup a previously computed gradient

  • options (dict) –

    Options include points : int

    The number of samples

    boundslist

    Range of the scan for both dimensions

c3.libraries.algorithms.lbfgs(x_init, fun=None, fun_grad=None, grad_lookup=None, options={})[source]

Wrapper for the scipy.optimize.minimize implementation of LBFG-S. See also:

https://docs.scipy.org/doc/scipy/reference/optimize.minimize-lbfgsb.html

Parameters
  • x_init (float) – Initial point

  • fun (callable) – Goal function

  • fun_grad (callable) – Function that computes the gradient of the goal function

  • grad_lookup (callable) – Lookup a previously computed gradient

  • options (dict) – Options of scipy.optimize.minimize

Returns

Scipy result object.

Return type

Result

c3.libraries.algorithms.lbfgs_grad_free(x_init, fun=None, fun_grad=None, grad_lookup=None, options={})[source]

Wrapper for the scipy.optimize.minimize implementation of LBFG-S. We let the algorithm determine the gradient by its own.

See also:

https://docs.scipy.org/doc/scipy/reference/optimize.minimize-lbfgsb.html

Parameters
  • x_init (float) – Initial point

  • fun (callable) – Goal function

  • fun_grad (callable) – Function that computes the gradient of the goal function

  • grad_lookup (callable) – Lookup a previously computed gradient

  • options (dict) – Options of scipy.optimize.minimize

Returns

Scipy result object.

Return type

Result

c3.libraries.algorithms.oneplusone(x_init, goal_fun)[source]
c3.libraries.algorithms.single_eval(x_init, fun=None, fun_grad=None, grad_lookup=None, options={})[source]

Return the function value at given point.

Parameters
  • x_init (float) – Initial point

  • fun (callable) – Goal function

  • fun_grad (callable) – Function that computes the gradient of the goal function

  • grad_lookup (callable) – Lookup a previously computed gradient

  • options (dict) – Algorithm specific options

c3.libraries.algorithms.sweep(x_init, fun=None, fun_grad=None, grad_lookup=None, options={})[source]

One dimensional scan of the function values around the initial point.

Parameters
  • x_init (float) – Initial point

  • fun (callable) – Goal function

  • fun_grad (callable) – Function that computes the gradient of the goal function

  • grad_lookup (callable) – Lookup a previously computed gradient

  • options (dict) –

    Options include points : int

    The number of samples

    boundslist

    Range of the scan

c3.libraries.algorithms.tf_adadelta(x_init: ndarray, fun: Optional[Callable] = None, fun_grad: Optional[Callable] = None, grad_lookup: Optional[Callable] = None, options: dict = {}) OptimizeResult[source]

Optimize using TensorFlow Adadelta https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/Adadelta

Parameters
  • x_init (np.ndarray) – starting value of parameter(s)

  • fun (Callable, optional) – function to minimize, by default None

  • fun_grad (Callable, optional) – gradient of function to minimize, by default None

  • grad_lookup (Callable, optional) – lookup stored gradients, by default None

  • options (dict, optional) – optional parameters for optimizer, by default {}

Returns

SciPy OptimizeResult type object with final parameters

Return type

OptimizeResult

c3.libraries.algorithms.tf_adam(x_init: ndarray, fun: Optional[Callable] = None, fun_grad: Optional[Callable] = None, grad_lookup: Optional[Callable] = None, options: dict = {}) OptimizeResult[source]

Optimize using TensorFlow ADAM https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/Adam

Parameters
  • x_init (np.ndarray) – starting value of parameter(s)

  • fun (Callable, optional) – function to minimize, by default None

  • fun_grad (Callable, optional) – gradient of function to minimize, by default None

  • grad_lookup (Callable, optional) – lookup stored gradients, by default None

  • options (dict, optional) – optional parameters for optimizer, by default {}

Returns

SciPy OptimizeResult type object with final parameters

Return type

OptimizeResult

c3.libraries.algorithms.tf_rmsprop(x_init: ndarray, fun: Optional[Callable] = None, fun_grad: Optional[Callable] = None, grad_lookup: Optional[Callable] = None, options: dict = {}) OptimizeResult[source]

Optimize using TensorFlow RMSProp https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/RMSprop

Parameters
  • x_init (np.ndarray) – starting value of parameter(s)

  • fun (Callable, optional) – function to minimize, by default None

  • fun_grad (Callable, optional) – gradient of function to minimize, by default None

  • grad_lookup (Callable, optional) – lookup stored gradients, by default None

  • options (dict, optional) – optional parameters for optimizer, by default {}

Returns

SciPy OptimizeResult type object with final parameters

Return type

OptimizeResult

c3.libraries.algorithms.tf_sgd(x_init: ndarray, fun: Optional[Callable] = None, fun_grad: Optional[Callable] = None, grad_lookup: Optional[Callable] = None, options: dict = {}) OptimizeResult[source]

Optimize using TensorFlow Stochastic Gradient Descent with Momentum https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/SGD

Parameters
  • x_init (np.ndarray) – starting value of parameter(s)

  • fun (Callable, optional) – function to minimize, by default None

  • fun_grad (Callable, optional) – gradient of function to minimize, by default None

  • grad_lookup (Callable, optional) – lookup stored gradients, by default None

  • options (dict, optional) – optional parameters for optimizer, by default {}

Returns

SciPy OptimizeResult type object with final parameters

Return type

OptimizeResult

Chip module

Component class and subclasses for the components making up the quantum device.

class c3.libraries.chip.CShuntFluxQubit(name: str, desc: Optional[str] = None, comment: Optional[str] = None, hilbert_dim: Optional[int] = None, calc_dim: Optional[int] = None, EC: Optional[Quantity] = None, EJ: Optional[Quantity] = None, EL: Optional[Quantity] = None, phi: Optional[Quantity] = None, phi_0: Optional[Quantity] = None, gamma: Optional[Quantity] = None, d: Optional[Quantity] = None, t1: Optional[Quantity] = None, t2star: Optional[Quantity] = None, temp: Optional[Quantity] = None, anhar: Optional[Quantity] = None, params={}, resolution=None)[source]

Bases: Qubit

get_Hamiltonian(signal: Optional[Union[dict, bool]] = None, transform: Optional[Tensor] = None) Tensor[source]

Calculate the hamiltonian :returns: Hamiltonian :rtype: tf.Tensor

get_anharmonicity(phi_sig=0)[source]
get_freq(phi_sig=0)
get_frequency(phi_sig=0)[source]
get_minimum_phi_var(init_phi_variable: tf.float64 = 0, phi_sig=0)[source]
get_potential_function(phi_variable, deriv_order=1, phi_sig=0)[source]
get_third_order_prefactor(phi_sig=0)[source]
init_Hs(ann_oper)[source]

initialize Hamiltonians for cubic hamiltinian :param ann_oper: Annihilation operator in the full Hilbert space :type ann_oper: np.array

class c3.libraries.chip.CShuntFluxQubitCos(name: str, desc: Optional[str] = None, comment: Optional[str] = None, hilbert_dim: Optional[int] = None, calc_dim: Optional[int] = None, EC: Optional[Quantity] = None, EJ: Optional[Quantity] = None, EL: Optional[Quantity] = None, phi: Optional[Quantity] = None, phi_0: Optional[Quantity] = None, gamma: Optional[Quantity] = None, d: Optional[Quantity] = None, t1: Optional[Quantity] = None, t2star: Optional[Quantity] = None, temp: Optional[Quantity] = None, anhar: Optional[Quantity] = None, params=None)[source]

Bases: Qubit

cosm(var, a=1, b=0)[source]
get_Hamiltonian(signal: Optional[Union[dict, bool]] = None, transform: Optional[Tensor] = None)[source]

Compute the Hamiltonian. Multiplies the number operator with the frequency and anharmonicity with the Duffing part and returns their sum.

Returns

Hamiltonian

Return type

tf.Tensor

get_freq()[source]
get_n_variable()[source]
get_phase_variable()[source]
init_Hs(ann_oper)[source]

Initialize the qubit Hamiltonians. If the dimension is higher than two, a Duffing oscillator is used.

Parameters

ann_oper (np.array) – Annihilation operator in the full Hilbert space

init_exponentiated_vars(ann_oper)[source]
class c3.libraries.chip.Coupling(name, desc=None, comment=None, strength: Optional[Quantity] = None, connected: Optional[List[str]] = None, params=None, hamiltonian_func=None)[source]

Bases: LineComponent

Represents a coupling behaviour between elements.

Parameters
  • strength (Quantity) – coupling strength

  • connected (list) – all physical components coupled via this specific coupling

get_Hamiltonian(signal: Optional[Union[dict, bool]] = None, transform: Optional[Tensor] = None)[source]
init_Hs(opers_list)[source]
class c3.libraries.chip.Coupling_Drive(**props)[source]

Bases: Drive

Represents a drive line that couples multiple qubits.

Parameters

connected (list) – all physical components receiving driving signals via this line

init_Hs(ann_opers: list)[source]
class c3.libraries.chip.Drive(**props)[source]

Bases: LineComponent

Represents a drive line.

Parameters

connected (list) – all physical components receiving driving signals via this line

get_Hamiltonian(signal: Optional[Union[Dict, bool]] = None, transform: Optional[Tensor] = None) Tensor[source]
init_Hs(ann_opers: list)[source]
class c3.libraries.chip.Fluxonium(name: str, desc: Optional[str] = None, comment: Optional[str] = None, hilbert_dim: Optional[int] = None, calc_dim: Optional[int] = None, EC: Optional[Quantity] = None, EJ: Optional[Quantity] = None, EL: Optional[Quantity] = None, phi: Optional[Quantity] = None, phi_0: Optional[Quantity] = None, gamma: Optional[Quantity] = None, t1: Optional[Quantity] = None, t2star: Optional[Quantity] = None, temp: Optional[Quantity] = None, params=None)[source]

Bases: CShuntFluxQubit

get_potential_function(phi_variable, deriv_order=1, phi_sig=0) tf.float64[source]
class c3.libraries.chip.LineComponent(**props)[source]

Bases: C3obj

Represents the components connecting chip elements and drives.

Parameters

connected (list) – specifies the component that are connected with this line

asdict() dict[source]
class c3.libraries.chip.PhysicalComponent(**props)[source]

Bases: C3obj

Represents the components making up a chip.

Parameters

hilbert_dim (int) – Dimension of the Hilbert space of this component

asdict() dict[source]
get_Hamiltonian(signal: Optional[Union[dict, bool]] = None, transform: Optional[Tensor] = None) Dict[str, Tensor][source]

Compute the Hamiltonian. :param signal: dictionary with signals to be used a time dependend Hamiltonian. By default “values” key will be used.

If true value control hamiltonian will be returned, used for later combination of signal and hamiltonians.

Parameters

transform – transform the hamiltonian, e.g. for expressing the hamiltonian in the expressed basis. Use this function if transform will be necessary and signal is given, in order to apply the transform only on single hamiltonians instead of all timeslices.

get_transformed_hamiltonians(transform: Optional[Tensor] = None)[source]

get transformed hamiltonians with given applied transformation. The Hamiltonians are assumed to be stored in Hs. :param transform: transform to be applied to the hamiltonians. Default: None for returning the hamiltonians without transformation applied.

set_subspace_index(index)[source]
class c3.libraries.chip.Qubit(name, hilbert_dim, desc=None, comment=None, freq: Optional[Quantity] = None, anhar: Optional[Quantity] = None, t1: Optional[Quantity] = None, t2star: Optional[Quantity] = None, temp: Optional[Quantity] = None, params=None)[source]

Bases: PhysicalComponent

Represents the element in a chip functioning as qubit.

Parameters
  • freq (Quantity) – frequency of the qubit

  • anhar (Quantity) – anharmonicity of the qubit. defined as w01 - w12

  • t1 (Quantity) – t1, the time decay of the qubit due to dissipation

  • t2star (Quantity) – t2star, the time decay of the qubit due to pure dephasing

  • temp (Quantity) – temperature of the qubit, used to determine the Boltzmann distribution of energy level populations

get_Hamiltonian(signal: Optional[Union[dict, bool]] = None, transform: Optional[Tensor] = None)[source]

Compute the Hamiltonian. Multiplies the number operator with the frequency and anharmonicity with the Duffing part and returns their sum.

Returns

Hamiltonian

Return type

tf.Tensor

get_Lindbladian(dims)[source]

Compute the Lindbladian, based on relaxation, dephasing constants and finite temperature.

Returns

Hamiltonian

Return type

tf.Tensor

init_Hs(ann_oper)[source]

Initialize the qubit Hamiltonians. If the dimension is higher than two, a Duffing oscillator is used.

Parameters

ann_oper (np.array) – Annihilation operator in the full Hilbert space

init_Ls(ann_oper)[source]

Initialize Lindbladian components.

Parameters

ann_oper (np.array) – Annihilation operator in the full Hilbert space

class c3.libraries.chip.Resonator(**props)[source]

Bases: PhysicalComponent

Represents the element in a chip functioning as resonator.

Parameters

freq (Quantity) – frequency of the resonator

get_Hamiltonian(signal: Optional[Union[dict, bool]] = None, transform: Optional[Tensor] = None)[source]

Compute the Hamiltonian.

get_Lindbladian(dims)[source]

NOT IMPLEMENTED

init_Hs(ann_oper)[source]

Initialize the Hamiltonian as a number operator

Parameters

ann_oper (np.array) – Annihilation operator in the full Hilbert space.

init_Ls(ann_oper)[source]

NOT IMPLEMENTED

class c3.libraries.chip.SNAIL(name: str, desc: str = ' ', comment: str = ' ', hilbert_dim: int = 4, freq: Optional[Quantity] = None, anhar: Optional[Quantity] = None, beta: Optional[Quantity] = None, t1: Optional[Quantity] = None, t2star: Optional[Quantity] = None, temp: Optional[Quantity] = None, params: Optional[dict] = None)[source]

Bases: Qubit

Represents the element in a chip functioning as a three wave mixing element also knwon as a SNAIL. Reference: https://arxiv.org/pdf/1702.00869.pdf :param freq: frequency of the qubit :type freq: Quantity :param anhar: anharmonicity of the qubit. defined as w01 - w12 :type anhar: Quantity :param beta: third order non_linearity of the qubit. :type beta: Quantity :param t1: t1, the time decay of the qubit due to dissipation :type t1: Quantity :param t2star: t2star, the time decay of the qubit due to pure dephasing :type t2star: Quantity :param temp: temperature of the qubit, used to determine the Boltzmann distribution

of energy level populations

Parameters
  • beta. (Class is mostly an exact copy of the Qubit class. The only difference is the added third order non linearity with a prefactor) –

  • linearity (The only modification is the get hamiltonian and init hamiltonian definition. Also imported the necessary third order non) –

  • library. (from the hamiltonian) –

get_Hamiltonian(signal: Optional[Union[dict, bool]] = None, transform: Optional[Tensor] = None)[source]

Compute the Hamiltonian. Multiplies the number operator with the frequency and anharmonicity with the Duffing part and returns their sum. :returns: Hamiltonian :rtype: tf.Tensor

init_Hs(ann_oper)[source]

Initialize the SNAIL Hamiltonians. :param ann_oper: Annihilation operator in the full Hilbert space :type ann_oper: np.array

class c3.libraries.chip.Transmon(name: str, desc: Optional[str] = None, comment: Optional[str] = None, hilbert_dim: Optional[int] = None, freq: Optional[Quantity] = None, anhar: Optional[Quantity] = None, phi: Optional[Quantity] = None, phi_0: Optional[Quantity] = None, gamma: Optional[Quantity] = None, d: Optional[Quantity] = None, t1: Optional[Quantity] = None, t2star: Optional[Quantity] = None, temp: Optional[Quantity] = None, params=None)[source]

Bases: PhysicalComponent

Represents the element in a chip functioning as tunanble transmon qubit.

Parameters
  • freq (Quantity) – base frequency of the Transmon

  • phi_0 (Quantity) – half period of the phase dependant function

  • phi (Quantity) – flux position

get_Hamiltonian(signal: Optional[Union[dict, bool]] = None, transform: Optional[Tensor] = None)[source]

Compute the Hamiltonian. :param signal: dictionary with signals to be used a time dependend Hamiltonian. By default “values” key will be used.

If true value control hamiltonian will be returned, used for later combination of signal and hamiltonians.

Parameters

transform – transform the hamiltonian, e.g. for expressing the hamiltonian in the expressed basis. Use this function if transform will be necessary and signal is given, in order to apply the transform only on single hamiltonians instead of all timeslices.

get_Lindbladian(dims)[source]

Compute the Lindbladian, based on relaxation, dephasing constants and finite temperature.

Returns

Hamiltonian

Return type

tf.Tensor

get_anhar()[source]
get_factor(phi_sig=0)[source]
get_freq(phi_sig=0)[source]
init_Hs(ann_oper)[source]
init_Ls(ann_oper)[source]

Initialize Lindbladian components.

Parameters

ann_oper (np.array) – Annihilation operator in the full Hilbert space

class c3.libraries.chip.TransmonExpanded(name: str, desc: Optional[str] = None, comment: Optional[str] = None, hilbert_dim: Optional[int] = None, freq: Optional[Quantity] = None, anhar: Optional[Quantity] = None, phi: Optional[Quantity] = None, phi_0: Optional[Quantity] = None, gamma: Optional[Quantity] = None, d: Optional[Quantity] = None, t1: Optional[Quantity] = None, t2star: Optional[Quantity] = None, temp: Optional[Quantity] = None, params=None)[source]

Bases: Transmon

energies_from_frequencies()[source]
get_Hamiltonian(signal: Optional[Union[dict, bool]] = None, transform: Optional[Tensor] = None)[source]

Compute the Hamiltonian. :param signal: dictionary with signals to be used a time dependend Hamiltonian. By default “values” key will be used.

If true value control hamiltonian will be returned, used for later combination of signal and hamiltonians.

Parameters

transform – transform the hamiltonian, e.g. for expressing the hamiltonian in the expressed basis. Use this function if transform will be necessary and signal is given, in order to apply the transform only on single hamiltonians instead of all timeslices.

get_Hs(ann_oper)[source]
get_prefactors(sig)[source]
init_Hs(ann_oper)[source]
c3.libraries.chip.dev_reg_deco(func)[source]

Decorator for making registry of functions

Constants module

All physical constants used in other code.

Envelopes module

Library of envelope functions.

All functions assume the input of a time vector and return complex amplitudes.

c3.libraries.envelopes.cosine(t, params)[source]

Cosine-shaped envelope. Maximum value is 1, area is given by length.

Parameters

params (dict) –

t_finalfloat

Total length of the Gaussian.

sigma: float

Width of the Gaussian.

c3.libraries.envelopes.cosine_flattop(t, params)[source]

Cosine-shaped envelope. Maximum value is 1, area is given by length.

Parameters

params (dict) –

t_finalfloat

Total length of the Gaussian.

sigma: float

Width of the Gaussian.

c3.libraries.envelopes.delta_pulse(t, params)[source]

Pulse shape which gives an output only at a given time bin

c3.libraries.envelopes.drag_der(t, params)[source]

Derivative of second order gaussian.

c3.libraries.envelopes.drag_sigma(t, params)[source]

Second order gaussian.

c3.libraries.envelopes.env_reg_deco(func)[source]

Decorator for making registry of functions

c3.libraries.envelopes.flattop(t, params)[source]

Flattop gaussian with width of length risefall, modelled by error functions.

Parameters

params (dict) –

t_upfloat

Center of the ramp up.

t_downfloat

Center of the ramp down.

risefallfloat

Length of the ramps.

c3.libraries.envelopes.flattop_cut(t, params)[source]

Flattop gaussian with width of length risefall, modelled by error functions.

Parameters

params (dict) –

t_upfloat

Center of the ramp up.

t_downfloat

Center of the ramp down.

risefallfloat

Length of the ramps.

c3.libraries.envelopes.flattop_cut_center(t, params)[source]

Flattop gaussian with width of length risefall, modelled by error functions.

Parameters

params (dict) –

t_upfloat

Center of the ramp up.

t_downfloat

Center of the ramp down.

risefallfloat

Length of the ramps.

c3.libraries.envelopes.flattop_risefall(t, params)[source]

Flattop gaussian with width of length risefall, modelled by error functions.

Parameters

params (dict) –

t_finalfloat

Total length of pulse.

risefallfloat

Length of the ramps. Position of ramps is so that the pulse starts with the start of the ramp-up and ends at the end of the ramp-down

c3.libraries.envelopes.flattop_risefall_1ns(t, params)[source]

Flattop gaussian with fixed width of 1ns.

c3.libraries.envelopes.flattop_variant(t, params)[source]

Flattop variant.

c3.libraries.envelopes.fourier_cos(t, params)[source]

Fourier basis of the pulse constant pulse (cos).

Parameters

params (dict) –

ampslist

Weights of the fourier components

freqslist

Frequencies of the fourier components

c3.libraries.envelopes.fourier_sin(t, params)[source]

Fourier basis of the pulse constant pulse (sin).

Parameters

params (dict) –

ampslist

Weights of the fourier components

freqslist

Frequencies of the fourier components

c3.libraries.envelopes.gaussian_der(t, params)[source]

Derivative of the normalized gaussian (ifself not normalized).

c3.libraries.envelopes.gaussian_der_nonorm(t, params)[source]

Derivative of the normalized gaussian (ifself not normalized).

c3.libraries.envelopes.gaussian_nonorm(t, params)[source]

Non-normalized gaussian. Maximum value is 1, area is given by length.

Parameters

params (dict) –

t_finalfloat

Total length of the Gaussian.

sigma: float

Width of the Gaussian.

c3.libraries.envelopes.gaussian_sigma(t, params)[source]

Normalized gaussian. Total area is 1, maximum is determined accordingly.

Parameters

params (dict) –

t_finalfloat

Total length of the Gaussian.

sigma: float

Width of the Gaussian.

c3.libraries.envelopes.no_drive(t, params=None)[source]

Do nothing.

c3.libraries.envelopes.pwc(t, params)[source]

Piecewise constant pulse.

c3.libraries.envelopes.pwc_shape(t, params)[source]

Piecewise constant pulse while defining only a given number of samples, while interpolating linearly between those. :param t: :param params: t_bin_start/t_bin_end can be used to specify specific range. e.g. timepoints taken from awg.

c3.libraries.envelopes.pwc_shape_plateau(t, params)[source]
c3.libraries.envelopes.pwc_symmetric(t, params)[source]

symmetic PWC pulse This works only for inphase component

c3.libraries.envelopes.rect(t, params=None)[source]

Rectangular pulse. Returns 1 at every time step.

c3.libraries.envelopes.slepian_fourier(t, params)[source]
c3.libraries.envelopes.trapezoid(t, params)[source]

Trapezoidal pulse. Width of linear slope.

Parameters

params (dict) –

t_finalfloat

Total length of pulse.

risefallfloat

Length of the slope

Estimators module

Collection of estimator functions, to compare two sets of (noisy) data.

c3.libraries.estimators.dv_g_LL_prime(gs, dv_gs, weights)[source]
c3.libraries.estimators.estimator_reg_deco(func)[source]

Decorator for making registry of functions

c3.libraries.estimators.g_LL_prime(exp_values, sim_values, exp_stds, shots)[source]
c3.libraries.estimators.g_LL_prime_combined(gs, weights)[source]
c3.libraries.estimators.mean_dist(exp_values, sim_values, exp_stds, shots)[source]

Return the root mean squared of the differences.

c3.libraries.estimators.mean_exp_stds_dist(exp_values, sim_values, exp_stds, shots)[source]

Return the mean of the distance in number of exp_stds away.

c3.libraries.estimators.mean_sim_stds_dist(exp_values, sim_values, exp_stds, shots)[source]

Return the mean of the distance in number of exp_stds away.

c3.libraries.estimators.median_dist(exp_values, sim_values, exp_stds, shots)[source]

Return the median of the differences.

c3.libraries.estimators.neg_loglkh_binom(exp_values, sim_values, exp_stds, shots)[source]

Average likelihood of the experimental values with binomial distribution.

Return the likelihood of the experimental values given the simulated values, and given a binomial distribution function.

c3.libraries.estimators.neg_loglkh_binom_norm(exp_values, sim_values, exp_stds, shots)[source]

Average likelihood of the exp values with normalised binomial distribution.

Return the likelihood of the experimental values given the simulated values, and given a binomial distribution function that is normalised to give probability 1 at the top of the distribution.

c3.libraries.estimators.neg_loglkh_gauss(exp_values, sim_values, exp_stds, shots)[source]

Likelihood of the experimental values.

The distribution is assumed to be binomial (approximated by a gaussian).

c3.libraries.estimators.neg_loglkh_gauss_norm(exp_values, sim_values, exp_stds, shots)[source]

Likelihood of the experimental values.

The distribution is assumed to be binomial (approximated by a gaussian) that is normalised to give probability 1 at the top of the distribution.

c3.libraries.estimators.neg_loglkh_gauss_norm_sum(exp_values, sim_values, exp_stds, shots)[source]

Likelihood of the experimental values.

The distribution is assumed to be binomial (approximated by a gaussian) that is normalised to give probability 1 at the top of the distribution.

c3.libraries.estimators.neg_loglkh_multinom(exp_values, sim_values, exp_stds, shots)[source]

Average likelihood of the experimental values with multinomial distribution.

Return the likelihood of the experimental values given the simulated values, and given a multinomial distribution function.

c3.libraries.estimators.neg_loglkh_multinom_norm(exp_values, sim_values, exp_stds, shots)[source]

Average likelihood of the experimental values with multinomial distribution.

Return the likelihood of the experimental values given the simulated values, and given a multinomial distribution function that is normalised to give probability 1 at the top of the distribution.

c3.libraries.estimators.rms_dist(exp_values, sim_values, exp_stds, shots)[source]

Return the root mean squared of the differences.

c3.libraries.estimators.rms_exp_stds_dist(exp_values, sim_values, exp_stds, shots)[source]

Return the root mean squared of the differences measured in exp_stds.

c3.libraries.estimators.rms_sim_stds_dist(exp_values, sim_values, exp_stds, shots)[source]

Return the root mean squared of the differences measured in exp_stds.

c3.libraries.estimators.std_of_diffs(exp_values, sim_values, exp_stds, shots)[source]

Return the std of the distances.

Fidelities module

Library of fidelity functions.

c3.libraries.fidelities.RB(propagators, min_length: int = 5, max_length: int = 500, num_lengths: int = 20, num_seqs: int = 30, logspace=False, lindbladian=False, padding='')[source]
c3.libraries.fidelities.average_infid(ideal: ndarray, actual: Tensor, index: List[int] = [0], dims=[2]) constant[source]

Average fidelity uses the Pauli basis to compare. Thus, perfect gates are always 2x2 (per qubit) and the actual unitary needs to be projected down.

Parameters
  • ideal (np.ndarray) – Contains ideal unitary representations of the gate

  • actual (tf.Tensor) – Contains actual unitary representations of the gate

  • index (List[int]) – Index of the qubit(s) in the Hilbert space to be evaluated

  • dims (list) – List of dimensions of qubits

c3.libraries.fidelities.average_infid_seq(propagators: dict, instructions: dict, index, dims, n_eval=-1)[source]

Average sequence fidelity over all gates in propagators.

Parameters
  • propagators (dict) – Contains unitary representations of the gates, identified by a key.

  • index (int) – Index of the qubit(s) in the Hilbert space to be evaluated

  • dims (list) – List of dimensions of qubits

  • proj (boolean) – Project to computational subspace

Returns

Mean average fidelity

Return type

tf.float64

c3.libraries.fidelities.average_infid_set(propagators: dict, instructions: dict, index: List[int], dims, n_eval=-1)[source]

Mean average fidelity over all gates in propagators.

Parameters
  • propagators (dict) – Contains unitary representations of the gates, identified by a key.

  • index (int) – Index of the qubit(s) in the Hilbert space to be evaluated

  • dims (list) – List of dimensions of qubits

  • proj (boolean) – Project to computational subspace

Returns

Mean average fidelity

Return type

tf.float64

c3.libraries.fidelities.calculate_state_overlap(psi1, psi2)[source]
c3.libraries.fidelities.epc_analytical(propagators: dict, index, dims, proj: bool, cliffords=False)[source]
c3.libraries.fidelities.fid_reg_deco(func)[source]

Decorator for making registry of functions

c3.libraries.fidelities.leakage_RB(propagators, min_length: int = 5, max_length: int = 500, num_lengths: int = 20, num_seqs: int = 30, logspace=False, lindbladian=False)[source]
c3.libraries.fidelities.lindbladian_RB_left(propagators: dict, gate: str, index, dims, proj: bool = False)[source]
c3.libraries.fidelities.lindbladian_RB_right(propagators: dict, gate: str, index, dims, proj: bool)[source]
c3.libraries.fidelities.lindbladian_average_infid(ideal: ndarray, actual: constant, index=[0], dims=[2]) constant[source]

Average fidelity uses the Pauli basis to compare. Thus, perfect gates are always 2x2 (per qubit) and the actual unitary needs to be projected down.

Parameters
  • ideal (np.ndarray) – Contains ideal unitary representations of the gate

  • actual (tf.Tensor) – Contains actual unitary representations of the gate

  • index (int) – Index of the qubit(s) in the Hilbert space to be evaluated

  • dims (list) – List of dimensions of qubits

c3.libraries.fidelities.lindbladian_average_infid_set(propagators: dict, instructions: Dict[str, Instruction], index, dims, n_eval)[source]

Mean average fidelity over all gates in propagators.

Parameters
  • propagators (dict) – Contains unitary representations of the gates, identified by a key.

  • index (int) – Index of the qubit(s) in the Hilbert space to be evaluated

  • dims (list) – List of dimensions of qubits

  • proj (boolean) – Project to computational subspace

Returns

Mean average fidelity

Return type

tf.float64

c3.libraries.fidelities.lindbladian_epc_analytical(propagators: dict, index, dims, proj: bool, cliffords=False)[source]
c3.libraries.fidelities.lindbladian_population(propagators: dict, lvl: int, gate: str)[source]
c3.libraries.fidelities.lindbladian_unitary_infid(ideal: ndarray, actual: constant, index=[0], dims=[2]) constant[source]

Variant of the unitary fidelity for the Lindbladian propagator.

Parameters
  • ideal (np.ndarray) – Contains ideal unitary representations of the gate

  • actual (tf.Tensor) – Contains actual unitary representations of the gate

  • index (List[int]) – Index of the qubit(s) in the Hilbert space to be evaluated

  • dims (list) – List of dimensions of qubits

Returns

Overlap fidelity for the Lindblad propagator.

Return type

tf.float

c3.libraries.fidelities.lindbladian_unitary_infid_set(propagators: dict, instructions: Dict[str, Instruction], index, dims, n_eval)[source]

Variant of the mean unitary fidelity for the Lindbladian propagator.

Parameters
  • propagators (dict) – Contains actual unitary representations of the gates, resulting from physical simulation

  • instructions (dict) – Contains the perfect unitary representations of the gates, identified by a key.

  • index (List[int]) – Index of the qubit(s) in the Hilbert space to be evaluated

  • dims (list) – List of dimensions of qubits

  • n_eval (int) – Number of evaluation

Returns

Mean overlap fidelity for the Lindblad propagator for all gates in propagators.

Return type

tf.float

c3.libraries.fidelities.open_system_deco(func)[source]

Decorator for making registry of functions

c3.libraries.fidelities.orbit_infid(propagators, RB_number: int = 30, RB_length: int = 20, lindbladian=False, shots: Optional[int] = None, seqs=None, noise=None)[source]
c3.libraries.fidelities.population(propagators: dict, lvl: int, gate: str)[source]
c3.libraries.fidelities.populations(state, lindbladian)[source]
c3.libraries.fidelities.set_deco(func)[source]

Decorator for making registry of functions

c3.libraries.fidelities.state_deco(func)[source]

Decorator for making registry of functions

c3.libraries.fidelities.state_transfer_from_states(states: Tensor, index, dims, params, n_eval=-1)[source]
c3.libraries.fidelities.state_transfer_infid(ideal: ndarray, actual: constant, index, dims, psi_0)[source]

Single gate state transfer infidelity. The dimensions of psi_0 and ideal need to be compatible and index and dims need to project actual to these same dimensions.

Parameters
  • ideal (np.ndarray) – Contains ideal unitary representations of the gate

  • actual (tf.Tensor) – Contains actual unitary representations of the gate

  • index (int) – Index of the qubit(s) in the Hilbert space to be evaluated

  • dims (list) – List of dimensions of qubits

  • psi_0 (tf.Tensor) – Initial state

Returns

State infidelity for the selected gate

Return type

tf.float

c3.libraries.fidelities.state_transfer_infid_set(propagators: dict, instructions: dict, index, dims, psi_0, n_eval=-1, proj=True)[source]

Mean state transfer infidelity.

Parameters
  • propagators (dict) – Contains unitary representations of the gates, identified by a key.

  • index (int) – Index of the qubit(s) in the Hilbert space to be evaluated

  • dims (list) – List of dimensions of qubits

  • psi_0 (tf.Tensor) – Initial state of the device

  • proj (boolean) – Project to computational subspace

Returns

State infidelity, averaged over the gates in propagators

Return type

tf.float

c3.libraries.fidelities.unitary_deco(func)[source]

Decorator for making registry of functions

c3.libraries.fidelities.unitary_infid(ideal: ndarray, actual: Tensor, index: Optional[List[int]] = None, dims=None) Tensor[source]

Unitary overlap between ideal and actually performed gate.

Parameters
  • ideal (np.ndarray) – Ideal or goal unitary representation of the gate.

  • actual (np.ndarray) – Actual, physical unitary representation of the gate.

  • index (List[int]) – Index of the qubit(s) in the Hilbert space to be evaluated

  • gate (str) – One of the keys of propagators, selects the gate to be evaluated

  • dims (list) – List of dimensions of qubits

Returns

Unitary fidelity.

Return type

tf.float

c3.libraries.fidelities.unitary_infid_set(propagators: dict, instructions: dict, index, dims, n_eval=-1)[source]

Mean unitary overlap between ideal and actually performed gate for the gates in propagators.

Parameters
  • propagators (dict) – Contains actual unitary representations of the gates, resulting from physical simulation

  • instructions (dict) – Contains the perfect unitary representations of the gates, identified by a key.

  • index (List[int]) – Index of the qubit(s) in the Hilbert space to be evaluated

  • dims (list) – List of dimensions of qubits

  • n_eval (int) – Number of evaluation

Returns

Unitary fidelity.

Return type

tf.float

Hamiltonians module

Library of Hamiltonian functions.

c3.libraries.hamiltonians.duffing(a)[source]

Anharmonic part of the duffing oscillator.

Parameters

a (Tensor) – Annihilator.

Returns

Number operator.

Return type

Tensor

c3.libraries.hamiltonians.hamiltonian_reg_deco(func)[source]

Decorator for making registry of functions

c3.libraries.hamiltonians.int_XX(anhs)[source]

Dipole type coupling.

Parameters

anhs (Tensor list) – Annihilators.

Returns

coupling

Return type

Tensor

c3.libraries.hamiltonians.int_YY(anhs)[source]

Dipole type coupling.

Parameters

anhs (Tensor list) – Annihilators.

Returns

coupling

Return type

Tensor

c3.libraries.hamiltonians.resonator(a)[source]

Harmonic oscillator hamiltonian given the annihilation operator.

Parameters

a (Tensor) – Annihilator.

Returns

Number operator.

Return type

Tensor

c3.libraries.hamiltonians.third_order(a)[source]
Parameters

a (Tensor) – Annihilator.

Returns

  • Tensor – Number operator.

  • return literally the Hamiltonian a_dag a a + a_dag a_dag a for the use in any Hamiltonian that uses more than

  • just a resonator or Duffing part. A more general type of quantum element on a physical chip can have this type of interaction.

  • One example is a three wave mixing element used in signal amplification called a Superconducting non-linear asymmetric inductive eLement

  • (SNAIL in short). The code is a simple modification of the Duffing function and written in the same style.

c3.libraries.hamiltonians.x_drive(a)[source]

Semiclassical drive.

Parameters

a (Tensor) – Annihilator.

Returns

Number operator.

Return type

Tensor

c3.libraries.hamiltonians.y_drive(a)[source]

Semiclassical drive.

Parameters

a (Tensor) – Annihilator.

Returns

Number operator.

Return type

Tensor

c3.libraries.hamiltonians.z_drive(a)[source]

Semiclassical drive.

Parameters

a (Tensor) – Annihilator.

Returns

Number operator.

Return type

Tensor

Sampling module

Functions to select samples from a dataset by various criteria.

c3.libraries.sampling.all(learn_from, batch_size)[source]

Return all points.

Parameters
  • learn_from (list) – List of data points

  • batch_size (int) – Number of points to select

Returns

All indeces.

Return type

list

c3.libraries.sampling.even(learn_from, batch_size)[source]

Select evenly distanced samples across the set.

Parameters
  • learn_from (list) – List of data points

  • batch_size (int) – Number of points to select

Returns

Selected indices.

Return type

list

c3.libraries.sampling.even_fid(learn_from, batch_size)[source]

Select evenly among reached fidelities.

Parameters
  • learn_from (list) – List of data points.

  • batch_size (int) – Number of points to select.

Returns

Selected indices.

Return type

list

c3.libraries.sampling.from_end(learn_from, batch_size)[source]

Select from the end.

Parameters
  • learn_from (list) – List of data points

  • batch_size (int) – Number of points to select

Returns

Selected indices.

Return type

list

c3.libraries.sampling.from_start(learn_from, batch_size)[source]

Select from the beginning.

Parameters
  • learn_from (list) – List of data points

  • batch_size (int) – Number of points to select

Returns

Selected indices.

Return type

list

c3.libraries.sampling.high_std(learn_from, batch_size)[source]

Select points that have a high ratio of standard deviation to mean. Sampling from ORBIT data, points with a high std have the most coherent error, thus might be suitable for model learning. This has yet to be confirmed beyond anecdotal observation.

Parameters
  • learn_from (list) – List of data points.

  • batch_size (int) – Number of points to select.

Returns

Selected indices.

Return type

list

c3.libraries.sampling.random_sample(learn_from, batch_size)[source]

Select randomly.

Parameters
  • learn_from (list) – List of data points.

  • batch_size (int) – Number of points to select.

Returns

Selected indices.

Return type

list

c3.libraries.sampling.sampling_reg_deco(func)[source]

Decorator for making registry of functions

Tasks module

class c3.libraries.tasks.ConfusionMatrix(name: str = 'conf_matrix', desc: str = ' ', comment: str = ' ', params=None, **confusion_rows)[source]

Bases: Task

Allows for misclassificaiton of readout measurement.

confuse(pops)[source]

Apply the confusion (or misclassification) matrix to populations.

Parameters

pops (list) – Populations

Returns

Populations after misclassification.

Return type

list

class c3.libraries.tasks.InitialiseGround(name: str = 'init_ground', desc: str = ' ', comment: str = ' ', init_temp: Optional[Quantity] = None, params=None)[source]

Bases: Task

Initialise the ground state with a given thermal distribution.

initialise(drift_ham, lindbladian=False, init_temp=None)[source]

Prepare the initial state of the system. At the moment finite temperature requires open system dynamics.

Parameters
  • drift_ham (tf.Tensor) – Drift Hamiltonian.

  • lindbladian (boolean) – Whether to include open system dynamics. Required for Temperature > 0.

  • init_temp (Quantity) – Temperature of the device.

Returns

State or density vector

Return type

tf.Tensor

class c3.libraries.tasks.MeasurementRescale(name: str = 'meas_rescale', desc: str = ' ', comment: str = ' ', meas_offset: Optional[Quantity] = None, meas_scale: Optional[Quantity] = None, params=None)[source]

Bases: Task

Rescale the result of the measurements. This is usually done to account for preparation errors.

Parameters
  • meas_offset (Quantity) – Offset added to the measured signal.

  • meas_scale (Quantity) – Factor multiplied to the measured signal.

rescale(pop1)[source]

Apply linear rescaling and offset to the readout value.

Parameters

pop1 (tf.float64) – Population in first excited state.

Returns

Population after rescaling.

Return type

tf.float64

class c3.libraries.tasks.Task(name: str = ' ', desc: str = ' ', comment: str = ' ', params: Optional[dict] = None)[source]

Bases: C3obj

Task that is part of the measurement setup.

c3.libraries.tasks.task_deco(cl)[source]

Decorator for task classes list.

Module contents