diff --git a/samples/notebooks/Lightweight Python components - basics.ipynb b/samples/notebooks/Lightweight Python components - basics.ipynb index 7328ae0b9ce..a36f13dd2e4 100644 --- a/samples/notebooks/Lightweight Python components - basics.ipynb +++ b/samples/notebooks/Lightweight Python components - basics.ipynb @@ -103,7 +103,7 @@ "#Advanced function\n", "#Demonstrates imports, helper functions and multiple outputs\n", "from typing import NamedTuple\n", - "def my_divmod(dividend: float, divisor:float, output_dir:str = './') -> NamedTuple('MyDivmodOutput', [('quotient', float), ('remainder', float)]):\n", + "def my_divmod(dividend: float, divisor:float) -> NamedTuple('MyDivmodOutput', [('quotient', float), ('remainder', float)]):\n", " '''Divides two numbers and calculate the quotient and remainder'''\n", " #Imports inside a component function:\n", " import numpy as np\n", @@ -114,8 +114,12 @@ "\n", " (quotient, remainder) = divmod_helper(dividend, divisor)\n", "\n", - " from tensorflow.python.lib.io import file_io\n", " import json\n", + " from pathlib import Path\n", + "\n", + " #FIX: Metadata and metrics should be output like all other outputs\n", + " ui_metadata_output_path='/mlpipeline-ui-metadata.json'\n", + " metrics_output_path='/mlpipeline-metrics.json'\n", " \n", " # Exports a sample tensorboard:\n", " metadata = {\n", @@ -124,8 +128,10 @@ " 'source': 'gs://ml-pipeline-dataset/tensorboard-train',\n", " }]\n", " }\n", - " with open(output_dir + 'mlpipeline-ui-metadata.json', 'w') as f:\n", - " json.dump(metadata, f)\n", + " metadata_text = json.dumps(metadata)\n", + " metadata_path = Path(ui_metadata_output_path)\n", + " metadata_path.parent.mkdir(parents=True, exist_ok=True)\n", + " metadata_path.write_text(metadata_text) #FIX: Remove explicit writing once artifact handling is fixed in the compiler\n", "\n", " # Exports two sample metrics:\n", " metrics = {\n", @@ -136,9 +142,10 @@ " 'name': 'remainder',\n", " 'numberValue': float(remainder),\n", " }]}\n", - "\n", - " with file_io.FileIO(output_dir + 'mlpipeline-metrics.json', 'w') as f:\n", - " json.dump(metrics, f)\n", + " metrics_text = json.dumps(metadata)\n", + " metrics_path = Path(metrics_output_path)\n", + " metrics_path.parent.mkdir(parents=True, exist_ok=True)\n", + " metrics_path.write_text(metrics_text)\n", "\n", " from collections import namedtuple\n", " divmod_output = namedtuple('MyDivmodOutput', ['quotient', 'remainder'])\n", @@ -208,7 +215,7 @@ " \n", " #Passing a task output reference as operation arguments\n", " #For an operation with a single return value, the output reference can be accessed using `task.output` or `task.outputs['output_name']` syntax\n", - " divmod_task = divmod_op(add_task.output, b, '/')\n", + " divmod_task = divmod_op(add_task.output, b)\n", "\n", " #For an operation with a multiple return values, the output references can be accessed using `task.outputs['output_name']` syntax\n", " result_task = add_op(divmod_task.outputs['quotient'], c)"