.. _create_scripts:

Creating Example Scripts 
##########################

|popy| contains built in example scripts that can be generated on the command line. The general method is:-

.. code-block:: console

    popy create [script_type] [script_name]

These built in scripts are designed to get you started with using a particular type of |script_file|. Once generated you can edit the default text for your own |pkpd| modelling requirements.
    
See :ref:`popy_create` documentation, or the :ref:`creating_a_fit_script` and :ref:`creating_a_tut_script` examples below.


.. _creating_a_fit_script:

Creating an example Fit Script 
===================================

First, :ref:`open_a_popy_command_prompt`. Then do:-

.. code-block:: console

    popy create fit my_fit_script.pyml

where

* :ref:`popy_create` is one of the :ref:`popy_tools`
* the **fit** option requests a fit script to be created and 
* the 'my_fit_script.pyml' file is the name of the :ref:`fit_script` written to disk.

You can generate a more verbose example script with comments using:-

.. code-block:: console

    popy create -acsl fit my_fit_script.pyml

See :ref:`popy_create` for the meaning of the '-acsl' command line switch options. Or type 'popy_create -h'.
      
You will notice that :ref:`popy_create` also creates a file called `my_fit_script.pyml.create.main.log`.
This is a record of the messages output by the :ref:`popy_create` tool.
In this case the log file is very short. These log files, created by all of the :ref:`popy_tools`, act as part of the audit trail for your experiments. 

You can try running the fit_script:-

.. code-block:: console

    popy run my_fit_script.pyml

However, you will likely see a message, similar to the following:-

.. code-block::

    CAST_ERROR= ERROR in value_record: ROOT->FILE_PATHS->input_data_file
    ERROR when casting input file element
    input file path = C:\Users\david\my_popy_egs\examples\fit_example4\input.csv
    NOT present on file system.
    
Essentially this is telling you that this entry in 'builtin_fit_example.pyml':-

.. code-block:: pyml

    FILE_PATHS: {input_data_file: input.csv}
    
Is causing a problem because 'input.csv' does |not| exist. The popy_create tool outputs a script file only, so the 'input.csv' entry is just a place holder. You need to set the 'input_data_file' field to point at an existing data file to run the :ref:`fit_script`.

Note one way of creating a data file is to create and then run a :ref:`gen_script` or :ref:`tut_script`, as described below.

The 'my_fit_script.pyml' is just meant to provide an easy template for you to use for your own analyses. The 'tut_script' example below is more complete, as a :ref:`tut_script` works with just a single \.pyml file.

.. _creating_a_tut_script:

Creating an example Tut Script 
====================================

As always the first step is to :ref:`open_a_popy_command_prompt`. Then do:-

.. code-block:: console

    popy create tut my_tut_script.pyml
       
You can generate a more verbose example script with comments using:-

.. code-block:: console

    popy create -acsl tut my_tut_script.pyml
   
See :ref:`popy_create` for the command line switch options. Or type 'popy_create -h'.
   
You can use this mechanism to create an example file for any of the :ref:`script_formats` in |popy|,
which you can then open and modify using your chosen text |editor|.

When you have a run-able :ref:`tut_script`, run it via:-

.. code-block:: console

    popy run my_tut_script.pyml

You can use this mechanism to create an example file for any of the :ref:`script_formats` in |popy|.


