Skip to content

Commit

Permalink
Update line numbers in modelling tutorials after header changes
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-traverse committed Nov 10, 2024
1 parent dd7238d commit 85b5712
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 50 deletions.
22 changes: 11 additions & 11 deletions doc/modelling/tutorial/hello_world.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ for running code in TRAC, both on the platform and using the local development s
:caption: src/tutorial/hello_world.py
:name: hello_world_py_part_1
:language: python
:lines: 15 - 20
:lines: 16 - 20
:linenos:
:lineno-start: 15
:lineno-start: 16

The model can define any parameters it is going to need. In this example there is only a
single parameter so it can be declared in code (more complex models may wish to manage
Expand All @@ -155,9 +155,9 @@ are defined in the correct format.
.. literalinclude:: ../../../examples/models/python/src/tutorial/hello_world.py
:name: hello_world_py_part_2
:language: python
:lines: 21 - 27
:lines: 22 - 27
:linenos:
:lineno-start: 21
:lineno-start: 22

The model can also define inputs and outputs. In this case since all we are going to do
is write a message in the log, no inputs and outputs are needed. Still, these methods are
Expand All @@ -166,9 +166,9 @@ required in order for the model to be valid.
.. literalinclude:: ../../../examples/models/python/src/tutorial/hello_world.py
:name: hello_world_py_part_3
:language: python
:lines: 28 - 33
:lines: 29 - 33
:linenos:
:lineno-start: 28
:lineno-start: 29

To write the model logic, implement the :py:meth:`run_model() <tracdap.rt.api.TracModel.run_model>` method.
When :py:meth:`run_model() <tracdap.rt.api.TracModel.run_model>` is called it receives a
Expand All @@ -178,9 +178,9 @@ TRAC platform.
.. literalinclude:: ../../../examples/models/python/src/tutorial/hello_world.py
:name: hello_world_py_part_4
:language: python
:lines: 34 - 40
:lines: 35 - 40
:linenos:
:lineno-start: 34
:lineno-start: 35

There are two useful features of :py:class:`TracContext <tracdap.rt.api.TracContext>`
that can be seen in this example:
Expand All @@ -191,7 +191,7 @@ that can be seen in this example:
datasets. Log outputs are available even if a job fails so they can be used for debugging.

* :py:meth:`get_parameter() <tracdap.rt.api.TracContext.get_parameter>` allows models to access any
parameters defined in the :py:meth:`define_parameters()<tracdap.rt.api.TracModel.define_parameters>`
parameters defined in the :py:meth:`define_parameters() <tracdap.rt.api.TracModel.define_parameters>`
method. They are returned as native Python objects, so integers use the Python integer type,
date and time values use the Python datetime classes and so on.

Expand Down Expand Up @@ -243,9 +243,9 @@ this, but the model will fail to deploy)!
:caption: src/tutorial/hello_world.py
:name: hello_world_py_launch
:language: python
:lines: 42-
:lines: 43-
:linenos:
:lineno-start: 42
:lineno-start: 43

Paths for the system and job config files are resolved in the following order:

Expand Down
38 changes: 19 additions & 19 deletions doc/modelling/tutorial/inputs_and_outputs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ Here is an example of defining an optional input, using schemas read from schema
:caption: src/tutorial/optional_io.py
:language: python
:name: optional_io_part_1
:lines: 38 - 48
:lines: 39 - 49
:linenos:
:lineno-start: 38
:lineno-start: 39

Schemas defined in code can also be marked as optional, let's use that approach to define an
optional output:

.. literalinclude:: ../../../examples/models/python/src/tutorial/optional_io.py
:language: python
:name: optional_io_part_2
:lines: 50 - 66
:lines: 51 - 67
:linenos:
:lineno-start: 50
:lineno-start: 51

Now let's see how to use optional inputs and outputs in :py:meth:`run_model() <tracdap.rt.api.TracModel.run_model>`.
Since the input is optional we will need to check if it is available before we can use it.
Expand All @@ -47,9 +47,9 @@ dataset with some stats on the filtered accounts. Here is what that looks like:
.. literalinclude:: ../../../examples/models/python/src/tutorial/optional_io.py
:language: python
:name: optional_io_part_3
:lines: 76 - 85
:lines: 77 - 86
:linenos:
:lineno-start: 76
:lineno-start: 77

In this example the optional output is only produced when the optional input is
supplied - that is not a requirement and the model can decide whether to
Expand Down Expand Up @@ -106,9 +106,9 @@ some basic information about the schema and content:
:caption: src/tutorial/dynamic_io.py
:language: python
:name: dynamic_io_schema_inspection_1
:lines: 21 - 39
:lines: 22 - 40
:linenos:
:lineno-start: 21
:lineno-start: 22

The source data is defined as a dynamic input. Notice that there are no fields in the
schema definition - dynamic inputs or outputs cannot define any fields, doing so will
Expand All @@ -122,9 +122,9 @@ Now let's see how to use these datasets in the model.
.. literalinclude:: ../../../examples/models/python/src/tutorial/dynamic_io.py
:language: python
:name: dynamic_io_schema_inspection_2
:lines: 41 - 60
:lines: 42 - 61
:linenos:
:lineno-start: 41
:lineno-start: 42

The model gets the source dataset as normal, but it also gets the schema of the dataset using
:py:meth:`get_schema() <tracdap.rt.api.TracContext.get_schema>` which returns aTRAC
Expand Down Expand Up @@ -185,9 +185,9 @@ Let's see how to define this model:
.. literalinclude:: ../../../examples/models/python/src/tutorial/dynamic_io.py
:language: python
:name: dynamic_io_data_generation_1
:lines: 63 - 80
:lines: 64 - 81
:linenos:
:lineno-start: 63
:lineno-start: 64

In real life more parameters would often be needed to control the generated data, e.g. range limits
or distribution parameters, but for this simple example those are not needed.
Expand All @@ -197,9 +197,9 @@ Now let's look at the model code:
.. literalinclude:: ../../../examples/models/python/src/tutorial/dynamic_io.py
:language: python
:name: dynamic_io_data_generation_2
:lines: 82 - 100
:lines: 83 - 101
:linenos:
:lineno-start: 82
:lineno-start: 83

The model creates a :py:class:`SchemaDefinition <tracdap.rt.metadata.SchemaDefinition>` and adds a
:py:class:`FieldSchema <tracdap.rt.metadata.FieldSchema>` for each column. The same helper functions
Expand All @@ -218,7 +218,7 @@ as part of the call to :py:meth:`put_schema() <tracdap.rt.api.TracContext.put_sc

.. note::
Calling :py:meth:`put_schema() <tracdap.rt.api.TracContext.put_schema>` creates a copy of
the TRAC schema object. Any changes made to the schema after it is saved will noo be picked
the TRAC schema object. Any changes made to the schema after it is saved will not be picked
up by TRAC. Calling :py:meth:`get_schema() <tracdap.rt.api.TracContext.get_schema>` after
a schema has been set will always return the schema as it was saved.

Expand All @@ -237,19 +237,19 @@ Let's see an example model definition that can help us do that:
.. literalinclude:: ../../../examples/models/python/src/tutorial/dynamic_io.py
:language: python
:name: dynamic_io_dynamic_filtering_1
:lines: 103 - 117
:lines: 104 - 118
:linenos:
:lineno-start: 63
:lineno-start: 104

Here both the input and the output are dynamic, and the model is controlled only by the two filter
parameters. Now let's see the implementation:

.. literalinclude:: ../../../examples/models/python/src/tutorial/dynamic_io.py
:language: python
:name: dynamic_io_dynamic_filtering_2
:lines: 119 - 130
:lines: 120 - 131
:linenos:
:lineno-start: 130
:lineno-start: 120

The original input schema is used directly as the output schema, so the schema of the input
and output will be the same.
Expand Down
40 changes: 20 additions & 20 deletions doc/modelling/tutorial/using_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ the top-level class or function as parameters, as shown in this example.
:caption: src/tutorial/using_data.py
:name: using_data_py_part_1
:language: python
:lines: 21 - 48
:lines: 22 - 49
:linenos:
:lineno-start: 21
:lineno-start: 22


Defining model requirements
Expand All @@ -38,9 +38,9 @@ so we can use the same syntax. We'll define the three parameters needed by the m
.. literalinclude:: ../../../examples/models/python/src/tutorial/using_data.py
:name: using_data_py_part_2
:language: python
:lines: 51-65
:lines: 52-66
:linenos:
:lineno-start: 51
:lineno-start: 52

The example model function has one data input, which is a table called *customer_loans*.
The function :py:func:`define_output_table() <tracdap.rt.api.define_output_table>` in the
Expand Down Expand Up @@ -79,9 +79,9 @@ lenient type handling for input files.
.. literalinclude:: ../../../examples/models/python/src/tutorial/using_data.py
:name: using_data_py_part_3
:language: python
:lines: 67 - 76
:lines: 68 - 77
:linenos:
:lineno-start: 67
:lineno-start: 68

To define the model outputs we can use :py:func:`define_output_table() <tracdap.rt.api.define_output_table>`,
which is identical to :py:func:`define_input_table() <tracdap.rt.api.define_input_table>` save for the fact it
Expand All @@ -93,9 +93,9 @@ Models are free to define multiple outputs if required, but this example only ha
.. literalinclude:: ../../../examples/models/python/src/tutorial/using_data.py
:name: using_data_py_part_4
:language: python
:lines: 78 - 84
:lines: 79 - 85
:linenos:
:lineno-start: 78
:lineno-start: 79

Now the parameters, inputs and outputs of the model are defined, we can implement the
:py:meth:`run_model() <tracdap.rt.api.TracModel.run_model>` method.
Expand All @@ -115,9 +115,9 @@ schema for this input.
.. literalinclude:: ../../../examples/models/python/src/tutorial/using_data.py
:name: using_data_py_part_5
:language: python
:lines: 86 - 92
:lines: 87 - 93
:linenos:
:lineno-start: 86
:lineno-start: 87

Once all the inputs and parameters are available, we can call the model function. Since all the inputs
and parameters are supplied using the correct native types there is no further conversion necessary,
Expand All @@ -126,9 +126,9 @@ they can be passed straight into the model code.
.. literalinclude:: ../../../examples/models/python/src/tutorial/using_data.py
:name: using_data_py_part_6
:language: python
:lines: 94 - 96
:lines: 95 - 97
:linenos:
:lineno-start: 94
:lineno-start: 95

The model code has produced a Pandas dataframe that we want to record as an output. To do this, we can use
:py:meth:`put_pandas_table() <tracdap.rt.api.TracContext.put_pandas_table>`. The dataframe should match
Expand All @@ -147,18 +147,18 @@ columns will be dropped.
.. literalinclude:: ../../../examples/models/python/src/tutorial/using_data.py
:name: using_data_py_part_7
:language: python
:lines: 98
:lines: 99
:linenos:
:lineno-start: 98
:lineno-start: 99

The model can be launched locally using :py:func:`launch_model() <tracdap.rt.launch.launch_model()>`.

.. literalinclude:: ../../../examples/models/python/src/tutorial/using_data.py
:name: using_data_py_part_8
:language: python
:lines: 101-103
:lines: 102-104
:linenos:
:lineno-start: 101
:lineno-start: 102

Configure local data
--------------------
Expand Down Expand Up @@ -265,9 +265,9 @@ Now we can re-write our model to use the new schema files. First we need to impo
:caption: src/tutorial/schema_files.py
:name: using_data_part_9
:language: python
:lines: 19
:lines: 20
:linenos:
:lineno-start: 19
:lineno-start: 20

Then we can load schemas from the schemas package in the
:py:meth:`define_inputs() <tracdap.rt.api.TracModel.define_inputs>` and
Expand All @@ -276,9 +276,9 @@ Then we can load schemas from the schemas package in the
.. literalinclude:: ../../../examples/models/python/src/tutorial/schema_files.py
:name: using_data_part_10
:language: python
:lines: 46 - 56
:lines: 47 - 57
:linenos:
:lineno-start: 46
:lineno-start: 47

Notice that the :py:func:`load_schema() <tracdap.rt.api.load_schema>` method is the same
for input and output schemas, so we need to use
Expand Down

0 comments on commit 85b5712

Please sign in to comment.