Brigitte Maillère
Brigitte Maillère

Reputation: 865

Papermill + Scrapbook : is it possible to reglue text in papermill notebook?

I use a Papermill notebook ("orchester_notebook") to launch multiple times a "training_notebook" with different sets of parameters.

For each set of parameters, a new "result_notebook" is saved with printed results (text) and figures.

I know how to display the figure from the "result_notebook" in my "orchester notebook"

but I wish to also display the text results (accuracy, classification report,....) in my "orchester_notebook".

Do you know if it is possible to reglue text via scrapbook ?

my code below :

orchestrer_notebook

import papermill as pm
import scrapbook as sb

experiment_dates = [20190101, 20190102]
features = 'my_features'
model = 'my_model'
parameters = dict({'experiment_dates' : experiment_dates, 'features' : 
features, 'model' : model})

output_filename = str(experiment_dates) + '_' + features + model

pm.execute_notebook('Training.ipynb', output_filename + '.ipynb', 
parameters=parameters)

out = sb.read_notebook(output_filename + '.ipynb')
out.reglue('figure')

training_notebook

import scrapbook as sb

# training
#...........
#............

fig, ax = plt.subplots()
ax.plot(data.index, data['mydata'], c='k', alpha=.5)
sb.glue('figure', fig, 'display')

print("this is my results") # how can I reglue this in orchestrer_notebook ?

Upvotes: 2

Views: 243

Answers (2)

Brigitte Maillère
Brigitte Maillère

Reputation: 865

The answer above doesn't work for me, I read this other doc part and the below solution works for me :

in the training notebook :

sb.glue("media_as_text_only",
  media_obj,
  encoder='display',
  display=('text/plain',) # This passes [text/plain] to format_display_data's include argument
)

in the orchetrer notebook :

out.reglue("media_as_text_only")

Upvotes: 0

Brigitte Maillère
Brigitte Maillère

Reputation: 865

I missed this in the doc :

"""glue example for recording data values"""
import scrapbook as sb

sb.glue("hello", "world") # this answers my need to reglue text
sb.glue("number", 123)
sb.glue("some_list", [1, 3, 5])
sb.glue("some_dict", {"a": 1, "b": 2})
sb.glue("non_json", df, 'arrow')

Upvotes: 2

Related Questions