Exemple #1
0
        "rollout_number_goal": [30000],
        "rollout_allocation_method": ["beta"],
        "alpha_param": [.75, 1, 2, 3, 4, 5, 6],
        "beta_param": [.75, 1, 2, 3, 4, 5, 6],
        "plan_commitment_algorithm": "n_steps",
        "plan_threshold": 1,
        "epsilon": 10,
        "delta": 0.1,
        "sample_observations": False,
        "waste_unused_rollouts": False,
        "use_expected_improvement": False,
        "planning_steps": 200
    }

    ##Create shared memory
    map_memory(generation_specifications["file"],
               generation_specifications["state_space_dimensionality"])

    specifications = SpecificationGenerator().generate(
        generation_specifications)
    runner = ExperimentRunner()
    DEBUG = False

    if DEBUG:
        runner.run(name,
                   specifications,
                   PlanningExperiment(),
                   propagate_exceptions=False,
                   specification_runner=MainRunner(),
                   use_dashboard=False,
                   force_pickle=True,
                   context_type="fork")
Exemple #2
0
    specs_tree_count = SpecificationGenerator().generate(gen_tree_count)

    specifications = []
    specifications += specs_baseline
    specifications += specs_ugapec
    specifications += specs_tTest

    print(
        f"Expt {name}:\t{len(specifications)/num_seeds} specs to run, over {num_seeds} seeds"
    )
    for spec in specifications:
        if spec["seed"] == 0:
            print(spec)

    runner = ExperimentRunner()
    map_memory(base_specs["file"], base_specs["state_space_dimensionality"])
    DEBUG = False

    if DEBUG:
        runner.run(name,
                   specifications,
                   PlanningExperiment(),
                   propagate_exceptions=True,
                   specification_runner=MainRunner(),
                   use_dashboard=False,
                   force_pickle=True,
                   context_type="fork")
    else:
        gpus = 4
        jobs_per_gpu = 2
        resources = list(product(list(range(gpus)), list(range(jobs_per_gpu))))
Exemple #3
0
    def initialize(self, specification: Specification):

        self.saved_before_first_action = False
        logger = logging.getLogger(self.get_logger_name())
        logger.setLevel(logging.DEBUG)
        self.specification = specification
        logger.info(f"Begin {specification}")
        self.use_heteroskedastic_noise = ["use_heteroskedastic_noise"]
        self.file = specification["file"]
        if "data" in self.file:
            self.action_model = ActionModel.XYZ
        elif "fn" in self.file:
            self.action_model = ActionModel.XYT
        else:
            raise Exception(f"cannot detect action model for file {self.file}")
        self.plot = specification["plot"]
        self.seed = specification["seed"]
        self.objective_c = specification["objective_c"]
        self.used_rollouts = 0
        self.rollout_allocation_method = specification[
            "rollout_allocation_method"]
        self.state_space_dimensionality = specification[
            "state_space_dimensionality"]
        self.rollout_number_goal = specification["rollout_number_goal"]

        # This needs to be done to make the spawn context work so the gpu can work
        map_memory([self.file], [self.state_space_dimensionality])

        # Plan commitment feature
        self.plan_commitment_algorithm = specification[
            "plan_commitment_algorithm"]
        self.plan_threshold = specification["plan_threshold"]

        if "waste_unused_rollouts" in specification:
            self.waste_unused_rollouts = specification["waste_unused_rollouts"]
        else:
            self.waste_unused_rollouts = False

        self.current_traj = []

        self.max_budget = specification[
            "planning_steps"]  #self.state_space_dimensionality[2]

        self.alpha_param = specification["alpha_param"]
        self.beta_param = specification["beta_param"]
        self.epsilon = specification["epsilon"]
        self.delta = specification["delta"]
        self.sample_observations = specification["sample_observations"]
        self.use_expected_improvement = specification[
            "use_expected_improvement"]

        self.data_X = []
        self.data_Y = []
        self.noises = []
        self.budgets_that_were_used = []
        if "fn" in self.file:
            oracle_model, workspace = create_data(self.file)
            oracle_model_for_hps = oracle_model
            if self.file == "fn:exp":
                self.chosen_function = exponential_function
            elif self.file == "fn:curved":
                self.chosen_function = curved_function
            elif self.file == "fn:sbo":
                self.chosen_function = sbo_function
            else:
                raise Exception()
            self.workspace = workspace
        elif "drone:" in self.file:
            oracle_model, workspace = load_from_egret_data(
                self.file.split(":")[1])
            oracle_model_for_hps = oracle_model
        else:
            oracle_model, workspace = load_from_ecomapper_data(
                self.file, 15, 50)
            oracle_model_for_hps = oracle_model
            self.oracle_model = oracle_model
            self.workspace = workspace
            workspace = self.workspace
        oracle_model.model.eval_model()
        logger.info(
            f"Workspace: X ({self.workspace.xmin} - {self.workspace.xmax}) Y ({self.workspace.ymin} - {self.workspace.ymax}) Z ({self.workspace.zmin} - {self.workspace.zmax})"
        )

        self.used_budget = 0
        # self.planning_iterations = specification["planning_iterations"]

        # This is a dumb way to do this
        initial = [
            int((workspace.xmin + workspace.xmax) / 2),
            int((workspace.ymin + workspace.ymax) / 2), workspace.zmin
        ]
        x = initial[0]
        y = initial[1]
        t = initial[2]

        self.auv = Simulated2dTemporalPoint(x, y, t)

        self.planner = POMCPPlanner(
            workspace,
            budget=self.max_budget,
            logger_name=self.get_logger_name(),
            seed=self.seed,
            objective_c=self.objective_c,
            action_model=self.action_model,
            total_rollouts=self.rollout_number_goal,
            rollout_allocation_method=self.rollout_allocation_method,
            state_space_dimensionality=self.state_space_dimensionality,
            filename=self.file,
            alpha_param=self.alpha_param,
            beta_param=self.beta_param,
            epsilon=self.epsilon,
            delta=self.delta,
            plan_commitment_algorithm=self.plan_commitment_algorithm,
            plan_threshold=self.plan_threshold,
            waste_unused_rollouts=self.waste_unused_rollouts,
            sample_observations=self.sample_observations,
            use_expected_improvement=self.use_expected_improvement)

        if self.plot:
            vbounds = (np.min(oracle_model.Ys), np.max(oracle_model.Ys))
            plt.ion()
            # env_view = GeneratingFieldViewVis(oracle_model, workspace, vbounds=vbounds)
            # env_view.update()
            # rig_view = RIGVisualizer(workspace.dimensions(), self.planner)

        X_t = np.array([self.auv.get_current_state()[:3]])
        if "fn" in self.file:
            samples = self.chosen_function(
                coordinates_to_unit_cube(X_t, self.workspace))
        else:
            samples = oracle_model.query_many(X_t, return_std=False)

        self.auv_data_model = TorchExactGPBackedDataModel(X_t,
                                                          samples,
                                                          logger=self.logger,
                                                          workspace=workspace)
        self.auv_data_model.model.copy_hyperparameters_from(
            oracle_model_for_hps.model.model)
        self.auv_data_model.update(X_t, samples)
        self.auv_data_model.model.eval_model()

        if self.plot:
            crit_path_view = CriticalPathVisualizer(self.auv,
                                                    self.planner,
                                                    self.auv_data_model,
                                                    workspace,
                                                    vbounds=vbounds)
            # crit_path_view.update()
            # self.auv_view = AUVViewVis(self.auv, self.auv_data_model, workspace)  # , vbounds=vbounds)
            # self.visualizers = [env_view, self.auv_view, rig_view]
            # self.visualizers = [self.auv_view]
            self.visualizers = [crit_path_view]
            # self.visualizers = [self.auv_view, rig_view]

        self.data_X.append(deepcopy(self.auv_data_model.Xs))
        self.data_Y.append(deepcopy(self.auv_data_model.Ys))
        # empty_cache()

        self.X_t = memory_mapped_dict[str(self.file) +
                                      str(self.state_space_dimensionality) +
                                      "Sreal_ndarrays"]
        if "fn" in self.file:
            X_t = coordinates_to_unit_cube(self.X_t, self.workspace)
            self.gt_Y = self.chosen_function(X_t)
        else:
            neigh = KNeighborsRegressor(n_neighbors=10)
            neigh.fit(self.oracle_model.Xs, self.oracle_model.Ys)
            self.oracle_model = neigh
            self.gt_Y = neigh.predict(self.X_t)

        del oracle_model_for_hps