Ejemplo n.º 1
0
    def reset(self, extraction_vessel):
        '''
        generate empty vessels
        '''

        vessels = [copy.deepcopy(extraction_vessel)]
        for i in range(self.n_empty_vessels):
            temp_vessel = vessel.Vessel(label='beaker_{}'.format(i + 1),
                                        v_max=self.max_vessel_volume,
                                        default_dt=0.05,
                                        n_pixels=self.n_vessel_pixels)
            vessels.append(temp_vessel)

        # generate oil vessel
        oil_vessel = vessel.Vessel(
            label='oil_vessel',
            v_max=self.oil_volume,
            n_pixels=self.n_vessel_pixels,
            settling_switch=False,
            layer_switch=False,
        )

        oil_vessel_material_dict = {}
        C6H14 = material.C6H14
        oil_vessel_material_dict[C6H14().get_name()] = [C6H14, self.oil_volume]
        oil_vessel_material_dict, _, _ = util.check_overflow(
            material_dict=oil_vessel_material_dict,
            solute_dict={},
            v_max=oil_vessel.get_max_volume())
        event = ['update material dict', oil_vessel_material_dict]
        oil_vessel.push_event_to_queue(feedback=[event], dt=0)

        state = util.generate_state(vessels, max_n_vessel=self.n_total_vessels)

        return vessels, oil_vessel, state
Ejemplo n.º 2
0
 def step(self, action):
     self.vessels, self.external_vessels, reward, self.done = self.extraction.perform_action(vessels=self.vessels,
                                                                                             oil_vessel=self.external_vessels,
                                                                                             action=action)
     self.state = util.generate_state(self.vessels, max_n_vessel=self.extraction.n_total_vessels)
     self.n_steps -= 1
     if self.n_steps == 0:
         self.done = True
         reward = self.extraction.done_reward(self.vessels[2])
     return self.state, reward, self.done, {}
Ejemplo n.º 3
0
    def step(self, action):
        '''
        Update the environment by performing an action.

        Parameters
        ---------------
        `action` : `list`
            A list of two numbers indicating the index of the action to
            perform and a multiplier to use in completing the action.

        Returns
        ---------------
        `state` : `np.array`
            A numpy array containing state variables, material concentrations, and spectral data.
        `reward` : `float`
            The amount of reward generated in perfoming the action.
        `done` : `bool`
            A boolean indicting if all the steps in an episode have been completed.
        `params` : `dict`
            A dictionary containing additional parameters or information that may be useful.

        Raises
        ---------------
        None
        '''

        # define the necessary parameters
        vessels = self.vessels
        ext_vessels = self.external_vessels
        done = self.done

        # perform the inputted action in the extraction module
        vessels, ext_vessels, reward, done = self.extraction.perform_action(
            vessels=vessels,
            external_vessels=ext_vessels,
            action=action
        )

        # re-define self variables for future use
        self.vessels = vessels
        self.external_vessels = ext_vessels
        self.done = done

        # determine the state after performing the action
        self.state = util.generate_state(
            self.vessels,
            max_n_vessel=self.extraction.n_total_vessels
        )

        # document the most recent step and determine if future steps are necessary
        self.n_steps -= 1
        if self.n_steps == 0:
            self.done = True

        # once all the steps have been completed, calculate the final reward and save any vessels
        if self.done:
            # after the last iteration, calculate the amount of target material in each vessel
            reward = ExtractionReward(
                vessels=self.vessels,
                desired_material=self.target_material,
                initial_target_amount=self.initial_target_amount
            ).calc_reward()

            # use the extraction reward class's `validate_vessels` method to output only the
            # vessels that pass a certain reward threshold;
            valid_vessels = ExtractionReward(
                vessels=self.vessels,
                desired_material=self.target_material,
                initial_target_amount=self.initial_target_amount
            ).validate_vessels(
                purity_threshold=self.min_purity_threshold
            )

            # save each validated vessel as pickle files
            for i, vessel in enumerate(valid_vessels):
                self._save_vessel(
                    extract_vessel=vessel,
                    vessel_rootname="extract_vessel_{}".format(i)
                )

        return self.state, reward, self.done, {}
Ejemplo n.º 4
0
    def reset(self, extraction_vessel):
        # generate empty vessels
        vessels = [copy.deepcopy(extraction_vessel)]
        for i in range(self.n_empty_vessels):
            temp_vessel = vessel.Vessel(label='beaker_{}'.format(i + 1),
                                        v_max=self.max_vessel_volume,
                                        default_dt=0.05,
                                        n_pixels=self.n_vessel_pixels)
            vessels.append(temp_vessel)

        # generate solution vessel2
        solution_1_vessel = vessel.Vessel(
            label='solution_1_vessel',
            v_max=self.solution_volume,
            n_pixels=self.n_vessel_pixels,
            settling_switch=False,
            layer_switch=False,
        )

        solution_2_vessel = vessel.Vessel(
            label='solution_2_vessel',
            v_max=self.solution_volume,
            n_pixels=self.n_vessel_pixels,
            settling_switch=False,
            layer_switch=False,
        )

        H2O = material.H2O
        Na = material.Na
        Cl = material.Cl
        Li = material.Li
        F = material.F

        solution_1_vessel_material_dict = {
            H2O().get_name(): [H2O, 30.0],
            Na().get_name(): [Na, 1.0],
            Cl().get_name(): [Cl, 1.0]
        }
        solution_1_solute_dict = {
            Na().get_name(): {
                H2O().get_name(): 1.0
            },
            Cl().get_name(): {
                H2O().get_name(): 1.0
            },
        }

        solution_2_vessel_material_dict = {
            H2O().get_name(): [H2O, 30.0],
            Li().get_name(): [Li, 1.0],
            F().get_name(): [F, 1.0]
        }
        solution_2_solute_dict = {
            Li().get_name(): {
                H2O().get_name(): 1.0
            },
            F().get_name(): {
                H2O().get_name(): 1.0
            },
        }

        solution_1_vessel_material_dict, solution_1_solute_dict, _ = util.check_overflow(
            material_dict=solution_1_vessel_material_dict,
            solute_dict=solution_1_solute_dict,
            v_max=solution_1_vessel.get_max_volume(),
        )

        solution_2_vessel_material_dict, solution_2_solute_dict, _ = util.check_overflow(
            material_dict=solution_2_vessel_material_dict,
            solute_dict=solution_2_solute_dict,
            v_max=solution_2_vessel.get_max_volume(),
        )

        event_s1_m = ['update material dict', solution_1_vessel_material_dict]
        event_s1_s = ['update solute dict', solution_1_solute_dict]

        event_s2_m = ['update material dict', solution_2_vessel_material_dict]
        event_s2_s = ['update solute dict', solution_2_solute_dict]

        solution_1_vessel.push_event_to_queue(feedback=[event_s1_m], dt=0)
        solution_1_vessel.push_event_to_queue(feedback=[event_s1_s], dt=0)

        solution_2_vessel.push_event_to_queue(feedback=[event_s2_m], dt=0)
        solution_2_vessel.push_event_to_queue(feedback=[event_s2_s], dt=0)

        return vessels, [solution_1_vessel,
                         solution_2_vessel], util.generate_state(
                             vessels, max_n_vessel=self.n_total_vessels)
Ejemplo n.º 5
0
    def reset(self, extraction_vessel):
        '''
        Method to reset the environment.

        Parameters
        ---------------
        `extraction_vessel` : `vessel` (default=`None`)
            A vessel object containing state variables, materials, solutes, and spectral data.

        Returns
        ---------------
        `vessels` : `list`
            A list of all the vessel objects that contain materials and solutes.
        `external_vessels` : `list`
            A list of the external vessels, beakers, to be used in the extraction.
        `state` : `np.array`
            An array containing state variables, material concentrations, and spectral data.

        Raises
        ---------------
        None
        '''

        # delete the extraction vessel's solute_dict and copy it into a list of vessels
        solute_dict = extraction_vessel._solute_dict
        extraction_vessel._solute_dict = {}
        vessels = [copy.deepcopy(extraction_vessel)]

        # create all the necessary beakers and add them to the list
        for i in range(self.n_empty_vessels):
            temp_vessel = vessel.Vessel(label='beaker_{}'.format(i + 1),
                                        v_max=self.max_vessel_volume,
                                        default_dt=0.05,
                                        n_pixels=self.n_vessel_pixels)
            vessels.append(temp_vessel)

        # generate a list of external vessels to contain solutes
        external_vessels = []

        # generate a vessel to contain the main solute
        solute_vessel = vessel.Vessel(
            label='solute_vessel0',
            v_max=self.solute_volume,
            n_pixels=self.n_vessel_pixels,
            settling_switch=False,
            layer_switch=False,
        )

        # create the material dictionary for the solute vessel
        solute_material_dict = {}
        solute_class = convert_to_class(materials=[self.solute])[0]
        solute_material_dict[self.solute] = [solute_class, self.solute_volume]

        # check for overflow
        solute_material_dict, _, _ = util.check_overflow(
            material_dict=solute_material_dict,
            solute_dict={},
            v_max=solute_vessel.get_max_volume())

        # instruct the vessel to update its material dictionary
        event = ['update material dict', solute_material_dict]
        solute_vessel.push_event_to_queue(feedback=[event], dt=0)

        # add the main solute vessel to the list of external vessels
        external_vessels.append(solute_vessel)

        # generate vessels for each solute in the extraction vessel
        for solute_name in solute_dict:
            # generate an empty vessel to be filled with a single solute
            solute_vessel = vessel.Vessel(label='solute_vessel{}'.format(
                len(external_vessels)),
                                          v_max=extraction_vessel.v_max,
                                          n_pixels=self.n_vessel_pixels,
                                          settling_switch=False,
                                          layer_switch=False)
            solute_material_dict = {}
            solute_material_dict[solute_name] = solute_dict[solute_name]

            # check for overflow
            solute_material_dict, _, _ = util.check_overflow(
                material_dict=solute_material_dict,
                solute_dict={},
                v_max=solute_vessel.get_max_volume())

            # instruct the vessel to update its material dictionary
            event = ['update material dict', solute_material_dict]
            solute_vessel.push_event_to_queue(feedback=[event], dt=0)

            # add this solute vessel to the list of external vessels
            external_vessels.append(solute_vessel)

        # generate the state
        state = util.generate_state(vessel_list=vessels,
                                    max_n_vessel=self.n_total_vessels)

        return vessels, external_vessels, state