Flow name: FlowName (uses latest successful run and end step)
When using partial pathspecs, the extension will resolve them to a unique task. If multiple tasks exist (e.g., from a foreach), you must specify the full pathspec.
path_components = pathspec.split("/")if not path_components: raise CommandException("Provide either a flow, run, step or task to debug")if len(path_components) < 2: # Flow name only - get latest successful run r = Flow(path_components[0]).latest_successful_run if r is None: raise CommandException( "Flow {} can only be specified if there is a successful run in the " "current namespace.".format(path_components[0]) ) path_components.append(r.id)if len(path_components) < 3: # No step specified - use 'end' step path_components.append("end")if len(path_components) < 4: # Enforce single task cur_task = None for t in r[path_components[2]]: if cur_task is not None: raise CommandException( "Step {} does not refer to a single task -- please specify the " "task unambiguously".format("/".join(path_components)) ) cur_task = t
The _escape_trampolines directory contains Python modules that override Metaflow internals to enable artifact access outside of a running task. This is generated using:
from metaflow.plugins.env_escape import generate_trampolinesgenerate_trampolines(trampoline_dir)
In the notebook, artifacts are accessible through the self object:
# Access input artifactsprint(self.input['n_estimators'])print(self.input['learning_rate'])# Access data artifactsprint(self.features.shape)print(self.labels.shape)# Access any artifact from the taskprint(self.index)
conda_command = [ "metaflow", "environment", "--quiet", "create", "--name", mf_env_name, "--install-notebook", "--force",]conda_command.extend(mf_env)result = subprocess.run( conda_command, check=True, capture_output=True,)# Parse the python path from stderrfor line in result.stderr.decode().split("\n"): if "/bin/python" in line: mf_python_path = line break
The extension updates the Jupyter kernel’s configuration to include:
The escape trampolines in PYTHONPATH
Any environment variables needed by the packaged Metaflow version
From debug_cmd.py:315-349:
def _update_kernel_pythonpath(kernelspec_path, metaflow_root_dir): kernel_json_path = os.path.join(kernelspec_path, "kernel.json") with open(kernel_json_path, "r") as f: kernel_json = json.load(f) _ = kernel_json.setdefault("env", {})["PYTHONPATH"] = os.path.abspath( os.path.join(metaflow_root_dir, "_escape_trampolines") ) for key, value in MetaflowCodeContent.get_env_vars_for_packaged_metaflow( metaflow_root_dir ).items(): if key.endswith(":"): # Override existing value kernel_json["env"][key[:-1]] = value elif key not in kernel_json["env"]: kernel_json["env"][key] = value else: # Prepend to existing value kernel_json["env"][key] = f"{value}:{kernel_json['env'][key]}"
This error occurs when trying to debug a task that was run locally. The debug extension requires a code package, which is only created for remote executions.Solution: Only debug tasks executed on remote compute (e.g., with @batch, @kubernetes, or other remote decorators).
This error occurs when the task used an older version of the Conda decorator.Solution: Re-run your flow with the enhanced Conda V2 decorator included in this package.