Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Support save and open experiments #2750

Merged
merged 27 commits into from
Aug 12, 2020

Conversation

SparkSnail
Copy link
Contributor

No description provided.

@scarlett2018 scarlett2018 mentioned this pull request Jul 31, 2020
66 tasks
|Name, shorthand|Required|Default|Description|
|------|------|------ |------|
|--path, -p| True| |the full file path of nni package|
|--codeDir, -c| True| |the path of codeDir|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could add more description for codeDir. for example, "the path that you want to put the code of the saved experiment into". BTW, what if the saved experiment does not include code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, if the experiment package does not code files, NNI will do nothing, just use new codeDir to replace old one.

parser_save_data.set_defaults(func=save_experiment)
#open experiment data
parser_open_data = parser_experiment_subparsers.add_parser('load', help='load experiment data')
parser_open_data.add_argument('--path', '-p', required=True, help='the path of nni package file')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to make it consistent with the doc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment on lines 755 to 757
logDir = os.path.join(os.path.expanduser("~"), 'nni-experiments', args.id)
if nni_config.get_config('logDir'):
logDir = os.path.join(nni_config.get_config('logDir'), args.id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to use a function to generate logDir, this function can be put in a file which store constants or meta-datas. 'nni-experiments' can be seen as a type of metadata

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


# Step2. Copy nnictl metadata to temp folder
temp_nnictl_dir = os.path.join(temp_root_dir, 'nnictl')
os.makedirs(temp_nnictl_dir, exist_ok=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible that the dir already existed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the dir name is generate by random() function, will not exist logically, I also add logic to handle this scenario, if the dir exist, nni will regenerate a new dir until it is not existed originally.

# Step4. Copy code dir
codeDir = os.path.expanduser(args.codeDir)
if not os.path.isabs(codeDir):
codeDir = os.path.join(os. getcwd(), codeDir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os. getcwd()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

additional whitespace after dot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the path is not a full path, nnictl will use current folder as a root path to find files.updated to os.getcwd()

temp_dir = generate_folder_name()
while os.path.exists(temp_dir):
temp_dir = generate_folder_name()
os.makedirs(temp_dir, exist_ok=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as temp_dir does not exist, so it is ok to remove exist_ok=True?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, updated

if nnictl_exp_config.get('logDir'):
logDir = nnictl_exp_config['logDir']
else:
logDir = os.path.join(os.path.expanduser("~"), 'nni-experiments')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also use NNICTL_HOME_DIR here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

exit(1)
temp_root_dir = generate_temp_dir()
shutil.unpack_archive(package_path, temp_root_dir)
print_normal('Opening...')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading... is better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

experiment_metadata.get('experimentName'),
experiment_metadata.get('endTime'),
experiment_metadata.get('status'))
print_normal('Open experiment %s succsss!' % experiment_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open -> Load ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

codeDir = os.path.join(os.getcwd(), codeDir)
print_normal('Expand codeDir to %s' % codeDir)
nnictl_exp_config['trial']['codeDir'] = codeDir
archive_code_dir = os.path.join(temp_root_dir, 'code')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not copy entire 'code' dir using shutil.copytree?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shutil.copytree only support copy entire folder to another folder, does not support merging two folder contents. We need to copy the contents under code folder, and do not change target folder name.

@SparkSnail SparkSnail merged commit d5072a2 into microsoft:master Aug 12, 2020
LovPe pushed a commit to LovPe/nni that referenced this pull request Aug 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants