Objects¶
Objects are the units which hold data in pdc. They are one or multi dimensional arrays of data with a single type. Example of creation and usage:
1import pdc
2from pdc import Object
3import numpy as np
4
5with pdc.ServerContext():
6 pdc.init()
7 #create temporary container
8 cont = pdc.Container('cont', lifetime=pdc.Container.Lifetime.TRANSIENT)
9
10 #create np data array of 128 doubles
11 data = np.full(128, 1.0, dtype=np.float64)
12
13 #Method 1: create object from array:
14 obj1 = cont.object_from_array('objectexample_obj1', data)
15
16 out_data = obj1.get_data().wait()
17 for val in out_data:
18 assert val == 1.0
19
20 #Method 2: create object from properties:
21 #create object property
22 prop = Object.Properties(dims=128, type=pdc.Type.DOUBLE)
23 #alternatively:
24 prop = Object.Properties(dims=128, type=np.double)
25
26 #property objects can be changed like so:
27 prop.app_name = 'objectexample'
28
29 #create object
30 obj2 = cont.create_object('objectexample_obj2', prop)
31
32 #set all data to data
33 obj2.set_data(data).wait()
34
35 #test data values
36 out_data = obj2.get_data().wait()
37 for val in out_data:
38 assert val == 1.0
- class pdc.Object(*args)
A PDC object
- class Properties(self, dims:Union[Tuple[uint32, ...], uint32], type, uint32_t time_step:uint32=0, user_id:Optional[uint32]=None, str app_name:str='')
Contains most of the metadata associated with an object. This is an inner class of Object
- Parameters:
dims (Tuple[uint32, ...] or uint32) – A tuple containing dimensions of the object, or a single integer for 1-D objects. For example, (10, 3) means 10 rows and 3 columns. 1 <= len(dims) <= 2^31-1
type (Type) – the data type. Either an instance of Type, or a numpy dtype.
time_step (uint32) – For applications that involve data along a time axis, this represents the point in time of the data. Defaults to 0.
user_id (uint32) – the id of the user. defaults to os.getuid()
app_name (str) – the name of the application. Defaults to an empty string.
- Raises:
ValueError – if type is an unsupported numpy dtype, if dims is empty.
- property app_name: unicode
The name of the application
- copy() Properties
Copy this properties object
- Returns:
A copy of this object
- property dims: Tuple[int, ...]
The dimensions of this object as a tuple.
- property type: Type
The data type of this object. Can be set to a numpy dtype, but the output value of this property will be a Type instance.
- property user_id: uint32
the id of the user.
- class TransferRequest(*args)
Represents a transfer request to either set a region’s data or get it.
- class RequestType(value)
The possible types of transfer request. Can be obtained with
TransferRequest.typeEither GET or SET.
- property done: bool
True if this transfer request is completed
- property result: Optional[ndarray[Any, dtype[ScalarType]]]
If the request is done and the request type is RequestType.GET, this is a numpy array containing the requested data. Otherwise, it is None.
- wait()
Block until the result of the transfer request is available, then return it. If this is a GET request, the return value is the data, otherwise it is None.
- property data: QueryComponent
- An object used to build queries.See Queries for more details.
- delete()
Delete this Object. Do not access any methods or properties of this object after calling this.
- property dims: Tuple[uint64, ...]
The dimensions of this object. read-only Equivalent to
obj.get_properties().dims
- classmethod get(name: unicode) Object
Get an existing object by name
If you have created multiple objects with the same name, this will return the one with time_step=0 If there are multiple objects with the same name and time_step, the tie is broken arbitrarily
- Parameters:
name (str) – the name of the object
- get_data(region: Region = None) TransferRequest
Request a region of data from an object
- Parameters:
region (Region) – the region of data to get. If this is None, defaults to the entire object.
- Returns:
A transfer request representing this request
- Return type:
TransferRequest
- property name: unicode
The name of this object. read-only
- set_data(self, data, region: 'Region' = None)
Request a region of data from an object to be set to a new value
- Parameters:
region (Region) – the region of data to set. Defaults to the entire object.
data – The data to set the region to. It must be a numpy array or convertible to a numpy array with numpy.array().
- Returns:
A TransferRequest representing this request
- Return type:
TransferRequest
- property type: Type
The type of this object. read-only