Pva Py Status Sinia Veseli Argonne National Laboratory
Pva. Py Status Siniša Veseli Argonne National Laboratory EPICS Collaboration Meeting September 2016 EPICS Collaboration Meeting - September 2016
About Pva. Py Python API for PV Access: - Simple to build and use: one should be able to get started in minutes - Python look and feel: easy conversion between python objects (dictionaries, lists, etc. ) and PV structures Has potential to provide full PV Access functionality: anything that can be done via C++ APIs should be doable with Pva. Py Uses boost. python to wrap EPICS v 4 C++ libraries: - Enables one to leverage existing functionality and reduce implementation effort - Simplifies maintenance: future improvements in C++ infrastructure should benefit Pva. Py Part of the latest EPICS v 4 release Source: https: //github. com/epics-base/pva. Py Documentation: http: //epics-pvdata. sourceforge. net/docbuild/pva. Py/tip EPICS Collaboration Meeting - September 2016 2
Current Functionality Support for scalars, structures and unions (both variant and restricted) Support for channel get(), put. Get() and get. Put() operations Channel monitor support RPC server/client Initial NT object support Support for numpy arrays (read-only) EPICS Collaboration Meeting - September 2016 3
Basic Usage Source setup file $PVAPY_DIR/bin/$EPICS_HOST_ARCH/setup. (c)sh, or manually configure PYTHONPATH: $ export PYTHONPATH=$PVAPY_DIR/lib/$EPICS_HOST_ARCH: $PYTHONPATH Inspect package contents: $ python -c "import pvaccess; print dir(pvaccess)" Start v 4 test IOC Use Channel class to get/set PVs: $ python >>> from pvaccess import * # do not do this in scripts >>> c = Channel('int 01') >>> c. put(7) >>> pv = c. get() >>> print pv epics: nt/NTScalar: 1. 0 int value 7 >>> type(pv) <class 'pvaccess. Pv. Object'> EPICS Collaboration Meeting - September 2016 4
PV Access in Pva. Py Pv. Object class represents PV structure: - Pv. Object is a base class for all python PVA objects - High-level Pva. Py API classes (Channel, Rpc. Server, Rpc. Client) work with Pv. Object instances Constructor: Pv. Object(structure. Dict [, value. Dict][, type. Id]) PV structure in Pva. Py is described via python structure dictionary of field name/descriptor pairs; field name is a string, and field descriptor is one of: - PVTYPE : scalar field (BOOLEAN, BYTE, UBYTE, …, STRING) - [PVTYPE] : scalar array, e. g. [INT] - {key: value, …} : structure, e. g. {'x' : INT, 'y' : FLOAT} - [{key: value, …}] : structure array, e. g. [{'x' : INT, 'y' : FLOAT}] - () : variant union - [()] : variant union list - ({key: value, …}, ) : restricted union - [({key: value, …}, )] : restricted union list Pv. Object elements can be accessed and manipulated similar to python dictionaries EPICS Collaboration Meeting - September 2016 5
Recent Developments (Release 0. 6) Added support for channel get. Put() and put. Get() operations >>> c = Channel('int 01') >>> c. put(5) >>> print c. get. Put() epics: nt/NTScalar: 1. 0 int value 5 New Pv. Object class constructor allows optional value dictionary to be specified >>> pv = Pv. Object( {'a' : {'b' : STRING, 'c' : FLOAT}}, {'a' : {'b' : 'my string', 'c' : 10. 1}} ) >>> print pv structure a float c 10. 1 string b my string EPICS Collaboration Meeting - September 2016 6
Recent Developments (Release 0. 6) Introduced Pv. Object support for getitem, setitem, and contains >>> pv['a'] = {'c' : 0. 1, 'b' : 'new string'} >>> print pv['a'] {'c': 0. 10000000149011612, 'b': 'new string'} >>> if 'a' in pv: . . . print 'Field "a" is in pv'. . . else: . . . print 'Field "a" is not in pv'. . . Field "a" is in pv Introduced Pv. Object support for field path notation (e. g, 'x. y. z') >>> pv['a. b'] 'new string’ Fixed Pv. Object type. Id issues (D. Hickin) - Exposed appropriate Pv. Object constructor to python - Fixes for type id’s in nested structures EPICS Collaboration Meeting - September 2016 7
Recent Developments (Release 0. 6) Added Pv. Object support for retrieving numeric scalar arrays as numpy arrays - Requires compiling with Boost. Num. Py - Ability to retrieve an array either as a list or as a read-only numpy array >>> pv = Pv. Object({'a' : {'b' : STRING, 'c' : [INT]}}, {'a' : {'b' : 'my string', 'c' : [1, 2, 3, 4, 5]}}) >>> print pv. use. Num. Py. Arrays True >>> c = pv['a. c'] >>> c array([1, 2, 3, 4, 5], dtype=int 32) >>> type(c) <type 'numpy. ndarray'> >>> pv. use. Num. Py. Arrays = False >>> c 2 = pv['a. c'] >>> c 2 >>> [1, 2, 3, 4, 5] >>> type(c 2) <type 'list'> EPICS Collaboration Meeting - September 2016 8
Recent Developments (Release 0. 6) Added ability to specify PV request object in RPC client code (D. Hickin): Rpc. Client(channel. Name[, pv. Request]) Channel monitor enhancements (thanks to M. Kraimer for help and suggestions): - Code is now similar to version used for release 0. 4 (uses monitor requester callback) - Added immediate processing mode: does not require background processing thread, and copying/queueing of monitor data (this is now default processing mode) - For background thread processing mode unnecessary monitor polling when monitor queue is full has been eliminated - Significantly better performance when compared to release 0. 5 EPICS Collaboration Meeting - September 2016 9
Channel Monitor Benchmarks Goal: run series of tests to assess current channel monitor performance and level of improvement relative to previous release Tests were designed to saturate Pva. Py processing capabilities and to measure how fast we can receive and process monitor data Test setup: - Simulation IOC based on AD framework generated ND arrays, and exposed those as NT ND Arrays using the NDPlugin. PVA (to be available in AD Core 2 -5) - Single Pva. Py monitor client subscribed to the corresponding PVA channel and processed NT ND arrays. - Both simulation IOC and single Pva. Py client run on the same machine - ND Array Data Size: 3145728 floats (12 MB) - Hardware: Intel Xeon E 5645, 6 cpu cores (HT enabled) @ 2. 40 GHz, 12 GB RAM - Software: RHEL 7. 2 (64 -bit), python 2. 7. 5, boost 1. 53, numpy 1. 7. 1, Boost. Num. Py master@2016 -06 -26, EPICS Base 3. 15. 4, EPICS v 4 CPP packages from 4. 6 release, AD Core from a v 4 -plugin branch EPICS Collaboration Meeting - September 2016 10
Channel Monitor Benchmarks done with the following Pva. Py software/configuration: - Release 0. 5 (plus numpy additions), with Max Queue Size 10 (processing thread mode) - Release 0. 6, with Max Queue Size 10 (processing thread mode) - Release 0. 6, with Max Queue Size 0 (immediate processing mode) Tests: 1) Minimal processing (no array data access, just calculate stats using array unique. Id) 2) Num. Py array access (get array data field from Pv. Object as numpy array) 3) Python list array access (get array data field from Pv. Object as python list) 4) Python list array sum by element access (get array data from Pv. Object as python list, iterate over all elements and sum them up) 5) Num. Py array sum by element access (get array data from Pv. Object as numpy array, iterate over all elements and sum them up) 6) Num. Py array sum using object interface (get array data from Pv. Object as numpy array, use ndarray. sum() method) Least CPU intensive: Test #1, most CPU intensive: Tests #4 and #5 EPICS Collaboration Meeting - September 2016 11
Channel Monitor Benchmarks EPICS Collaboration Meeting - September 2016 12
Channel Monitor Benchmarks Test 1: More than 3 x higher array receiving/processing rate with Pva. Py v 0. 6 (about 110 arrays processed per second) Test 2: Accessing array data field as numpy array is very efficient Test 3: Conversion to python list is rather costly for large scalar arrays Test 5: Individual element access is very inefficient with numpy arrays Tests 1, 2, 6: Immediate processing mode is better if python processing time is rather short Tests 3, 4, 5: Processing thread mode is more efficient for intensive processing EPICS Collaboration Meeting - September 2016 13
Upcoming Work Pva. Py Channel Provider (work in progress - D. Hickin, T. Cobb) Complete NT type support: - Revise existing NT classes (e. g. , NTTable) - Add support for NTName. Value, NTMulti. Channel, etc. Test suite development Any other requests/immediate needs? EPICS Collaboration Meeting - September 2016 14
- Slides: 14