Skip to content

Commit

Permalink
Samples/Notebooks - Partially restored the lightweight components sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark-kun committed Dec 18, 2018
1 parent 19e7ff2 commit 06513c9
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions samples/notebooks/Lightweight Python components - basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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)"
Expand Down

0 comments on commit 06513c9

Please sign in to comment.