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

fix experiment import bug and add it cases: experiment import #2878

Merged
merged 4 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion docs/en_US/TrialExample/SklearnExamples.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ It is easy to use NNI in your scikit-learn code, there are only a few steps.
"kernel": {"_type":"choice","_value":["linear", "rbf", "poly", "sigmoid"]},
"degree": {"_type":"choice","_value":[1, 2, 3, 4]},
"gamma": {"_type":"uniform","_value":[0.01, 0.1]},
"coef0 ": {"_type":"uniform","_value":[0.01, 0.1]}
"coef0": {"_type":"uniform","_value":[0.01, 0.1]}
}
```

Expand Down
2 changes: 1 addition & 1 deletion examples/trials/sklearn/classification/search_space.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"kernel": {"_type":"choice","_value":["linear", "rbf", "poly", "sigmoid"]},
"degree": {"_type":"choice","_value":[1, 2, 3, 4]},
"gamma": {"_type":"uniform","_value":[0.01, 0.1]},
"coef0 ": {"_type":"uniform","_value":[0.01, 0.1]}
"coef0": {"_type":"uniform","_value":[0.01, 0.1]}
}
1 change: 1 addition & 0 deletions src/sdk/pynni/nni/msg_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def handle_import_data(self, data):
data: a list of dictionaries, each of which has at least two keys, 'parameter' and 'value'
"""
for entry in data:
entry['value'] = entry['value'] if type(entry['value']) is str else json_tricks.dumps(entry['value'])
entry['value'] = json_tricks.loads(entry['value'])
self.tuner.import_data(data)

Expand Down
7 changes: 7 additions & 0 deletions test/config/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ testCases:
validator:
class: ExportValidator

- name: experiment-import
configFile: test/config/nnictl_experiment/sklearn-classification.yml
validator:
class: ImportValidator
kwargs:
import_data_file_path: config/nnictl_experiment/test_import.json

- name: nnicli
configFile: test/config/examples/sklearn-regression.yml
config:
Expand Down
23 changes: 23 additions & 0 deletions test/config/nnictl_experiment/sklearn-classification.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
authorName: nni
experimentName: default_test
maxExecDuration: 5m
maxTrialNum: 4
trialConcurrency: 2
searchSpacePath: ../../../examples/trials/sklearn/classification/search_space.json

tuner:
builtinTunerName: TPE
assessor:
builtinAssessorName: Medianstop
classArgs:
optimize_mode: maximize
trial:
codeDir: ../../../examples/trials/sklearn/classification
command: python3 main.py
gpuNum: 0

useAnnotation: false
multiPhase: false
multiThread: false

trainingServicePlatform: local
4 changes: 4 additions & 0 deletions test/config/nnictl_experiment/test_import.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
{"parameter": {"C": 0.15940134774738896, "kernel": "sigmoid", "degree": 3, "gamma": 0.07295826917955316, "coef0": 0.0978204758732429}, "value": 0.6},
{"parameter": {"C": 0.5556430724708544, "kernel": "linear", "degree": 3, "gamma": 0.04957496655414671, "coef0": 0.08520868779907687}, "value": 0.7}
]
8 changes: 8 additions & 0 deletions test/nni_test/nnitest/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ def __call__(self, rest_endpoint, experiment_dir, nni_source_dir, **kwargs):
print('\n\n')
remove('report.json')

class ImportValidator(ITValidator):
def __call__(self, rest_endpoint, experiment_dir, nni_source_dir, **kwargs):
exp_id = osp.split(experiment_dir)[-1]
import_data_file_path = kwargs.get('import_data_file_path')
proc = subprocess.run(['nnictl', 'experiment', 'import', exp_id, '-f', import_data_file_path])
assert proc.returncode == 0, \
'`nnictl experiment import {0} -f {1}` failed with code {2}'.format(exp_id, import_data_file_path, proc.returncode)
Copy link
Contributor

Choose a reason for hiding this comment

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

Any other means to verify the data is actually imported successfully besides checking the return 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.

I'll view the code again to find if there is a way to check the result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In order to check the imported data, add an api api/v1/nni/experiment/imported-data to get the imported data. I don't know if it is appropriate to do so. Maybe users also have demand to view the data they have imported?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is OK to call api/v1/nni/experiment/imported-data to verify


class MetricsValidator(ITValidator):
def __call__(self, rest_endpoint, experiment_dir, nni_source_dir, **kwargs):
self.check_metrics(nni_source_dir, **kwargs)
Expand Down