def createNewModel(): """ Create a new Delphi model. """ data = json.loads(request.data) if os.environ.get("CI") == "true": # When running in a continuous integration run, we set the sampling # resolution to be small to prevent timeouts. res = 5 elif os.environ.get("DELPHI_N_SAMPLES") is not None: # We also enable setting the sampling resolution through the # environment variable "DELPHI_N_SAMPLES", for development and testing # purposes. res = int(os.environ["DELPHI_N_SAMPLES"]) else: # If neither "CI" or "DELPHI_N_SAMPLES" is set, we default to a # sampling resolution of 1000. # TODO - we might want to set the default sampling resolution with some # kind of heuristic, based on the number of nodes and edges. - Adarsh res = 1000 G = AnalysisGraph.from_causemos_json_string(request.data, res) model = DelphiModel(id=data["id"], model=G.serialize_to_json_string(verbose=False)) db.session.merge(model) db.session.commit() response = json.loads(G.generate_create_model_response()) return jsonify(response)
def createNewModel(): """ Create a new Delphi model. """ data = json.loads(request.data) G = AnalysisGraph.from_causemos_json_string(request.data) G.id = data["id"] model = DelphiModel(id=data["id"], model=G.to_json_string()) db.session.merge(model) db.session.commit() edge_weights = G.get_edge_weights_for_causemos_viz() return jsonify({"status": "success", "relations": edge_weights})
def createNewModel(): """ Create a new Delphi model. """ if os.environ.get("CI") == "true": # When running in a continuous integration run, we set the sampling # resolution to be small to prevent timeouts. kde_kernels = 5 sampling_resolution = 5 burn = 5 elif os.environ.get("DELPHI_N_SAMPLES") is not None: # We also enable setting the sampling resolution through the # environment variable "DELPHI_N_SAMPLES", for development and testing # purposes. # NOTE: When creating, this environment variable is named incorrectly! kde_kernels = int(os.environ["DELPHI_N_SAMPLES"]) sampling_resolution = 100 burn = 100 else: # If neither "CI" or "DELPHI_N_SAMPLES" is set, we default to a # sampling resolution of 1000. # TODO - we might want to set the default sampling resolution with some # kind of heuristic, based on the number of nodes and edges. - Adarsh kde_kernels = 1000 sampling_resolution = 1000 burn = 10000 data = json.loads(request.data) G = AnalysisGraph.from_causemos_json_string(request.data, belief_score_cutoff=0, grounding_score_cutoff=0, kde_kernels=kde_kernels) model = DelphiModel(id=data["id"], model=G.serialize_to_json_string(verbose=False)) db.session.merge(model) db.session.commit() response = json.loads(G.generate_create_model_response()) # executor.submit_stored(data["id"], train_model, G, data["id"]) try: proc = multiprocessing.Process(target=train_model, args=(G, data["id"], sampling_resolution, burn, current_app), name='training') proc.start() except multiprocessing.ProcessError: print("Error: unable to start training process") response['status'] = 'server error: training' return jsonify(response)