def test_simplest_precharged(self): args = misc.Namespace() args.samples = [64] args.n_test = 0 args.loop = 1 args.full = False args.period = 16 args.ic = "precharge" args.seed = SEED args.inputs = INPUTS conf_seq = mconf.calib(self.meta, args, True) tb = sims.StageTestbench.Scalar(self.real.as_delta_sigma()[0], [], conf_seq) self.system_compare(tb)
def run(args): assert len(args.bits) == len(args.seed) directory = args.location mkdir(misc.Namespace(directory=directory, mode="750")) path_context = data.PathContext.relative() names = [ "paper_set_{}{}".format(ii, "_DRY" if DRY_RUN else "") for ii in range(len(args.bits)) ] if not JUST_PLOT: for ii, bits, seed, name in zip(count(), args.bits, args.seed, names): print("SET {}/{}".format(ii + 1, len(args.bits))) adcs = gen_adc(bits, seed, args, args.n_adcs) uncertain, ref, thres = characterize(args, adcs, seed) if 0 in TESTS: uncertain = prepickle_data(uncertain, path_context, directory, "{}.{}".format(name, "uncertain")) else: uncertain = None if 1 in TESTS: ref = prepickle_data(ref, path_context, directory, "{}.{}".format(name, "ref")) else: ref = None if 2 in TESTS: thres = prepickle_data(thres, path_context, directory, "{}.{}".format(name, "thres")) else: thres = None with open(name, 'wb') as f: pickle.dump(( uncertain, ref, thres, ), f, protocol=pickle.HIGHEST_PROTOCOL) for name in names: with open(name, 'rb') as f: dat = pickle.load(f) uncertain, ref, thres = dat uncertain = postpickle_data(uncertain, path_context) ref = postpickle_data(ref, path_context) thres = postpickle_data(thres, path_context) dat = ( uncertain, ref, thres, ) real_thres_s = data.at_least_ndarray(args.real_thres_s) sample_adc = dat[TESTS[0]][0][0, 0, 0] fsr = sample_adc.stages[0].meta.fsr n_bits = int( np.sum([ np.floor(stage.meta.n_bits) for stage in sample_adc.stages ])) n_bits += int(gen.infer_thres_bits(sample_adc.tail)[0]) lsb = gen.compute_lsb(n_bits, *fsr) min_snr_ref_v = args.min_snr_ref_v min_snr_thres_v = args.min_snr_thres_v if min_snr_ref_v is None: min_snr_ref_v = lsb / 2 if min_snr_thres_v is None: min_snr_thres_v = lsb / 2 snr_ref_inv = np.linspace(0, min_snr_ref_v, args.samples_snr_ref) snr_thres_inv = np.linspace(0, min_snr_thres_v, args.samples_snr_thres) u_args = ( "{}.uncertain".format(name), uncertain, ( "Real threshold voltage standard deviation (LSB)", "Modeled std (LSB)", ), ) u_kwargs = {"x_axes": real_thres_s, "y_axes": real_thres_s} t_args = ( "{}.thres".format(name), thres, ( "Real threshold voltage standard deviation (LSB)", "Thres. noise (SNR)", ), ) t_kwargs = { "x_axes": real_thres_s, "y_axes": snr_thres_inv, "noise": True } r_args = ( "{}.ref".format(name), ref, ( "Real threshold voltage standard deviation (LSB)", "Ref. noise (SNR)", ), ) r_kwargs = { "x_axes": real_thres_s, "y_axes": snr_ref_inv, "noise": True } if TOGETHER: f = plots.figure(figsize=( 10, 4, ) if FULL_SIZE else ( 5 * 1.5, 2 * 1.5, )) ax = f.add_subplot(111) h0 = [] h1 = [] h2 = [] brightness = 1 if 0 in TESTS: f, ax, h0 = plot2d(*u_args, **u_kwargs, ax=ax, color=(brightness, 0, 0), first_black=True, index=0, legend_handlers=h0, hide_constants=False) h0 = reversed(h0) if 2 in TESTS: f, ax, h2 = plot2d(*t_args, **t_kwargs, ax=ax, color=(0, 0, brightness), first_black=None, index=2, legend_handlers=h2) h2 = reversed(h2) if 1 in TESTS: f, ax, h1 = plot2d(*r_args, **r_kwargs, ax=ax, color=(0, brightness, 0), first_black=None, index=1, legend_handlers=h1) h1 = reversed(h1) h = [] for hh in (h0, h1, h2): h.extend(hh) proportion = 0.65 box = ax.get_position() ax.set_position( [box.x0, box.y0, box.width * proportion, box.height]) ax.set_facecolor((0.85, ) * 3) legend_handlers = h paths, names = tuple(zip(*legend_handlers)) f.legend(paths, names, loc='center left', bbox_to_anchor=(proportion, 0.5)) prev = mpl.rcParams['hatch.linewidth'] mpl.rcParams['hatch.linewidth'] = 5.0 f.savefig("{}.png".format(name), dpi=300) plots.show() mpl.rcParams['hatch.linewidth'] = prev else: if 0 in TESTS: plot2d(*u_args, **u_kwargs, color=(0.8, 0, 1), hide_constants=False) if 1 in TESTS: plot2d(*r_args, **r_kwargs, color=(0.8, 0, 1), hide_constants=False) if 2 in TESTS: plot2d(*t_args, **t_kwargs, color=(0.8, 0, 1), hide_constants=False) print("DONE")
plot2d(*t_args, **t_kwargs, color=(0.8, 0, 1), hide_constants=False) print("DONE") if __name__ == "__main__": # This was supoused to be built using argparse, but time contraints! N_FOR_STD = 4 SAMPLES = 4 SAMPLES_THRES = 3 SAMPLES_REF = 3 args = misc.Namespace() # Generation args args.bits = [[3.5, 3.5, 2.5, 4]] # args.bits = [4.5, 3.5, 3.5, 4] args.seed = [486582] args.s_cap = 0.0025 args.s_ref = None # Characterization args args.real_thres_s = np.linspace(0, 0.5 / 3, SAMPLES) # In lsb args.confidence = 0.95 args.n_adcs = N_FOR_STD