def component_index(self, component_index): if component_index is not None: parameter = get_nested_value(self.evaluation_object.parameters, self.parameter_sequence) if component_index > len(parameter) - 1: raise CADETProcessError('Index exceeds components') self._component_index = component_index
def entry_index(self, entry_index): if entry_index is not None: parameter = get_nested_value(self.event_handler.parameters, self.parameter_sequence) if entry_index > len(parameter) - 1: raise CADETProcessError('Index exceeds components') self._entry_index = entry_index
def set_variables(self, x, make_copy=False): """Sets the values from the x-vector to the OptimizationVariables. Parameters ---------- x : array_like Value of the optimization variables make_copy : Bool If True, a copy of the evaluation_object attribute is made on which the values are set. Otherwise, the values are set on the attribute. Returns ------- evaluation_object : object Returns copy of evaluation object if make_copy is True, else returns the attribute evaluation_object with the values set. Raises ------ ValueError If value of variable exceeds bounds See also -------- OptimizationVariable evaluate """ if len(x) != self.n_variables: raise CADETProcessError('Expected {} variables'.format( self.n_variables)) if make_copy: evaluation_object = copy.deepcopy(self.evaluation_object) else: evaluation_object = self.evaluation_object for variable, value in zip(self.variables, x): if value < variable.lb: raise ValueError("Exceeds lower bound") if value > variable.ub: raise ValueError("Exceeds upper bound") if variable.component_index is not None: value_list = get_nested_value(evaluation_object.parameters, variable.parameter_path) value_list[variable.component_index] = value parameters = generate_nested_dict(variable.parameter_path, value_list) else: parameters = generate_nested_dict(variable.parameter_path, value) evaluation_object.parameters = parameters return evaluation_object
def state(self, state): current_value = get_nested_value(self.event_handler.parameters, self.parameter_path) try: if self.entry_index is not None: value_list = current_value if isinstance(value_list, np.ndarray): value_list = value_list.tolist() value_list[self.entry_index] = state parameters = generate_nested_dict(self.parameter_sequence, value_list) else: parameters = generate_nested_dict(self.parameter_sequence, state) self.event_handler.parameters = parameters except (TypeError, ValueError) as e: raise CADETProcessError('{}'.format(str(e))) state = get_nested_value(self.event_handler.parameters, self.parameter_path) if self.entry_index is not None: state = state[self.entry_index] self._state = copy.deepcopy(state)
def parameter_timelines(self): """dict: TimeLine for every event parameter. """ parameter_timelines = { param: TimeLine() for param in self.event_parameters if param not in self.entry_dependent_parameters } parameters = self.parameters multi_timelines = {} for param in self.entry_dependent_parameters: base_state = get_nested_value(parameters, param) multi_timelines[param] = MultiTimeLine(base_state) for evt_parameter, events in self.parameter_events.items(): for index, evt in enumerate(events): section_start = evt.time if index < len(events) - 1: section_end = events[index + 1].time section = Section(section_start, section_end, evt.state, evt.n_entries, evt.degree) self._add_section(evt, section, parameter_timelines, multi_timelines) else: section_end = self.cycle_time section = Section(section_start, section_end, evt.state, evt.n_entries, evt.degree) self._add_section(evt, section, parameter_timelines, multi_timelines) if events[0].time != 0: section = Section(0.0, events[0].time, evt.state, evt.n_entries, evt.degree) self._add_section(evt, section, parameter_timelines, multi_timelines) for param, tl in multi_timelines.items(): parameter_timelines[param] = tl.combined_time_line() return Dict(parameter_timelines)
def parameter_shape(self): parameter = get_nested_value(self.event_handler.parameters, self.parameter_sequence) return np.array((parameter), ndmin=2).shape