How to use papermill - 10 common examples

To help you get started, we’ve selected a few papermill examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nteract / papermill / papermill / translators.py View on Github external
    @classmethod
    def translate_list(cls, val):
        """Translate list to scala Seq"""
        escaped = ', '.join([cls.translate(v) for v in val])
        return 'Seq({})'.format(escaped)

    @classmethod
    def comment(cls, cmt_str):
        return '// {}'.format(cmt_str).strip()

    @classmethod
    def assign(cls, name, str_val):
        return 'val {} = {}'.format(name, str_val)


class JuliaTranslator(Translator):
    @classmethod
    def translate_none(cls, val):
        return 'nothing'

    @classmethod
    def translate_dict(cls, val):
        escaped = ', '.join(
            ["{} => {}".format(cls.translate_str(k), cls.translate(v)) for k, v in val.items()]
        )
        return 'Dict({})'.format(escaped)

    @classmethod
    def translate_list(cls, val):
        escaped = ', '.join([cls.translate(v) for v in val])
        return '[{}]'.format(escaped)
github nteract / papermill / papermill / translators.py View on Github external
    @classmethod
    def translate_list(cls, val):
        """Translate list to array"""
        escaped = ', '.join([cls.translate(v) for v in val])
        return 'new [] {{ {} }}'.format(escaped)

    @classmethod
    def comment(cls, cmt_str):
        return '// {}'.format(cmt_str).strip()

    @classmethod
    def assign(cls, name, str_val):
        return 'var {} = {};'.format(name, str_val)


class FSharpTranslator(Translator) :

    @classmethod
    def translate_none(cls, val) :
        return 'None'

    @classmethod
    def translate_bool(cls, val) :
        return 'true' if val else 'false'

    @classmethod
    def translate_int(cls, val):
        strval = cls.translate_raw_str(val)
        return strval + "L" if (val > 2147483647 or val < -2147483648) else strval

    @classmethod
    def translate_dict(cls, val):
github nteract / papermill / tests / test_execute.py View on Github external
def test(self):
        nb_test1_fname = get_notebook_path('simple_execute.ipynb')
        nb_test1_executed_fname = os.path.join(self.test_dir, 'test1_executed.ipynb')
        execute_notebook(nb_test1_fname, nb_test1_executed_fname, {'msg': 'Hello'})
        test_nb = read_notebook(nb_test1_executed_fname)
        self.assertEqual(test_nb.node.cells[0].get('source'), u'# Parameters\nmsg = "Hello"\n')
        self.assertEqual(test_nb.parameters, {'msg': 'Hello'})
github nteract / papermill / tests / test_execute.py View on Github external
def test(self):
        path = get_notebook_path('broken.ipynb')
        result_path = os.path.join(self.test_dir, 'broken.ipynb')
        execute_notebook(path, result_path)
        nb = read_notebook(result_path)
        self.assertEqual(nb.node.cells[0].execution_count, 1)
        self.assertEqual(nb.node.cells[1].execution_count, 2)
        self.assertEqual(nb.node.cells[1].outputs[0].output_type, 'error')
        self.assertEqual(nb.node.cells[2].execution_count, None)
github interpretml / interpret-community / test / test_notebooks.py View on Github external
def test_advanced_feature_transformations_explain_local():

    notebookname = "advanced-feature-transformations-explain-local"
    input_notebook = "notebooks/" + notebookname + ".ipynb"
    output_notebook = "./test/" + notebookname + ".output.ipynb"

    pm.execute_notebook(input_notebook, output_notebook)

    nb = sb.read_notebook(input_notebook)
    nb.scraps  # print a dict of all scraps by name

    return
github microsoft / nlp-recipes / tests / integration / test_notebooks_sentence_similarity.py View on Github external
def test_gensen_aml_deep_dive(notebooks):
    notebook_path = notebooks["gensen_aml_deep_dive"]
    pm.execute_notebook(
        notebook_path,
        OUTPUT_NOTEBOOK,
        parameters=dict(
            CACHE_DIR="./tests/integration/temp",
            AZUREML_CONFIG_PATH="./tests/integration/.azureml",
            UTIL_NLP_PATH="./utils_nlp",
            MAX_EPOCH=1,
            TRAIN_SCRIPT="./examples/sentence_similarity/gensen_train.py",
            CONFIG_PATH="./examples/sentence_similarity/gensen_config.json",
            MAX_TOTAL_RUNS=1,
            MAX_CONCURRENT_RUNS=1,
        ),
    )
    result = sb.read_notebook(OUTPUT_NOTEBOOK).scraps.data_dict
    assert result["min_val_loss"] > 5
    assert result["learning_rate"] >= 0.0001
github microsoft / nlp-recipes / tests / integration / test_notebooks_interpretability.py View on Github external
def test_deep_and_unified_understanding(notebooks):
    notebook_path = notebooks["deep_and_unified_understanding"]
    pm.execute_notebook(
        notebook_path,
        OUTPUT_NOTEBOOK,
        kernel_name=KERNEL_NAME)
    
    result = sb.read_notebook(OUTPUT_NOTEBOOK).scraps.data_dict
    sigma_numbers = [0.00317593, 0.00172284, 0.00634005, 0.00164305, 0.00317159]
    sigma_bert = [0.1735696 , 0.14028822, 0.14590865, 0.2263149 , 0.20640415,
       0.21249843, 0.18685372, 0.14112663, 0.25824168, 0.22399105,
       0.2393731 , 0.12868434, 0.27386534, 0.35876372]
    
    np.testing.assert_array_almost_equal(result["sigma_numbers"], sigma_numbers, decimal=3) 
    np.testing.assert_array_almost_equal(result["sigma_bert"], sigma_bert, decimal=1)
github microsoft / computervision-recipes / tests / integration / classification / test_integration_classification_notebooks.py View on Github external
def test_03_notebook_run(classification_notebooks):
    notebook_path = classification_notebooks["03_training_accuracy_vs_speed"]
    pm.execute_notebook(
        notebook_path,
        OUTPUT_NOTEBOOK,
        parameters=dict(PM_VERSION=pm.__version__),
        kernel_name=KERNEL_NAME,
    )

    nb_output = sb.read_notebook(OUTPUT_NOTEBOOK)
    assert len(nb_output.scraps["training_accuracies"].data) == 12
    assert nb_output.scraps["training_accuracies"].data[-1] > 0.70
    assert nb_output.scraps["validation_accuracy"].data > 0.70
github microsoft / computervision-recipes / tests / smoke / test_azureml_notebooks.py View on Github external
def test_od_20_notebook_run(
    detection_notebooks,
    subscription_id,
    resource_group,
    workspace_name,
    workspace_region,
):
    notebook_path = detection_notebooks["20_deployment_on_kubernetes"]
    pm.execute_notebook(
        notebook_path,
        OUTPUT_NOTEBOOK,
        parameters=dict(
            PM_VERSION=pm.__version__,
            subscription_id=subscription_id,
            resource_group=resource_group,
            workspace_name=workspace_name,
            workspace_region=workspace_region,
        ),
        kernel_name=KERNEL_NAME,
    )
github microsoft / nlp-recipes / tests / integration / test_notebooks_dataset.py View on Github external
def test_msrpc_runs(notebooks):
    notebook_path = notebooks["msrpc"]
    pm.execute_notebook(
        notebook_path,
        OUTPUT_NOTEBOOK,
        kernel_name=KERNEL_NAME,
    )