12.1. Introduction

12.1.1. Requirements

pSeven Core examples use certain well-known free third party Python modules, which can not be included into the pSeven Core package and have to be installed separately. Those modules provide common utilities, which are not essential for using pSeven Core though are required to run the examples. Explaining the usage of those modules is beyond the scope of this manual; refer to the respective module documentation.

Third party modules required to run the examples include:

  • SciPy — a popular library for scientific programming.
  • pandas — a common data analysis and manipulation library.
  • Matplotlib — a plotting library widely used in examples. Compatible versions are Matplotlib 1.1 and newer.
  • psutil — an utility providing memory usage information. Required by the Training with Limited Memory example only.

12.1.2. Running Examples

All examples run with the current version of pSeven Core provided that all modules mentioned in section Requirements are available. The examples are included into package and are installed automatically when you install pSeven Core.

The preferred method of running an example is to execute it as a module using python -m, for example:

python -m da.p7core.examples.gtopt.example_gtopt_ZDT1

Note that since the argument is a module name, there is no need to add the .py extension. Module names are given in example descriptions.

When run, the example will log its activity and intermediate results to the console and finally display a plot with results. Close the plot window to finish the example. Some examples generate more than one plot — in this case, execution is halted when the first plot is ready; close the plot window to continue with the example (a message about this will also be printed to the log).

Plots are also saved to the current working directory, and the location of saved images is printed to the console log. Before running an example, check that you have write access to the current directory (the directory where you invoke the Python interpreter).

You can also run examples as scripts. At the end of each example description you will find links to the full code (and additional data files, if required). You can save them to any location and execute python example_file_name.py from this directory, for instance:

python example_gtopt_ZDT1.py

In this case the .py extension is required. Also note that if the example requires source data files, they have to be placed in the same directory with the script.

If you invoke Python from another directory, check that you have write access to that directory. The script always saves generated plots to the current working directory (the one where you invoke the Python interpreter), which in this case is different from the directory where you have placed the example and data files.

Warning

Running example scripts right from the pSeven Core package directory is strongly not recommended. If you do not want to create a copy of the example script, just run it through python -m.

Finally, it is possible to run example scripts by double-clicking the .py file you have downloaded, though it introduces additional requirements.

  • In Linux, requires the pSeven Core package to be installed with super user privileges. If the package was installed as a regular user (see Installation), only the two methods described above are available. Additionally, the executable permission has to be set for the script — for example:

    chmod 744 example_file_name.py
    
  • In Windows, the .py extension has to be registered and associated with the Python interpreter (python.exe). Usually this is done automatically when Python is installed. If it is not, you can right-click the script file, select “Open with”, then “Choose default program…” and select your Python interpreter (uncheck “Always use the selected program to open this kind of file” at the bottom if you want to only execute the script without associating all .py files with Python).

If an example fails to run or produces unexpected results, please refer to the Troubleshooting section.