topqad_sdk.noiseprofiler package

Subpackages

Submodules

topqad_sdk.noiseprofiler.fit module

topqad_sdk.noiseprofiler.fit.convert_sympy_formula_to_numpy_func(formula: str, scale: str = 'linear')[source]

Convert a sympy formula string to a numerical function.

Parameters:
  • formula (str) – The sympy formula string. Should only use functions available in numpy.

  • scale (str) – If ‘linear’ formula is computed as is. If ‘log’ the log of the formula is computed.

Returns:

A function that computes the input formula.

Return type:

Callable

topqad_sdk.noiseprofiler.fit.fit_data(xs: list[float], ys: list[float], es: list[float], fit_ansatz: Callable, fit_param_bounds: tuple[list, list], fit_y_scale: str, SNR_threshold: float = 5, Abs_threshold: float = inf, verbose: bool = False) tuple[Variable, ...][source]

Fit given data using the given ansatz.

Uses scipy’s curve_fit with method=’trf’.

Parameters:
  • xs (list[float]) – The independent variable data.

  • ys (list[float]) – The dependent variable data.

  • es (list[float]) – The uncertainity in the dependent variable.

  • fit_ansatz (Callable) – The fit function.

  • fit_param_bounds (tuple[list, list]) – The bounds for the fit parameters.

  • fit_y_scale (str) – Either ‘linear’ or ‘log’. If ‘log’ then ys is scaled to log(ys) before fit.

  • SNR_threshold (float, optional) – The signal-to-noise threshold below which data is discarded. Defaults to 5.

  • Abs_threshold (float, optional) – The error rate above which the data is discarded. Defaults to infinity.

  • verbose (bool, optional) – Whether to print info. Defaults to False.

Raises:
  • ValueError – If xs, ys and es don’t have the same length.

  • ValueError – If at least two points not provided, or less than two points remain after filtering.

Returns:

The fit parameters as uncertainities Variable types. Use p.nominal_value and p.std_dev to

access the stored values.

Return type:

tuple[Variable, …]

topqad_sdk.noiseprofiler.models module

class topqad_sdk.noiseprofiler.models.BackendSimulationParametersModel(*, num_workers: int)[source]

Bases: BaseModel

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

num_workers: int
class topqad_sdk.noiseprofiler.models.ProtocolSpecificationListModel(*, protocols: list[ProtocolSpecificationModel])[source]

Bases: BaseModel

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

protocols: list[ProtocolSpecificationModel]
class topqad_sdk.noiseprofiler.models.RequestResponseModel(*, protocols: list[ProtocolSpecificationModel], backend_simulation_parameters: BackendSimulationParametersModel | None = None, simulation_run_information: SimulationRunInformation | None = None)[source]

Bases: BaseModel

backend_simulation_parameters: BackendSimulationParametersModel | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

protocols: list[ProtocolSpecificationModel]
simulation_run_information: SimulationRunInformation | None
class topqad_sdk.noiseprofiler.models.SimulationRunInformation(*, system: str, python_version: str, noiseprofiler_version: str, execution_time: int, report_generation_time: str)[source]

Bases: BaseModel

execution_time: int
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

noiseprofiler_version: str
python_version: str
report_generation_time: str
system: str

topqad_sdk.noiseprofiler.qre_noiseprofile module

Create the noise profile needed to perform qre.

topqad_sdk.noiseprofiler.qre_noiseprofile.get_preset_names()[source]
topqad_sdk.noiseprofiler.qre_noiseprofile.noise_profile_from_preset(preset_name: str)[source]

Load a precomputed noise profile appropriate for quantum resource estimation.

Parameters:
  • preset_name (str) – The name of the noise profile to load. Options include - “physical_depolarizing_baseline” - “physical_depolarizing_baseline_throughput_matched” - “physical_depolarizing_baseline_logical_time_matched” - “physical_depolarizing_target” - “physical_depolarizing_target_throughput_matched” - “physical_depolarizing_target_logical_time_matched” - “physical_depolarizing_desired” - “physical_depolarizing_desired_throughput_matched” - “physical_depolarizing_desired_logical_time_matched”

  • follows (The profiles have decoder reaction times as)

  • physical_depolarizing_baseline* (-) – parameters associated with existing state-of-the-art hardware.

  • physical_depolarizing_target* (-) – parameters aligned with near-term research goals.

  • physical_depolarizing_desired* (-) – an optimistic target for future high-quality devices.

  • follows

  • base (-) – a SotA2025 decoder that has high reaction time compared to the logical cycle time.

  • throughput-matched (-) – the decoder’s throughput matches the logical cycle time. However, the reaction time of the decoder is larger than the logical cycle time.

  • logical_time_matched (-) – reaction time equal to the logical cycle time.

Raises:

ValueError – If unknown preset name provided.

Returns:

A json string with the noise profile.

Return type:

str

topqad_sdk.noiseprofiler.qre_noiseprofile.noise_profile_from_protocols(memory: Memory, magic_state_prep: MagicStatePreparationHookInjection | MagicStatePreparationRepCode, lattice_surgery_distance: LatticeSurgery, lattice_surgery_rounds: LatticeSurgery)[source]

Create a noise profile from a set of already computed protocols.

This noise profile can be passed to “qre” to obtain a resource estimate.

Each input object should have enough simulation data in it that the fit_data method outputs the correct fit. The fit_options may be modified for this purpose as well. Before calling this function, make sure that each fit extrapolates well to very low logical error rates.

Parameters:
Raises:
  • ValueError – If multiple noise models are founds in any of the inputs.

  • ValueError – If the two lattice surgery have different noise models.

Returns:

A json string with the noise profile.

Return type:

str

topqad_sdk.noiseprofiler.simtable module

class topqad_sdk.noiseprofiler.simtable.FieldHeader(name: str, kind: str, *, full_label: str | None = None, math_symbol: str | None = None, compute_formula: Callable | str | None = None, floatfmt: str = '.2f', intfmt: str = ',', hidden: bool = False)[source]

Bases: object

copy()[source]
classmethod from_json(json_data: str)[source]
to_json()[source]
to_model()[source]
class topqad_sdk.noiseprofiler.simtable.FieldHeaderModel(*, name: str, full_label: str, kind: str | None = None, math_symbol: str | None = None, compute_formula: Callable | str | None = None, floatfmt: str, intfmt: str, hidden: bool)[source]

Bases: BaseModel

compute_formula: Callable | str | None
floatfmt: str
full_label: str
hidden: bool
intfmt: str
kind: str | None
math_symbol: str | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
class topqad_sdk.noiseprofiler.simtable.SimTable(fields: list[FieldHeader] | list[str])[source]

Bases: object

This class provides storage for simulation data.

Data is stored in a flat 2D table. Each column is described by a FieldHeader.

add_col(col_field: ~topqad_sdk.noiseprofiler.simtable.FieldHeader | str, formula: ~collections.abc.Callable = <function SimTable.<lambda>>)[source]

Add col to the sim table

Parameters:
  • col_field (Field | str) – The column field.

  • formula (Callable, optional) – The formula to use to compute the data in the column by operating on each row. Defaults to lambda s: “?”.

add_row(**kwargs)[source]

Add a row of data.

If any columns are missing, a “?” is added instead.

Raises:

AttributeError – If data for unknown column is provided.

compute_computed_columns(row_ind: int | None = None) None[source]

Compute the value of all columns with computed kind in the table.

Columns are computed in turn from left to rigth.

Parameters:

row_ind (int | None, optional) – Only compute the specified row. Defaults to None.

create_empty_copy() SimTable[source]

Create a new empty SimTable with the same field headers as this table.

Returns:

A new SimTable instance with identical field headers but no data rows.

Return type:

SimTable

classmethod create_from_function_parameters(func: Callable)[source]

Return a list of parameter names for a function, excluding *args and **kwargs parameters.

Parameters:

func (Callable) – Function whose parameters to extract.

data() list[source]

If database is a single column, return data as list.

Raises:

ValueError – If self has multiple columns.

Returns:

The list of values in the column.

Return type:

list

filter(condition: ~collections.abc.Callable = <function SimTable.<lambda>>) SimTable[source]

Output a table filtered by the condition.

Parameters:
  • condition (Callable, optional) – A lambda function that determines if row should be in output. Defaults to

  • s (lambda) – True.

Returns:

The filtered rows.

Return type:

SimTable

classmethod from_json(json_str: str) SimTable[source]

Create a SimTable instance from a json string.

Parameters:

json_str (str) – json string

Returns:

A new SimTable instance populated from the json.

Return type:

SimTable

get_field_names_of_kind(kind: str) list[source]

Get all field names of a particular kind.

Parameters:

kind (str) – The kind to search for.

Returns:

List of field names that match the kind.

Return type:

list

group(condition: ~collections.abc.Callable = <function SimTable.<lambda>>)[source]

Output a dictionary of simtables specified by the condition.

Parameters:

condition (Callable, optional) – Condition to group by that is applied to each row.

Returns:

The keys of the dictionary are the unique outputs of conditon.

Return type:

dict[SimTable]

num_fields() int[source]

Count the number of fields in the table.

print_full_table() None[source]

Print the entire table, including hidden columns.

sort_by(column: str, reverse: bool = False, key: Callable = None) None[source]

Sort the table by a particular column inplace.

Parameters:
  • column (str) – The name of the column to sort by

  • reverse (bool, optional) – Whether to sort in descending order. Defaults to False.

  • key (Callable, optional) – A function that takes a value and returns a sort key. If None, values are compared directly. Defaults to None.

Raises:

ValueError – If the specified column doesn’t exist in the table

to_json() str[source]

Convert the SimTable to json.

Returns:

The json representation of the table.

Return type:

str

to_model() SimTableModel[source]
class topqad_sdk.noiseprofiler.simtable.SimTableModel(*, FieldHeaders: list[FieldHeaderModel], data: list[dict[str, Any]])[source]

Bases: BaseModel

FieldHeaders: list[FieldHeaderModel]
data: list[dict[str, Any]]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Module contents

class topqad_sdk.noiseprofiler.FitSpecification(fit_ansatz: str, param_bounds: tuple[list, list], y_scale: str, fit_ansatz_latex: str, ind_math_symbol: str)[source]

Bases: object

Contains all information to specify a fit for a given class of curves.

Parameters:
  • fit_ansatz (Callable) – The fit function.

  • param_bounds (tuple[list, list]) – The parameter bounds.

  • y_scale (str) – Either ‘linear’ or ‘log’.

  • fit_ansatz_latex (str) – The latex description of the fit function. Use raw strings.

Examples

def fit_ansatz_memory_d_ler(distance, p_1, p_2):

return -(distance+1)/2 * np.log(p_2) + 2*np.log(distance) + np.log(p_1)

FitSpecification(fit_ansatz=fit_ansatz_memory_d_ler,

param_bounds=([0, 0], [np.inf, np.inf]), y_scale=’log’, fit_ansatz_latex=r”{p_1} d^2 times {p_2}^{{-frac{{d+1}}{{2}}}}”, )

fit_ansatz: str
fit_ansatz_latex: str
ind_math_symbol: str
param_bounds: tuple[list, list]
y_scale: str
class topqad_sdk.noiseprofiler.Quantity(*, value: float, unit: str)[source]

Bases: BaseModel

A basic quantity with a value and unit.

classmethod from_raw_value(raw_value: float, unit: str) Quantity[source]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.

unit: str
value: float