Python API for PV Access: PvaPy Overview

pvapy status l.w
1 / 14
Embed
Share

Explore PvaPy, a Python API for PV Access, at the EPICS Collaboration Meeting in September 2016. Learn about its features, current functionality, basic usage, and PV object representation. Discover how to interact with PV structures efficiently using Python.

  • Python API
  • PV Access
  • EPICS Collaboration
  • PvaPy
  • PV Structure

Uploaded on | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. PvaPy Status Sini a Veseli Argonne National Laboratory EPICS Collaboration Meeting September 2016 EPICS Collaboration Meeting - September 2016

  2. About PvaPy Python API for PV Access: - Simple to build and use: one should be able to get started in minutes - Has potential to provide full PV Access functionality: anything that can be done via C++ APIs should be doable with PvaPy Python look and feel: easy conversion between python objects (dictionaries, lists, etc.) and PV structures Uses boost.python to wrap EPICS v4 C++ libraries: - - Enables one to leverage existing functionality and reduce implementation effort Simplifies maintenance: future improvements in C++ infrastructure should benefit PvaPy Part of the latest EPICS v4 release Source: https://github.com/epics-base/pvaPy Documentation: http://epics-pvdata.sourceforge.net/docbuild/pvaPy/tip - EPICS Collaboration Meeting - September 2016 2

  3. Current Functionality Support for scalars, structures and unions (both variant and restricted) Support for channel get(), put(), putGet() and getPut() operations Channel monitor support RPC server/client Initial NT object support Support for numpy arrays (read-only) EPICS Collaboration Meeting - September 2016 3

  4. 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 v4 test IOC Use Channel class to get/set PVs: $ python >>> from pvaccess import * # do not do this in scripts >>> c = Channel('int01') >>> c.put(7) >>> pv = c.get() >>> print pv epics:nt/NTScalar:1.0 int value 7 >>> type(pv) <class 'pvaccess.PvObject'> EPICS Collaboration Meeting - September 2016 4

  5. PV Access in PvaPy PvObject class represents PV structure: - PvObject is a base class for all python PVA objects - High-level PvaPy API classes (Channel, RpcServer, RpcClient) work with PvObject instances Constructor: PvObject(structureDict [,valueDict][,typeId]) - PV structure in PvaPy 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 PvObject elements can be accessed and manipulated similar to python dictionaries EPICS Collaboration Meeting - September 2016 5

  6. Recent Developments (Release 0.6) Added support for channel getPut() and putGet() operations >>> c = Channel('int01') >>> c.put(5) >>> print c.getPut() epics:nt/NTScalar:1.0 int value 5 New PvObject class constructor allows optional value dictionary to be specified >>> pv = PvObject( {'a' : {'b' : STRING, 'c' : FLOAT}}, {'a' : {'b' : 'my string', 'c' : 10.1}} ) >>> print pv structure structure a float c 10.1 string b my string EPICS Collaboration Meeting - September 2016 6

  7. Recent Developments (Release 0.6) Introduced PvObject 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 PvObject support for field path notation (e.g, 'x.y.z') >>> pv['a.b'] 'new string Fixed PvObject typeId issues (D. Hickin) - Exposed appropriate PvObject constructor to python - Fixes for type id s in nested structures EPICS Collaboration Meeting - September 2016 7

  8. Recent Developments (Release 0.6) Added PvObject support for retrieving numeric scalar arrays as numpy arrays - Requires compiling with Boost.NumPy - Ability to retrieve an array either as a list or as a read-only numpy array >>> pv = PvObject({'a' : {'b' : STRING, 'c' : [INT]}}, {'a' : {'b' : 'my string', 'c' : [1,2,3,4,5]}}) >>> print pv.useNumPyArrays True >>> c = pv['a.c'] >>> c array([1, 2, 3, 4, 5], dtype=int32) >>> type(c) <type 'numpy.ndarray'> >>> pv.useNumPyArrays = False >>> c2 = pv['a.c'] >>> c2 >>> [1, 2, 3, 4, 5] >>> type(c2) <type 'list'> EPICS Collaboration Meeting - September 2016 8

  9. Recent Developments (Release 0.6) Added ability to specify PV request object in RPC client code (D. Hickin): RpcClient(channelName[, pvRequest]) 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

  10. 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 PvaPy 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 NDPluginPVA (to be available in AD Core 2-5) - Single PvaPy monitor client subscribed to the corresponding PVA channel and processed NT ND arrays. - Both simulation IOC and single PvaPy client run on the same machine - ND Array Data Size: 3145728 floats (12MB) - Hardware: Intel Xeon E5645, 6 cpu cores (HT enabled) @ 2.40GHz, 12GB RAM - Software: RHEL 7.2 (64-bit), python 2.7.5, boost 1.53, numpy 1.7.1, Boost.NumPy master@2016-06-26, EPICS Base 3.15.4, EPICS v4 CPP packages from 4.6 release, AD Core from a v4-plugin branch EPICS Collaboration Meeting - September 2016 10

  11. Channel Monitor Benchmarks Benchmarks done with the following PvaPy 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 uniqueId) 2) NumPy array access (get array data field from PvObject as numpy array) 3) Python list array access (get array data field from PvObject as python list) 4) Python list array sum by element access (get array data from PvObject as python list, iterate over all elements and sum them up) 5) NumPy array sum by element access (get array data from PvObject as numpy array, iterate over all elements and sum them up) 6) NumPy array sum using object interface (get array data from PvObject 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

  12. Channel Monitor Benchmarks ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? PvaPy Processing? Rates ? Test? 1 (no? array? data? field? access) Release? 0.5 Q? Size:? 10 Release? 0.6 Q? Size:? 10 Release? 0.6 Q? Size:? 0 Array? Processing Rate? [Hz] Data? Processing Rate? [MB/s] Array? Processing Rate? [Hz] Data? Processing Rate? [MB/s] 34.4? ? 0.1 109.7? ? 1.2 112.9? ? 0.7 413.4? ? 1.8 1316.4? ? 14.3 1354.8? ? 8.0 ? Test? 2 (get? array? data? field? as? numpy? array) 34.0 ? 0.1 108.5? ? 1.2 113.0? ? 0.6 408.5? ? 1.4 1301.8? ? 14.6 1356.1? ? 7.6 ? Test? 3 (get? array? data? field? as? python? list) Array? Processing Rate? [Hz] Data? Processing Rate? [MB/s] 7.8? ? 0.1 8.9? ? 0.1 7.9? ? 0.4 94.1? ? 0.5 107.3? ? 1.3 94.7? ? 4.2 ? Test? 4 (sum? array? elements;? iterate? over? python? list) Array? Processing Rate? [Hz] Data? Processing Rate? [MB/s] 3.07? ? 0.01 3.34? ? 0.06 3.24? ? 0.04 36.9? ? 0.1 40.1? ? 0.7 38.8? ? 0.4 ? Test? 5 (sum? array? elements;? iterate? over? numpy? array) ? Test? 6 (sum? array? elements;? use? numpy? ndarray.sum()? method) Array? Processing Rate? [Hz] Data? Processing Rate? [MB/s] 0.638? ? 0.001 0.683? ? 0.007 0.680? ? 0.011 7.66? ? 0.01 8.20? ? 0.09 8.17? ? 0.13 Array? Processing Rate? [Hz] Data? Processing Rate? [MB/s] 33.0? ? 0.2 71.0? ? 0.4 76.6? ? 0.4 396.4? ? 2.5 852.1? ? 4.6 918.9? ? 5.3 EPICS Collaboration Meeting - September 2016 12

  13. Channel Monitor Benchmarks Test 1: More than 3x higher array receiving/processing rate with PvaPy v0.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

  14. Upcoming Work PvaPy Channel Provider (work in progress - D. Hickin, T. Cobb) Complete NT type support: - Revise existing NT classes (e.g., NTTable) - Add support for NTNameValue, NTMultiChannel, etc. Test suite development Any other requests/immediate needs? EPICS Collaboration Meeting - September 2016 14

Related


More Related Content