def test_handler_hyperlist(): run_spec = tag_test(base_spec, 'test_handler_hyperlist') run_spec.spec.param_file = 'param_file.csv' result = run_start(run_spec, handler=my_func, rundb=rundb_path) print(result) assert len(result.status.iterations) == 3+1, 'hyper parameters test failed' verify_state(result)
def run_operator(): import yaml import json from mlrun import get_or_create_ctx, run_start context = get_or_create_ctx('sparkk8s') sparkk8s_spec = context.get_param('sparkk8sspec', {}) # IGUAZIO environment AUTH_SECRET = sparkk8s_spec.get('metadata.AUTH_SECRET', "shell-um81v5npue-qh8oc-v3io-auth") FUSE_SECRET = sparkk8s_spec.get('metadata.FUSE_SECRET', "shell-um81v5npue-qh8oc-v3io-fuse") rundb = sparkk8s_spec.get('rundb', '') run_start(runtime=sparkk8s_spec, rundb=rundb, command='sparkk8s://')
def test_handler_hyper(): run_spec = tag_test(base_spec, 'test_handler_hyper') run_spec.with_hyper_params({'p1': [1, 2, 3]}) result = run_start(run_spec, handler=my_func, rundb=rundb_path) print(result) assert len(result.status.iterations) == 3+1, 'hyper parameters test failed' verify_state(result)
def test_simple_function(): _thread.start_new_thread(create_function, (myfunction, 4444)) time.sleep(2) spec = tag_test(basespec, 'simple_function') result = run_start(spec, command='http://localhost:4444', rundb=rundb_path) print(result) verify_state(result)
def test_handler_project(): spec = tag_test(base_spec, 'test_handler_project') spec.metadata.project = 'myproj' spec.metadata.labels = {'owner': 'yaronh'} result = run_start(spec, handler=my_func, rundb=rundb_path) print(result) assert result.output('accuracy') == 16, 'failed to run' verify_state(result)
def test_simple_function(): Thread(target=create_function, args=(myfunction, 4444)).start() time.sleep(2) spec = tag_test(base_spec, 'simple_function') result = run_start(spec, command='http://localhost:4444', rundb=rundb_path) print(result) verify_state(result)
def test_hyper_function(): _thread.start_new_thread(create_function, (myfunction, 4444)) time.sleep(2) spec = tag_test(basespec, 'hyper_function') spec['spec']['hyperparams'] = {'p1': [1, 2, 3]} result = run_start(spec, command='http://localhost:4444', rundb=rundb_path) print(result) verify_state(result)
def test_hyper_function(): Thread(target=create_function, args=(myfunction, 4444)) time.sleep(2) spec = tag_test(base_spec, 'hyper_function') spec.spec.hyperparams = {'p1': [1, 2, 3]} result = run_start(spec, command='http://localhost:4444', rundb=rundb_path) print(result) verify_state(result)
def test_kfp_run(): tmpdir = mktemp() spec = run_spec.copy() spec.spec.output_path = tmpdir print(tmpdir) result = run_start(spec, handler=my_job, rundb=rundb_path, kfp=True) print(result.status.output_artifacts) alist = listdir(tmpdir) expected = ['chart.html', 'dataset.csv', 'model.txt', 'results.html'] for a in expected: assert a in alist, 'artifact {} was not generated'.format(a) assert result.output('accuracy') == 10, 'failed to run' assert result.status.state == 'completed', \ 'wrong state ({}) {}'.format(result.status.state, result.status.error)
def test_kfp_hyper(): tmpdir = mktemp() spec = run_spec.copy() spec.spec.output_path = tmpdir spec.spec.hyperparams = {'p1': [1, 2, 3]} print(tmpdir) result = run_start(spec, handler=my_job, rundb=rundb_path, kfp=True) alist = listdir(tmpdir) print(alist) print(listdir('/tmp')) with open('/tmp/iterations') as fp: iter = json.load(fp) print(yaml.dump(iter)) assert len(iter) == 3+1, 'didnt see expected iterations file output' assert result.status.state == 'completed', \ 'wrong state ({}) {}'.format(result.status.state, result.status.error)
#!/usr/bin/env python # coding: utf-8 # In[2]: import yaml import json from mlrun import get_or_create_ctx, run_start context = get_or_create_ctx('sparkk8s') sparkk8s_spec = context.get_param('sparkk8sspec', {}) # IGUAZIO environment AUTH_SECRET = sparkk8s_spec.get('metadata.AUTH_SECRET', "shell-um81v5npue-qh8oc-v3io-auth") FUSE_SECRET = sparkk8s_spec.get('metadata.FUSE_SECRET', "shell-um81v5npue-qh8oc-v3io-fuse") rundb = sparkk8s_spec.get('rundb', '') run_start(runtime=sparkk8s_spec, rundb=rundb, command='sparkk8s://')
def test_local_runtime(): spec = tag_test(base_spec, 'test_local_runtime') result = run_start(spec, command='{}/training.py'.format(examples_path), rundb=rundb_path) verify_state(result)
def test_with_params_s3(): spec = tag_test(s3_spec, 'test_with_params') result = run_start(spec, handler=my_func, rundb=rundb_path) assert result.output('accuracy') == 16, 'failed to run' assert result.status.output_artifacts[0].get('key') == 'chart', 'failed to run'
def test_noparams(): environ['MLRUN_META_DBPATH'] = rundb_path result = run_start(None, handler=my_func) assert result.output('accuracy') == 2, 'failed to run' assert result.status.output_artifacts[0].get('key') == 'chart', 'failed to run'
def test_local_no_context(): spec = tag_test(base_spec, 'test_local_no_context') result = run_start(spec, command='{}/no_ctx.py'.format(here), rundb=rundb_path, mode='noctx') verify_state(result)
def test_local_handler(): spec = tag_test(base_spec, 'test_local_runtime') result = run_start(spec, command='{}/handler.py:my_func'.format(examples_path), rundb=rundb_path) verify_state(result)