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

support package install #91

Merged
merged 8 commits into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tools/nnicmd/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@
'4. nnictl trial kill kill a trial job by id\n' \
'5. nnictl --help get help information about nnictl\n' \
'6. nnictl webui url get the url of web ui'

PACKAGE_REQUIREMENTS = {
'SMAC': {'install':['git+https://github.com/QuanluZhang/ConfigSpace.git','git+https://github.com/QuanluZhang/SMAC3.git'],
'uninstall':['ConfigSpace', 'smac']}
}
19 changes: 17 additions & 2 deletions tools/nnicmd/nnictl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
from .launcher import create_experiment, resume_experiment
from .updater import update_searchspace, update_concurrency, update_duration
from .nnictl_utils import *
from .package_management import *

def nni_help_info(*args):
print('please run "nnictl --help" to see nnictl guidance')

def parse_args():
'''Definite the arguments users need to follow and input'''
parser = argparse.ArgumentParser(prog='nni ctl', description='use nni control')
parser = argparse.ArgumentParser(prog='nnictl', description='use nnictl command to control nni experiments')
parser.set_defaults(func=nni_help_info)

# create subparsers for args with sub values
Expand Down Expand Up @@ -104,7 +105,7 @@ def parse_args():

#parse log command
parser_log = subparsers.add_parser('log', help='get log information')
# add subparsers for parser_rest
# add subparsers for parser_log
parser_log_subparsers = parser_log.add_subparsers()
parser_log_stdout = parser_log_subparsers.add_parser('stdout', help='get stdout information')
parser_log_stdout.add_argument('--tail', '-T', dest='tail', type=int, help='get tail -100 content of stdout')
Expand All @@ -117,6 +118,20 @@ def parse_args():
parser_log_stderr.add_argument('--path', '-p', action='store_true', default=False, help='get the path of stderr file')
parser_log_stderr.set_defaults(func=log_stderr)

#parse package command
parser_package = subparsers.add_parser('package', help='control nni tuner and assessor packages')
# add subparsers for parser_package
parser_package_subparsers = parser_package.add_subparsers()
parser_package_install = parser_package_subparsers.add_parser('install', help='install packages')
parser_package_install.add_argument('--name', '-n', dest='name', choices=['SMAC'], help='package name to be installed')
parser_package_install.set_defaults(func=package_install)
parser_package_uninstall = parser_package_subparsers.add_parser('uninstall', help='uninstall packages')
parser_package_uninstall.add_argument('--name', '-n', dest='name', choices=['SMAC'], help='package name to be uninstalled')
parser_package_uninstall.set_defaults(func=package_uninstall)
parser_package_show = parser_package_subparsers.add_parser('show', help='show the information of packages')
parser_package_show.set_defaults(func=package_show)


args = parser.parse_args()
args.func(args)

Expand Down
52 changes: 52 additions & 0 deletions tools/nnicmd/package_management.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright (c) Microsoft Corporation
# All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge,
# to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and
# to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import nni
import os
from subprocess import call
from .constants import PACKAGE_REQUIREMENTS
from .common_utils import print_normal

def manage_smac(mode):
Copy link
Contributor

Choose a reason for hiding this comment

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

refactor the code in this file.

if mode == 'install':
for package in PACKAGE_REQUIREMENTS.get('SMAC').get('install'):
print_normal('installing ' + package)
cmds = ['pip3', 'install', '--user', package]
call(cmds)
else:
for package in PACKAGE_REQUIREMENTS.get('SMAC').get('uninstall'):
print_normal('uninstalling ' + package)
cmds = ['pip3', 'uninstall', '-y', package]
call(cmds)

def package_install(args):
'''install packages'''
if args.name == 'SMAC':
manage_smac('install')

def package_uninstall(args):
'''uninstall packages'''
if args.name == 'SMAC':
manage_smac('uninstall')

def package_show(args):
'''show all packages'''
print(' '.join(PACKAGE_REQUIREMENTS.keys()))