scalerqec.Stratified package

Submodules

scalerqec.Stratified.Scaler module

class scalerqec.Stratified.Scaler.Scaler(error_rate=0, time_budget=7200)[source]

Bases: object

Use stratified sampling to estimate the logical error rate of a quantum error correction code. The only hyper parameters are physical error rate and time budget (in seconds).

calculate_LER_from_file(filepath, pvalue, codedistance, figname, titlename, repeat=1)[source]

scalerqec.Stratified.ScurveModel module

scalerqec.Stratified.ScurveModel.bias_estimator(N, M)[source]

Bias = E[y(w)] - y(w) Estimated by: (1/2) * f’’(P_w) * Var(P_w) where f(x) = ln(1/(2x) - 1)

scalerqec.Stratified.ScurveModel.evenly_spaced_ints(minw, maxw, N)[source]
scalerqec.Stratified.ScurveModel.inv_logit_half(y)[source]
scalerqec.Stratified.ScurveModel.linear_function(x, a, b)[source]

Linear function for curve fitting.

scalerqec.Stratified.ScurveModel.modified_linear_function(d)[source]
scalerqec.Stratified.ScurveModel.modified_linear_function_with_d(x, a, b, c, d)[source]
scalerqec.Stratified.ScurveModel.modified_sigmoid_function(x, a, b, c, d)[source]

Modified sigmoid function for curve fitting. This function is used to fit the S-curve.

scalerqec.Stratified.ScurveModel.poly_function(x, a, b, c, d)[source]

Linear function for curve fitting.

scalerqec.Stratified.ScurveModel.quadratic_function(x, a, b, c)[source]

Linear function for curve fitting.

scalerqec.Stratified.ScurveModel.refined_sweet_spot(alpha, beta, t, ratio=0.05)[source]
scalerqec.Stratified.ScurveModel.scurve_function(x, center, sigma)[source]
scalerqec.Stratified.ScurveModel.scurve_function_with_distance(x, cd, mu, sigma)[source]
Piece-wise S-curve:

0 for x < cd 0.5 * Φ((x - μ) / σ) for x ≥ cd

where Φ is the standard normal CDF.

scalerqec.Stratified.ScurveModel.show_bias_estimator(N, M)[source]

Bias = E[y(w)] - y(w) Estimated by: (1/2) * f’’(P_w) * Var(P_w) where f(x) = ln(1/(2x) - 1)

scalerqec.Stratified.ScurveModel.sigma_estimator(N, M)[source]
scalerqec.Stratified.ScurveModel.subspace_sigma_estimator(N, M)[source]

scalerqec.Stratified.fitting module

scalerqec.Stratified.fitting.r_squared(y_true, y_pred, clip=False)[source]

Compute the coefficient of determination (R²).

Parameters:
  • y_true (array-like) – Observed data.

  • y_pred (array-like) – Model-predicted data (same length as y_true).

  • clip (bool, default False) – If True, negative R² values are clipped to 0 so the score lies strictly in the interval [0, 1].

Returns:

The R² statistic.

Return type:

float

scalerqec.Stratified.StratifiedLERcalc module

scalerqec.Stratified.StratifiedLERcalc.SAMPLE_GAP = 100

Use strafified sampling algorithm to calculate the logical error rate

class scalerqec.Stratified.StratifiedLERcalc.StratifiedLERcalc(error_rate=0, sampleBudget=10000, num_subspace=30)[source]

Bases: object

calculate_LER_from_StabCode(qeccirc: StabCode, noise_model: NoiseModel, repeat=1)[source]
calculate_LER()[source]
calculate_LER_from_file(filepath, pvalue)[source]
clear_all()[source]
determine_range_to_sample(epsilon=0.01)[source]

We need to be exact about the range of w we want to sample. We don’t want to sample too many subspaces, especially those subspaces with tiny binomial weights. This should comes from the analysis of the weight of each subspace.

We use the standard deviation to approimxate the range

get_LER_subspace(weight)[source]
get_LER_subspace_no_weight(weight)[source]
parse_from_file(filepath)[source]

Read the circuit, parse from the file

sample_all_subspace(shots_each_subspace=1000000)[source]

Aggressively sample all the subspace. This function is only used to test the correctness of the algorithm.

subspace_sampling()[source]

Sample around the subspaces.

scalerqec.Stratified.stratifiedScurveLER module

class scalerqec.Stratified.stratifiedScurveLER.StratifiedScurveLERcalc(error_rate=0, sampleBudget=10000, k_range=3, num_subspace=5, beta=4)[source]

Bases: object

binary_search_lower(low, high, shots=5000)[source]
binary_search_upper(low, high, shots)[source]
calculate_LER_from_StabCode(qeccirc: StabCode, noise_model: NoiseModel, figname, titlename, repeat=1)[source]
calc_logical_error_rate_after_curve_fitting()[source]
calc_logical_error_rate_with_fixed_w(shots, w)[source]

Calculate the logical error rate with fixed w

calculate_LER()[source]
calculate_LER_from_file(filepath, pvalue, codedistance, figname, titlename, repeat=1)[source]
calculate_R_square_score()[source]
clear_all()[source]
determine_lower_w()[source]
determine_range_to_sample()[source]

We need to be exact about the range of w we want to sample. We don’t want to sample too many subspaces, especially those subspaces with tiny binomial weights. This should comes from the analysis of the weight of each subspace.

We use the standard deviation to approimxate the range

determine_saturated_w(shots=1000)[source]

Use binary search to determine the minw and maxw

fast_calculate_LER_from_file(filepath, pvalue, codedistance, figname, titlename, repeat=1)[source]
fit_Scurve()[source]
fit_linear_area()[source]
fit_log_S_model(filename, time=None)[source]
get_LER_subspace(weight)[source]
ground_truth_subspace_sampling()[source]

Sample around the subspaces. This is the ground truth value to test the accuracy of the curve fitting.

load_all_sample_result(filepath)[source]
parse_from_file(filepath)[source]

Read the circuit, parse from the file

plot_scurve(filename, title='S-curve')[source]

Plot the S-curve and its discrete estimate.

sample_all_subspaces(Nclip, Budget, save_path=None)[source]

Sample all subspaces from minw to maxw return the result of these samples as two dictionary

set_sample_bound(MIN_NUM_LE_EVENT, SAMPLE_GAP, MAX_SAMPLE_GAP, MAX_SUBSPACE_SAMPLE)[source]

Set the sample bound for the subspace sampling

set_t(t)[source]

Set the t value for the S-curve fitting. This is used to determine the range of subspace we need to sample.

subspace_sampling()[source]

wlist store the subset of weights we need to sample and get correct logical error rate.

In each subspace, we stop sampling until 100 logical error events are detected, or we hit the total budget.

subspace_sampling_to_fit_curve(sampleBudget)[source]

After we determine the minw and maxw, we generate an even distribution of points between minw and maxw.

The goal is for the curve fitting in the next step to get more accurate.

Module contents

class scalerqec.Stratified.Scaler(error_rate=0, time_budget=7200)[source]

Bases: object

Use stratified sampling to estimate the logical error rate of a quantum error correction code. The only hyper parameters are physical error rate and time budget (in seconds).

calculate_LER_from_file(filepath, pvalue, codedistance, figname, titlename, repeat=1)[source]
class scalerqec.Stratified.StratifiedLERcalc(error_rate=0, sampleBudget=10000, num_subspace=30)[source]

Bases: object

calculate_LER_from_StabCode(qeccirc: StabCode, noise_model: NoiseModel, repeat=1)[source]
calculate_LER()[source]
calculate_LER_from_file(filepath, pvalue)[source]
clear_all()[source]
determine_range_to_sample(epsilon=0.01)[source]

We need to be exact about the range of w we want to sample. We don’t want to sample too many subspaces, especially those subspaces with tiny binomial weights. This should comes from the analysis of the weight of each subspace.

We use the standard deviation to approimxate the range

get_LER_subspace(weight)[source]
get_LER_subspace_no_weight(weight)[source]
parse_from_file(filepath)[source]

Read the circuit, parse from the file

sample_all_subspace(shots_each_subspace=1000000)[source]

Aggressively sample all the subspace. This function is only used to test the correctness of the algorithm.

subspace_sampling()[source]

Sample around the subspaces.

class scalerqec.Stratified.StratifiedScurveLERcalc(error_rate=0, sampleBudget=10000, k_range=3, num_subspace=5, beta=4)[source]

Bases: object

binary_search_lower(low, high, shots=5000)[source]
binary_search_upper(low, high, shots)[source]
calculate_LER_from_StabCode(qeccirc: StabCode, noise_model: NoiseModel, figname, titlename, repeat=1)[source]
calc_logical_error_rate_after_curve_fitting()[source]
calc_logical_error_rate_with_fixed_w(shots, w)[source]

Calculate the logical error rate with fixed w

calculate_LER()[source]
calculate_LER_from_file(filepath, pvalue, codedistance, figname, titlename, repeat=1)[source]
calculate_R_square_score()[source]
clear_all()[source]
determine_lower_w()[source]
determine_range_to_sample()[source]

We need to be exact about the range of w we want to sample. We don’t want to sample too many subspaces, especially those subspaces with tiny binomial weights. This should comes from the analysis of the weight of each subspace.

We use the standard deviation to approimxate the range

determine_saturated_w(shots=1000)[source]

Use binary search to determine the minw and maxw

fast_calculate_LER_from_file(filepath, pvalue, codedistance, figname, titlename, repeat=1)[source]
fit_Scurve()[source]
fit_linear_area()[source]
fit_log_S_model(filename, time=None)[source]
get_LER_subspace(weight)[source]
ground_truth_subspace_sampling()[source]

Sample around the subspaces. This is the ground truth value to test the accuracy of the curve fitting.

load_all_sample_result(filepath)[source]
parse_from_file(filepath)[source]

Read the circuit, parse from the file

plot_scurve(filename, title='S-curve')[source]

Plot the S-curve and its discrete estimate.

sample_all_subspaces(Nclip, Budget, save_path=None)[source]

Sample all subspaces from minw to maxw return the result of these samples as two dictionary

set_sample_bound(MIN_NUM_LE_EVENT, SAMPLE_GAP, MAX_SAMPLE_GAP, MAX_SUBSPACE_SAMPLE)[source]

Set the sample bound for the subspace sampling

set_t(t)[source]

Set the t value for the S-curve fitting. This is used to determine the range of subspace we need to sample.

subspace_sampling()[source]

wlist store the subset of weights we need to sample and get correct logical error rate.

In each subspace, we stop sampling until 100 logical error events are detected, or we hit the total budget.

subspace_sampling_to_fit_curve(sampleBudget)[source]

After we determine the minw and maxw, we generate an even distribution of points between minw and maxw.

The goal is for the curve fitting in the next step to get more accurate.