def stage_0_read(reactor_id): children = None if reactor_id==None: children = database_manager.fetch_children() elif isinstance(reactor_id,list): children = database_manager.fetch_children_subset(id=reactor_id) hanashi.create_new_batch(np.array([[None] for i in range(len(reactor_id))]),servers=reactor_id) hanashi.step()
def uniform(alpha): with open("../data/spectra/neutral_spectrum_components.json") as f: coefficients = json.load(f)["coefficients"] coefficients = np.array(coefficients) coefficients = alpha * coefficients hanashi.create_new_batch( coefficients.reshape((1, coefficients.shape[0]))) hanashi.step()
def assignments(): if request.method == "GET": database_manager.get_exsiting_batch() assignments = database_manager.fetch_assignments() return render_template('pages/assignments.html', assignments=assignments) elif request.method == "POST": """ Manually add new data. """ data = request.json["matrix"] #list of lists hanashi.create_new_batch(np.array(data)) return json.dumps({'success': True}), 200, { 'ContentType': 'application/json' }
def fitness(X_cube, mode="volume", high=None, low=None, E=1): """ mode: str -volume: expects the energy constranint to be smaller than a threshold -surface: expects the energy constraint to be equal to a threshold """ high = np.ones(X_cube.shape[1]) if not high else high low = np.zeros(X_cube.shape[1]) if not low else low scale = np.array([high, low]) if mode == "volume": X = hypercube_to_simplex(X_cube.copy(), scale) elif mode == "surface": #In this case there is a dimension reduction X = hypercube_to_simplex(X_cube.copy(), scale) u = E - X.sum(axis=1) u = u.reshape((u.shape[0], 1)) X = np.hstack([u, X]) print(X) shared_memory.set('batch_done', False) batch = hanashi.create_new_batch(X) R = hanashi.step() wait(lambda: shared_memory.get('batch_done')) id = batch["id"] Y = hanashi.get_from_id(id, return_request_id=True) Y = {u[1]: u[0] for u in Y} y = [Y[k] for k in np.array(R)[:, 2].astype(int)] return np.array(y).ravel()
def set_color(self): assert len(self.colors) != 0 and isinstance(self.colors,list) color_partitions = np.array_split(np.array(self._colors_index),len(self.reactors)) color_partition_dict = dict(zip(self.reactors,color_partitions)) X = np.repeat([self.color_base],len(self.colors),acis=0) X += np.eye(X.shape[0],X.shape[1],0)*self.color_current R = hanashi.create_new_batch(X,self.reactors) self.color_batch_id = R["batch_id"]