Contents
In this sample, the Python and Python Instance operators work to create Python instances and execute Python code. The operators enable Python-centric teams to reuse their code without major rewrites to execute event processing. This includes execution of models produced with SciPy and TensorFlow.
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, select
→ . -
In the search field, enter
wits
to narrow the list of samples. -
Select
Performing operations using Python
from the Large Data Storage and Analysis category. -
Click
.
StreamBase Studio creates a single project containing the sample files.
Before running the samples, open the supplied adapter-configurations.xml
, which is located in src/main/resources
, and edit the configuration to point to your installed version of Python.
To run the TensorFlow sample, you must have the following modules installed into your Python:
-
TensorFlow
-
OpenCV-Python
This sample demonstrates performing a very basic Python call and returning a result.
-
In the Project Explorer, open the sample you just loaded.
-
Open the
src/main/eventflow
folder and double-click to opensample-version.sbapp
. Make sure the application is the currently active tab in the EventFlow Editor. -
Click the
Run button. This opens the SB Test/Debug perspective and starts the application.
If you see red marks, wait a moment for the project in Studio to load its features.
If red marks do not resolve themselves in a moment, select the project and right-click
→ from the context menu. -
In the Manual Input view, select the
Input
input stream.Click
. -
In the Application Output view, look for the OutputStream tuples for the selected operation, which gives the current Python's version information.
-
When done, press F9 or click the
Stop Running Application button.
This sample demonstrates using a local instance of the Python engine — versus a global instance — that can be accessed by all running modules. The input takes an integer that determines how many Fibonacci series to calculate and output.
-
In the Project Explorer view, double-click to open
sample-local-instance.sbapp
. Make sure the application is the currently active tab in the EventFlow Editor. -
Click the
Run button. This opens the SB Test/Debug perspective and starts the application.
-
In the Manual Input view, select the
InputStream
input stream.Enter
100
into thefib
field.Click
. -
In the Application Output view, look for the OutputStream tuples for the selected operation, which gives the current Python's version information.
-
When done, press F9 or click the
Stop Running Application button.
This sample demonstrates using TensorFlow to run a model in multiple thread instances, evaluate model input, and receive model output. This sample requires that the Python installation is configured to handle TensorFlow as mentioned above.
The sample uses a worker module to enable eight operations to occur simultaneously. Each instance has its own instance of
Python and initializes the model within each instance. See the sample-tensorflow-worker.sbapp
-
In the Project Explorer view, double-click to open
sample-tensorflow.sbapp
. Make sure the application is the currently active tab in the EventFlow Editor. -
Click the
Run button. This opens the SB Test/Debug perspective and starts the application.
-
In the Application Output view, look for the OutputStream tuples for the selected operation, which gives the current Python's version information.
-
When done, press F9 or click the
Stop Running Application button.
When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.
Important
Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.
Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:
studio-workspace
/sample_python
See Default Installation Directories for the location of studio-workspace
on your system.