ADMIT Task

This module defines the ADMIT task (AT) base class.

class admit.AT.AT(keys={}, keyvals={})

Base class for Admit Task (AT) objects.

The ADMIT task base class implements generic interface features common to concrete ATs. Tasks are the basic execution unit in ADMIT and are responsible for operating on BDPs to perform calculations or otherwise transform them into new data products. Each task includes a unique set of keywords controlling its behavior.

Parameters:

keys : dictionary of str keywords with default values, optional.

Task keyword settings; default keyword values vary by task.

keyvals : dictionary of new values for the keywords, optional.

These keyword value pairs can be fed in form the command line instantiation of the class.

Notes

As a general rule the attributes of an AT should not be directly manipulated by the code in an AT, all are taken care of internally or accessed via methods (e.g. setkey)

Attributes

_taskid (int) Static task ID counter (increments as new tasks are instantiated). Instances also have a unique _taskid containing their particular ID number.
_bdp_in (list of BDPs) BDP input cache.
_bdp_in_map (list of ints) Listing of BDP uid’s correspinding to those listed in _bdp_in
_bdp_out (list of BDPs) BDP output cache.
_bdp_out_map (list of ints) Listing of BDP uid’s correspinding to those listed in _bdp_out
_keys (dict) Task keyword dictionary.
_type (str) Concrete task type.
_stale (boolean) Whether the AT needs to be run (i.e. keyword changed) ??? what if the output BDP doesn’t exist ???
_enabled (boolean) Whether the AT is enabled, if set to False the flow manager will not execute the local run method.
_do_plot (boolean) Should plotting be done
_plot_mode (int) TBD
_valid_bdp_in (List) List of Tuples indicating what types and how many BDPs are expected as input
_valid_bdp_out (List) List of Tuples indicating what types and how many BDPs are expected as output
_needToSave (boolean) Whether this AT and underlying BDP’s need to be saved to disk

Methods

addinput(item[, slot]) Add a BDP input to an AT.
addinputbdp(item[, slot, insert]) Add a BDP to the _bdp_in list
addoutput(item[, slot]) Add a BDP output product to an AT.
addoutputbdp(item[, slot, insert]) Add a BDP to the _bdp_out list
check()
checkfiles() check if the files from all the BDP_out’s in an AT exist,
checktype(item) Check the type of an object to see if ti is a BDP
clearinput() Clear the input BDP list
clearoutput() Clear the output BDP list
copy() Creates an independent duplicate of the task.
delete([delfiles]) Method to delete the AT and underlying BDPs.
delinput(slot) Delete a specific BDP in the _bdp_in list
deloutput(slot) Delete a specific BDP in the _bdp_out list
dir([filename]) Return the absolution directory of this ADMIT project or a derefenced filename address.
execute([args]) Executes the task.
getVersion() Return the version string
getdtd(fl) Method to write out the dtd data
getkey(key) Retrieval value for a key.
haskey(key) Query if a key exists for an AT.
isequal(at) Method to determine if two ATs are the same.
isstale() Return True/False if an AT is up to date
len2() Return the length of _bdp_in and _bdp_out in a tuple
markChanged() Mark an AT that it’s state was changed, so it would need to be rerun.
markUpToDate() Sets the _stale state to indicate that the AT does not need to be run
mkdir(dirname) Make a directory in the ADMIT hierarchy if it doesn’t exist yet It also allows an absolute path, in the classical unix sense.
run() Runs the task.
save()
set_bdp_in([bin]) Validate the _valid_bdp_in list and digest it into the appropriate attributes
set_bdp_out([bout]) Validate the _valid_bdp_out list and digest it into the appropriate attributes
setkey([name, value, isinit]) set keys, two styles are possible:
show() Return the type of the AT
summary() place holder empty summary in case the derived class doesn’t implement it
uptodate() Returns the current state of the _stale flag
validateinput([describe]) Method to validate the _bdp_in’s against a dictionary of expected types.
write(node) Method to write the AT to disk
addinput(item, slot=-1)

Add a BDP input to an AT. The BDP type will be validated before it is added to the input list.

Parameters:

item : BDP

The BDP to be added to the input list

slot : int

The slot in the BDP to add it to. The BDP type must match the expected type for the slot. Default: -1 (i.e. insert into the first available slot)

Returns:

None

addinputbdp(item, slot=-1, insert=False)

Add a BDP to the _bdp_in list This method should not be called directly, use addinput instead

Parameters:

item : BDP

The BDP to add

slot : int

Where the BDP should be added to the list default : -1

insert : Boolean

insert into the middle of the list (not replace)

Returns:

None

addoutput(item, slot=-1)

Add a BDP output product to an AT. The BDP type will be validated before it is added to the output list.

Parameters:

item : BDP

The BDP to be added to the output list

slot : int

The slot in the BDP to add it to. The BDP type must match the expected type for the slot. Default: -1 (i.e. insert into the first available slot)

Returns:

None

addoutputbdp(item, slot=-1, insert=False)

Add a BDP to the _bdp_out list This method should not be called directly, use addoutput instead

Parameters:

item : BDP

The BDP to add

slot : int

Where the BDP should be added to the list default : -1

insert : Boolean

insert into the middle of the list (not replace)

Returns:

None

check()
checkfiles()

check if the files from all the BDP_out’s in an AT exist, and return the list of files not found @todo this needs a catch-22 fix on re-running admit

checktype(item)

Check the type of an object to see if ti is a BDP

Parameters:

item : Any

The item to check

Returns:

Boolean

True if the item is a BDP, False otherwise

clearinput()

Clear the input BDP list

clearoutput()

Clear the output BDP list

copy()

Creates an independent duplicate of the task.

WARNING: The current implementation performs a deepcopy() and updates a few members; proper behavior with respect to input/output BDPs, filenames, keywords, etc., are still TBD.

Returns: Reference to the new (cloned) task.

delete(delfiles=True)

Method to delete the AT and underlying BDPs.

Parameters:

delfiles : Boolean

Whether or not to delete the actual files on disk (default

is True)

It is recommended that any AT that stores images inside of lists, dictionaries,

tuples, etc. override this method with a customized version.

delinput(slot)

Delete a specific BDP in the _bdp_in list

Parameters:

slot : int

The slot to remove the BDP from

deloutput(slot)

Delete a specific BDP in the _bdp_out list

Parameters:

slot : int

The slot to remove the BDP from

dir(filename=None)

Return the absolution directory of this ADMIT project or a derefenced filename address. This includes the potentially operating system dependant directory separator. This way filenames can be constructed as follows: Admit.dir() + ‘foobar.dat’ or Admit.dir(‘foobar.dat’)

Parameters:

filename : filename (optional)

Optional filename

Returns:

string

The directory name within which all ADMIT files reside

execute(args=None)

Executes the task.

Execution performs the following actions:
  1. Update BDP inputs (if args is given).
  2. Validate task keywords.
  3. Validate task BDP inputs.
  4. Call task run().
  5. Mark task up to date.
  6. Mark persistent BDP outputs out of date.
Parameters:

args: list of BDPs, optional

List of BDP inputs used by run() method; default is to use ehe most recently supplied inputs.

Returns:

None

See also

run

Notes

If args is not given, the previously cached BDP inputs are reused; hence execution (input validation) will fail if required arguments are absent.

getVersion()

Return the version string

Returns:

String

The version of the AT

getdtd(fl)

Method to write out the dtd data

Parameters:

fl : file handle

The file handle to write to

Returns:

None

getkey(key)

Retrieval value for a key. If the key had not been set yet, a default value can be returned, else None is returned. Notice no type checking has been done here, the caller is responsible for this.

See also haskey()

Parameters:

key : string

The key whose value is to be returned

Returns:

The value of the key

haskey(key)

Query if a key exists for an AT. Returns True/False

Parameters:

key : string

The key to check for existence

Returns:

Boolean

True if the key exists, False otherwise

isequal(at)

Method to determine if two ATs are the same. Useful for testing.

Parameters:

at : AT

The AT to compare against

Returns:

Boolean

Whether or not the ATs are equal

isstale()

Return True/False if an AT is up to date

Returns:

boolean

Whether or not the AT is up to date

len2()

Return the length of _bdp_in and _bdp_out in a tuple If you just want the _bdp_out, the intrinsic len(my_at) Thus my_at.len2()[1] is the same as len(my_at)

Returns:

Tuple

Tuple contains 2 values, the length of _bdp_in and _bdp_out

markChanged()

Mark an AT that it’s state was changed, so it would need to be rerun. The FlowManager will take care of any dependants that will need to be marked as well. Use “markUpToDate” if you want the opposite function.

markUpToDate()

Sets the _stale state to indicate that the AT does not need to be run

mkdir(dirname)

Make a directory in the ADMIT hierarchy if it doesn’t exist yet It also allows an absolute path, in the classical unix sense. @todo this routine is identical to the one in Admit()

run()

Runs the task.

Running a task transforms its input BDPs into output BDPs according to its function. Following this call the output BDPs accurately reflect the current state of the task (keywords and BDP inputs). Each concrete AT must implement its own run() method.

Returns:None

See also

execute

save()
set_bdp_in(bin=[])

Validate the _valid_bdp_in list and digest it into the appropriate attributes

Parameters:

bin : List

List containing tuples of the valid BDP inputs and their counts

set_bdp_out(bout=[])

Validate the _valid_bdp_out list and digest it into the appropriate attributes

Parameters:

bout : List

List containing tuples of the valid BDP outputs and their counts

setkey(name='', value='', isinit=False)

set keys, two styles are possible:

  1. name = {key:val} e.g. setkey({“a”:1})
  2. name = “key”, value = val e.g. setkey(“a”,1)

This method checks the type of the keyword value, as it must remain the same. Also new keywords cannot be added.

Parameters:

name : dictionary or string

Dictionary of keyword value pais to set or a string with the name of a single key

value : any

The value to change the keyword to

Returns:

None

show()

Return the type of the AT

Returns:

string

The type of the AT

summary()

place holder empty summary in case the derived class doesn’t implement it

uptodate()

Returns the current state of the _stale flag

Returns:

boolean

The current state of the _stale flag

validateinput(describe=False)

Method to validate the _bdp_in’s against a dictionary of expected types. Returns False if anything is amiss. If describe == True then the return is a tuple containing True/False and a list of what was found/not found.

write(node)

Method to write the AT to disk

Parameters:

node : elemettree node

The node to attach to (usually supplied by flowmanager)

Returns:

node : elemettree node

The modified node

dtd : Text string of the dtd

Previous topic

ADMIT Package

This Page