HyFI Template Example#
This Jupyter Notebook demonstrates the usage of the hyfi_template
package, including initializing a workspace, mounting Google Drive on Colab, and using HyFI to manage configurations.
First, let’s import the necessary functions and classes from the hyfi_template
package.
from hyfi_template import get_version, HyFI
/home/yjlee/.cache/pypoetry/virtualenvs/hyfi-template-_RhRudZi-py3.8/lib/python3.8/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from .autonotebook import tqdm as notebook_tqdm
Check Version#
Now, let’s get the version of the hyfi_template
package.
version = get_version()
print("HyFI Template version:", version)
HyFI Template version: 0.1.5
Initialize Workspace#
We’ll initialize the workspace using the HyFI.init_workspace
function. The function takes the following parameters:
workspace
: The root workspace directory.project
: The project subdirectory.task
: The specific task within the project.log_level
: Logging level for the workspace.verbose
: Whether to print verbose messages.
We’ll check if we’re running in Google Colab, and if so, we’ll mount Google Drive.
if HyFI.is_colab():
HyFI.mount_google_drive()
ws = HyFI.init_workspace(
workspace="/workspace",
project="hyfi-template/examples",
task="test",
log_level="INFO",
verbose=True,
)
print("version:", ws.version)
print("project_dir:", ws.project_dir)
INFO:hyfi.utils.notebook:Extension autotime not found. Install it first.
INFO:hyfi.env:config_module: hyfi.conf
INFO:hyfi.env:compose config with overrides: ['+project=__init__']
INFO:hyfi.env:initialized batcher with <hyfi.utils.batch.batcher.Batcher object at 0x7f5b4a1cafd0>
version: 0.1.5
project_dir: /workspace/projects/hyfi-template/examples
Compose Configuration#
We can use the HyFI.compose
function to load a configuration file. In this example, we’ll use the default configuration by specifying path=__default__
.
cfg = HyFI.compose("path=__default__")
INFO:hyfi.env:config_module: hyfi_template.conf
INFO:hyfi.env:compose config with overrides: ['+path=__default__']
Display Configuration#
Now, let’s print the loaded configuration using the HyFI.print
function.
HyFI.print(cfg)
{'cache_dir': '/workspace/projects/hyfi-template/examples/default-task/cache',
'data_dir': '/workspace/projects/hyfi-template/examples/default-task/data',
'library_dir': '/workspace/projects/hyfi-template/examples/default-task/libs',
'log_dir': '/workspace/projects/hyfi-template/examples/default-task/logs',
'model_dir': '/workspace/projects/hyfi-template/examples/default-task/models',
'output_dir': '/workspace/projects/hyfi-template/examples/default-task/outputs',
'root': '/workspace/projects/hyfi-template/examples/default-task',
'task_name': 'default-task',
'tmp_dir': '/workspace/projects/hyfi-template/examples/default-task/tmp',
'verbose': False}
That’s it! This example demonstrated the basic usage of the hyfi_template
package. You can now use this package to manage your own projects and tasks in a structured manner.