Example #1
0
    async def async_measure_performance(self, prj, load_from_file=False):
        # type: (BagProject, bool) -> Dict[str, Any]
        """A coroutine that performs measurement.

        The measurement is done like a FSM.  On each iteration, depending on the current
        state, it creates a new testbench (or reuse an existing one) and simulate it.
        It then post-process the simulation data to determine the next FSM state, or
        if the measurement is done.

        Parameters
        ----------
        prj : BagProject
            the BagProject instance.
        load_from_file : bool
            If True, then load existing simulation data instead of running actual simulation.

        Returns
        -------
        output : Dict[str, Any]
            the last dictionary returned by process_output().
        """
        cur_state = self.get_initial_state()
        prev_output = None
        done = False

        while not done:
            # create and setup testbench
            tb_name, tb_type, tb_specs, tb_sch_params = self.get_testbench_info(cur_state,
                                                                                prev_output)

            tb_package = tb_specs['tb_package']
            tb_cls_name = tb_specs['tb_class']
            tb_module = importlib.import_module(tb_package)
            tb_cls = getattr(tb_module, tb_cls_name)
            raw_data_fname = os.path.join(self.data_dir, '%s.hdf5' % cur_state)

            tb_manager = tb_cls(raw_data_fname, tb_name, self.impl_lib, tb_specs,
                                self.sim_view_list, self.env_list)

            if load_from_file:
                print('Measurement %s in state %s, '
                      'load sim data from file.' % (self.meas_name, cur_state))
                if os.path.isfile(raw_data_fname):
                    cur_results = load_sim_file(raw_data_fname)
                else:
                    print('Cannot find data file, simulating...')
                    cur_results = await tb_manager.setup_and_simulate(prj, tb_sch_params)
            else:
                cur_results = await tb_manager.setup_and_simulate(prj, tb_sch_params)

            # process and save simulation data
            print('Measurement %s in state %s, '
                  'processing data from %s' % (self.meas_name, cur_state, tb_name))
            done, next_state, prev_output = self.process_output(cur_state, cur_results, tb_manager)
            with open_file(os.path.join(self.data_dir, '%s.yaml' % cur_state), 'w') as f:
                yaml.dump(prev_output, f)

            cur_state = next_state

        return prev_output
def compute_ss():
    output = 'ibias'
    for mos_type in mos_list:
        for thres in thres_list:
            for lch in lch_list:
                # load simulation results
                tb_name = get_tb_name(mos_type, thres, lch)
                fname = os.path.join(data_dir, '%s.data' % tb_name)
                results = load_sim_file(fname)
                info = compute_ss_helper(mos_type, results, output)
                for key, val in info.items():
                    results[key] = val
                    results['sweep_params'][key] = results['sweep_params'][output]
                save_sim_results(results, fname)
def print_data_info():
    tb_name = get_tb_name(mos_list[0], thres_list[0], lch_list[0])
    results = load_sim_file(os.path.join(data_dir, '%s.data' % tb_name))
    # show that results is a dictionary
    print('results type: %s' % type(results))
    print('results keys: %s' % list(results.keys()))
    # show values in the result dictionary
    vds = results['vds']
    vgs = results['vgs']
    ibias = results['ibias']
    # show how the sweep variables and outputs are structured
    print('vds type: {}, vds shape: {}'.format(type(vds), vds.shape))
    print('vgs type: {}, vgs shape: {}'.format(type(vgs), vgs.shape))
    print('ibias type: {}, ibias shape: {}'.format(type(ibias), ibias.shape))
    # show how to get sweep parameter order
    print('sweep_params:')
    pprint.pprint(results['sweep_params'])
def plot_data():
    # output data name
    output_names = ['ibias', 'gm', 'gds', 'vstar']

    # plot all ibias data
    fig_idx = 1
    for mos_type in mos_list:
        for thres in thres_list:
            for lch in lch_list[:1]:
                # load simulation results
                tb_name = get_tb_name(mos_type, thres, lch)
                results = load_sim_file(os.path.join(data_dir, '%s.data' % tb_name))
                # plot data
                for output in output_names:
                    plot_2d_data(mos_type, results, output, fig_idx)
                    fig_idx += 1

    plt.show()