From f8460e52a2972823bac486c6cc6e394c65180f85 Mon Sep 17 00:00:00 2001 From: Janis Date: Fri, 28 Dec 2018 01:26:54 +1100 Subject: [PATCH 1/2] Start tutorial about function call serialization --- .../2018-12-28/serializaing_function_calls.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 content/tutorial-pages/2018-12-28/serializaing_function_calls.md diff --git a/content/tutorial-pages/2018-12-28/serializaing_function_calls.md b/content/tutorial-pages/2018-12-28/serializaing_function_calls.md new file mode 100644 index 00000000..7bc48ca0 --- /dev/null +++ b/content/tutorial-pages/2018-12-28/serializaing_function_calls.md @@ -0,0 +1,30 @@ +--- +title: Serializing the state of a function call" +authors: + - "Janis Lesinskis" +date: "2018-12-28" +tags: + - Python + - introspection + - serialization +contentType: "blog" +callToActionText: "Are you looking to improve the architecture of your Python programs? Fill in the form below with some details and one of our Python experts will get back to you." +hideCallToAction: false + +--- + +It comes up occasionally that you want to serialize the state of a function call. For example in the Persephone project we have a few situations where recording the state of a function call is important for reproducible research as results can only be verified by being rerun. + +## Serializing a function call + +The simplest case is where you have a single function call that you wish to serialize the local state of. + +```python +def some_func(msg:str="message", repeat=1, *, padding=0): + s = msg*repeat + return s.ljust(padding) +``` + +The first challenge is getting a snapshot of the code that was executed at the time. A good choice here is to refer to a Git commit with a SHA hash of the code that's being used. This is possible if you use Git and you are running the code from a Git repository. + +If you have an installed package perhaps you can access the version of the package and store that. \ No newline at end of file From d25e8df3bb355cb292afd1457594c2598706084b Mon Sep 17 00:00:00 2001 From: Janis Date: Fri, 28 Dec 2018 01:28:38 +1100 Subject: [PATCH 2/2] Reorganize section ordering --- .../2018-12-28/serializaing_function_calls.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/content/tutorial-pages/2018-12-28/serializaing_function_calls.md b/content/tutorial-pages/2018-12-28/serializaing_function_calls.md index 7bc48ca0..4988084e 100644 --- a/content/tutorial-pages/2018-12-28/serializaing_function_calls.md +++ b/content/tutorial-pages/2018-12-28/serializaing_function_calls.md @@ -15,6 +15,12 @@ hideCallToAction: false It comes up occasionally that you want to serialize the state of a function call. For example in the Persephone project we have a few situations where recording the state of a function call is important for reproducible research as results can only be verified by being rerun. +## Serializing the state of the code + +The first challenge is getting a snapshot of the code that was executed at the time. A good choice here is to refer to a Git commit with a SHA hash of the code that's being used. This is possible if you use Git and you are running the code from a Git repository. + +If you have an installed package perhaps you can access the version of the package and store that. + ## Serializing a function call The simplest case is where you have a single function call that you wish to serialize the local state of. @@ -24,7 +30,3 @@ def some_func(msg:str="message", repeat=1, *, padding=0): s = msg*repeat return s.ljust(padding) ``` - -The first challenge is getting a snapshot of the code that was executed at the time. A good choice here is to refer to a Git commit with a SHA hash of the code that's being used. This is possible if you use Git and you are running the code from a Git repository. - -If you have an installed package perhaps you can access the version of the package and store that. \ No newline at end of file