Пример #1
0
def main():
    parser = argparse.ArgumentParser(
        description="Starts an LLH client, which then requests 3600 evals.")

    parser.add_argument("-c",
                        "--conf_file",
                        type=str,
                        help="service configuration file",
                        required=True)
    parser.add_argument("-d", "--data_file", type=str, help="test data file")
    args = parser.parse_args()

    with open(args.conf_file) as f:
        params = json.load(f)

    client = LLHClient(ctrl_addr=params["ctrl_addr"], conf_timeout=20000)

    with open(args.data_file, "rb") as f:
        event = pickle.load(f)[8]

    hit_data = event["hits"]
    evt_data = event["total_charge"]
    theta = event["params"]

    llhs = []
    start = time.time()
    for i in range(N_ITERATIONS):
        llhs.append(client.eval_llh(hit_data, evt_data, theta))
    delta = time.time() - start

    print(f"{N_ITERATIONS} evals took {delta*1000:.3f} ms"
          f" ({delta/N_ITERATIONS*1e3:.3f} ms per eval)")
Пример #2
0
class I3FreeDOMClient:
    """FreeDOM client IceTray module. Connects to a running LLHService"""
    def __init__(self, ctrl_addr, conf_timeout, rng=None):
        """initialize FreeDOM client, connect to LLH service"""
        self._llh_client = LLHClient(ctrl_addr, conf_timeout)

        if rng is None:
            self._rng = np.random.default_rng(None)
        else:
            self._rng = rng

    def __call__(
        self,
        frame,
        geo,
        reco_pulse_series_name,
        suffix="",
        init_range=DEFAULT_INIT_RANGE,
        search_limits=DEFAULT_SEARCH_LIMITS,
        n_live_points=DEFAULT_N_LIVE_POINTS,
        do_postfit=True,
        store_all=False,
        truth_seed=False,
        batch_size=DEFAULT_BATCH_SIZE,
        par_transforms=None,
        do_track_dllh=False,
        **crs_fit_kwargs,
    ):
        """reconstruct an event stored in an i3frame"""
        event = i3frame_dataloader.load_event(frame, geo,
                                              reco_pulse_series_name)

        fit_kwargs = dict(
            event=event,
            clients=[self._llh_client],
            rng=self._rng,
            init_range=init_range,
            search_limits=search_limits,
            n_live_points=n_live_points,
            do_postfit=do_postfit,
            store_all=store_all,
            truth_seed=truth_seed,
            param_transforms=par_transforms,
            batch_size=batch_size,
            spherical_indices=DEFAULT_SPHERICAL_INDICES,
            max_iter=DEFAULT_MAX_ITER,
            **crs_fit_kwargs,
        )

        full_res = timed_fit(**fit_kwargs)

        if event["params"] is not None:
            full_res["truth_LLH"] = self._llh_client.eval_llh(
                event["hit_data"][0], event["evt_data"][0], event["params"])

        prefix = f"FreeDOM_{suffix}_"

        store_fit_result(frame,
                         prefix,
                         full_res,
                         par_transforms,
                         store_i3_particles=True)

        if do_track_dllh:
            # do not conduct postfit for zero_track fits
            fit_kwargs["do_postfit"] = False
            no_track_res, E_only_res = zero_track_fit(full_res, **fit_kwargs)

            store_dllh(frame, prefix, full_res, no_track_res, E_only_res)
            store_fit_result(frame, prefix + "no_track_", no_track_res,
                             par_transforms)
            store_fit_result(frame, prefix + "E_only_", E_only_res,
                             par_transforms)