def test_render_3d(self): # if we don't have ascent, simply return info = ascent.about() if info["runtimes/ascent/vtkm/status"] != "enabled": return obase = "tout_python_ascent_render_3d" ofile = obase + "100.png" # clean up old results if they exist if os.path.isfile(ofile): os.remove(ofile) # create example mesh n_mesh = conduit.Node() conduit.blueprint.mesh.examples.braid("hexs", 10, 10, 10, n_mesh) # open ascent a = ascent.Ascent() a.open() a.publish(n_mesh) actions = conduit.Node() scenes = conduit.Node() scenes["s1/plots/p1/type"] = "pseudocolor" scenes["s1/plots/p1/field"] = "braid" scenes["s1/image_prefix"] = obase add_act = actions.append() add_act["action"] = "add_scenes" add_act["scenes"] = scenes a.execute(actions) a.close() self.assertTrue(os.path.isfile(ofile))
def test_render_flow_inspect(self): # if we don't have ascent, simply return info = ascent.about() if info["runtimes/ascent/status"] != "enabled": return flow.Workspace.register_builtin_filter_types() flow.Workspace.register_filter_type(flow.wrap_function(inspect)); # create example mesh n_mesh = conduit.Node() conduit.blueprint.mesh.examples.braid("quads", 10, 10, 0, n_mesh) # open ascent a = ascent.Ascent() open_opts = conduit.Node() open_opts["runtime/type"].set("flow") a.open(open_opts) a.publish(n_mesh) actions = conduit.Node() add_py = actions.append() add_py["action"] = "add_filter"; add_py["type_name"] = "ensure_python"; add_py["name"] = "py"; add_ins = actions.append() add_ins["action"] = "add_filter"; add_ins["type_name"] = "inspect"; add_ins["name"] = "my_inspect"; conn_py = actions.append() conn_py["action"] = "connect"; conn_py["src"] = "source"; conn_py["dest"] = "py"; conn_ins = actions.append() conn_ins["action"] = "connect"; conn_ins["src"] = "py"; conn_ins["dest"] = "my_inspect"; print(actions) actions.append()["action"] = "execute" # this will fail for static libs case # b/c the py libs are still dynamic, and they each # link their own static copy of flow try: a.execute(actions) except RuntimeError as e: if not e.message.count("ensure_python") > 0: raise(e) a.close()
def test_delete_scene(self): # exec again, but this time remove a scene # tests regression related to internal book keeping # with graph setup mesh = conduit.Node() conduit.blueprint.mesh.examples.braid("hexs", 5, 5, 5, mesh) a = ascent.Ascent() opts = conduit.Node() opts["exceptions"] = "forward" a.open(opts) a.publish(mesh) actions = conduit.Node() add_act = actions.append() add_act["action"] = "add_pipelines" pipelines = add_act["pipelines"] pipelines["pl1/f1/type"] = "contour" contour_params = pipelines["pl1/f1/params"] contour_params["field"] = "braid" iso_vals = np.array([0.2, 0.4], dtype=np.float32) contour_params["iso_values"].set(iso_vals) add_act2 = actions.append() add_act2["action"] = "add_scenes" scenes = add_act2["scenes"] scenes["s1/plots/p1/type"] = "pseudocolor" scenes["s1/plots/p1/pipeline"] = "pl1" scenes["s1/plots/p1/field"] = "braid" # set the output file name (ascent will add ".png") scenes["s1/image_name"] = "out_pipeline_ex1_contour" scenes["s2/plots/p1/type"] = "pseudocolor" scenes["s2/plots/p1/pipeline"] = "pl1" scenes["s2/plots/p1/field"] = "braid" # set the output file name (ascent will add ".png") scenes["s2/image_name"] = "out_pipeline_ex1_contour_blah" # print our full actions tree print(actions.to_yaml()) # execute the actions a.execute(actions) # now exec w/o s1 scenes.remove(path="s1") # print our full actions tree print(actions.to_yaml()) # execute the actions a.execute(actions)
import conduit import conduit.blueprint import ascent import numpy as np mesh = conduit.Node() conduit.blueprint.mesh.examples.braid("hexs", 25, 25, 25, mesh) # Use Ascent to create and render multiple pipelines a = ascent.Ascent() a.open() # publish mesh to ascent a.publish(mesh); # setup actions actions = conduit.Node() add_act = actions.append() add_act["action"] = "add_pipelines" pipelines = add_act["pipelines"] # create our first pipeline (pl1) # with a contour filter (f1) pipelines["pl1/f1/type"] = "contour" # extract contours where braid variable
def jupyter_extract(): global global_dict server = None # this runs once per simulation if "server_ascent" not in global_dict: ascent_opts = conduit.Node() if global_dict["MPI_ENABLED"]: comm = MPI.Comm.f2py(ascent_extract.ascent_mpi_comm_id()) ascent_opts["mpi_comm"].set(comm.py2f()) server_ascent = ascent.mpi.Ascent() global_dict["comm"] = comm else: server_ascent = ascent.Ascent() ascent_opts["actions_file"] = "" server_ascent.open(ascent_opts) global_dict["server_ascent"] = server_ascent # we have an inception ref count flow issue here # so we use set_external until we better understand # the cause pub_data = conduit.Node() pub_data.update_external(ascent_extract.ascent_data()) global_dict["server_ascent"].publish(pub_data) def display_images(info): nonlocal server for img in info["images"].children(): with open(img.node()["image_name"], 'rb') as f: img_content = f.read() server._write_bytes_image(img_content, "png") def get_encoded_images(info): images = [] for img in info["images"].children(): with open(img.node()["image_name"], 'rb') as f: images.append(encodebytes(f.read()).decode('utf-8')) return images def run_transformation(transformation, info, *args, **kwargs): render = None #get the first render for child in info["actions"].children(): if child.node()["action"] == "add_scenes": render = child.node()["scenes"][0]["renders"][0] break if render is None: print("ERROR: no scenes found") # keeps the defaults from info['actions'] render.update(transformation(info, *args, **kwargs)) # TODO this is temporary render["image_name"] = "out_ascent_render_3d" return info["actions"] #TODO why doesn't if rank==0 at the top work? def handle_message(message): nonlocal server with server._redirect(): server_ascent = global_dict['server_ascent'] info = conduit.Node() server_ascent.info(info) data = message["code"] if data["type"] == "transform": call_obj = data["code"] # TODO i shouldn't import everything into this file # eval args args = [] for arg in call_obj["args"]: args.append(eval(arg)) # TODO eval kwargs kwargs = call_obj["kwargs"] actions = run_transformation( utils.utils_dict[call_obj["name"]], info, *args, **kwargs) server_ascent.execute(actions) server.root_writemsg({"type": "transform"}) elif data["type"] == "get_images": server.root_writemsg({ "type": "images", "code": get_encoded_images(info), }) elif data["type"] == "get_ascent_info": server.root_writemsg({ "type": "ascent_info", "code": info.to_json(), }) elif data["type"] == "next": server_ascent.publish(ascent_extract.ascent_data()) server_ascent.execute(info['actions']) server.root_writemsg({"type": "next"}) my_prefix = "%s_%s" % (os.path.splitext(os.path.basename( sys.argv[0]))[0], socket.gethostname()) my_ns = { 'display_images': display_images, 'conduit': conduit, 'ascent_data': ascent_extract.ascent_data, 'jupyter_ascent': global_dict['server_ascent'], } if global_dict["MPI_ENABLED"]: my_ns['MPI'] = MPI my_ns['ascent_mpi_comm_id'] = ascent_extract.ascent_mpi_comm_id server = MPIServer(comm=global_dict["comm"], ns=my_ns, callback=handle_message, prefix=my_prefix) else: server = MPIServer(comm=None, ns=my_ns, callback=handle_message, prefix=my_prefix) server.serve()
def test_about(self): print(ascent.about()) s = ascent.Ascent()