Support code for the community code interfaces

class amuse.rfi.core.CodeFunction(interface, owner, specification)

Implementation of the runtime call to the remote process.

Performs the encoding of python arguments into lists of values, sends a message over an MPI channel and waits for a result message, decodes this message and returns.

class amuse.rfi.core.CodeFunctionWithUnits(interface, owner, specification)
class amuse.rfi.core.CodeInterface(name_of_the_worker='worker_code', **options)

Abstract base class for all interfaces to legacy codes.

When a subclass is instantiated, a number of subprocesses will be started. These subprocesses are called workers as they implement the interface and do the actual work of the instantiated object.

before_get_data_store_names()

called before getting data store names (for state model) - should eventually not be necessary

before_get_parameter()
Called everytime just before a parameter is retrieved in using::

instance.parameter.name

before_new_set_instance()

(Can be) called everytime just before a new set is created

before_set_interface_parameter()
Called everytime just before a interface parameter is updated in using::

instance.parameter.name = newvalue

before_set_parameter()
Called everytime just before a parameter is updated in using::

instance.parameter.name = newvalue

get_working_directory
int32 get_working_directory(char * * working_directory);
function get_working_directory(working_directory)
  character(len=*) :: working_directory
  integer :: get_working_directory
end function
Parameters:

working_directory (string, OUT) –

Returns:

initialize_mpi

Is MPI initialized in the code or not. Defaults to True if MPI is available

internal__accept_on_port
int32 internal__accept_on_port(char * port_identifier, 
  int32 * comm_identifier);
function internal__accept_on_port(port_identifier, comm_identifier)
  character(len=*) :: port_identifier
  integer :: comm_identifier
  integer :: internal__accept_on_port
end function
Parameters:
  • port_identifier (string, IN) –

  • comm_identifier (int32, OUT) –

Returns:

internal__activate_communicator
int32 internal__activate_communicator(int32 comm_identifier);
function internal__activate_communicator(comm_identifier)
  integer :: comm_identifier
  integer :: internal__activate_communicator
end function
Parameters:

comm_identifier (int32, IN) –

Returns:

internal__become_code
int32 internal__become_code(int32 number_of_workers, char * modulename, 
  char * classname);
function internal__become_code(number_of_workers, modulename, classname)
  integer :: number_of_workers
  character(len=*) :: modulename, classname
  integer :: internal__become_code
end function
Parameters:
  • number_of_workers (int32, IN) –

  • modulename (string, IN) –

  • classname (string, IN) –

Returns:

internal__connect_to_port
int32 internal__connect_to_port(char * port_identifier, 
  int32 * comm_identifier);
function internal__connect_to_port(port_identifier, comm_identifier)
  character(len=*) :: port_identifier
  integer :: comm_identifier
  integer :: internal__connect_to_port
end function
Parameters:
  • port_identifier (string, IN) –

  • comm_identifier (int32, OUT) –

Returns:

internal__get_message_polling_interval

Gets the message polling interval for MPI header messages, in microseconds

int32 internal__get_message_polling_interval(int32 * polling_interval);
function internal__get_message_polling_interval(polling_interval)
  integer :: polling_interval
  integer :: internal__get_message_polling_interval
end function
Parameters:

polling_interval (int32, OUT) –

Returns:

internal__open_port
int32 internal__open_port(char * * port_identifier);
function internal__open_port(port_identifier)
  character(len=*) :: port_identifier
  integer :: internal__open_port
end function
Parameters:

port_identifier (string, OUT) –

Returns:

internal__set_message_polling_interval
int32 internal__set_message_polling_interval(int32 polling_interval);
function internal__set_message_polling_interval(polling_interval)
  integer :: polling_interval
  integer :: internal__set_message_polling_interval
end function
Parameters:

polling_interval (int32, IN) –

Returns:

redirection

Redirect the output of the code to null, standard streams or file

reuse_worker

Do not stop a worker, re-use an existing one

set_working_directory
int32 set_working_directory(char * working_directory);
function set_working_directory(working_directory)
  character(len=*) :: working_directory
  integer :: set_working_directory
end function
Parameters:

working_directory (string, IN) –

Returns:

class amuse.rfi.core.LegacyFunctionSpecification(counter=[233])

Specification of a legacy function. Describes the name, result type and parameters of a legacy function.

The legacy functions are implemented by legacy codes. The implementation of legacy functions is in C/C++ or Fortran. To interact with these functions a specification of the legacy function is needed. This specification is used to determine how to encode and decode the parameters and results of the function. Objects of this class describe the specification of one function.

>>> specification = LegacyFunctionSpecification()
>>> specification.name = "test"
>>> specification.addParameter("one", dtype="int32", direction = specification.IN)
>>> specification.addParameter("two", dtype="float64", direction = specification.OUT)
>>> specification.result_type = "int32"
>>> print specification
function: int test(int one)
output: double two, int __result
IN = <object object>

Used to specify that a parameter is used as an input parameter, passed by value

INOUT = <object object>

Used to specify that a parameter is used as an input and an outpur parameter, passed by reference

LENGTH = <object object>

Used to specify that a parameter is used as the length parameter for the other parameters

OUT = <object object>

Used to specify that a parameter is used as an output parameter, passed by reference

addParameter(name, dtype='i', direction=<object object>, description='', default=None, unit=None)

Extend the specification with a new parameter.

The sequence of calls to addParameter is important. The first call will be interpreted as the first argument, the second call as the second argument etc.

Parameters:
  • name – Name of the parameter, used in documentation and function generation

  • dtype – Datatype specification string

  • direction – Direction of the argument, can be IN, OUT or INOUT

  • description – Description of the argument, for documenting purposes

  • default – An optional default value for the parameter

class amuse.rfi.core.PythonCodeInterface(implementation_factory=None, name_of_the_worker=None, **options)

Base class for codes having a python implementation

Parameters:

implementation_factory – Class of the python implementation

class amuse.rfi.core.legacy_function(specification_function)

Decorator for legacy functions.

The decorated function cannot have any arguments. This means the decorated function must not have a self argument.

The decorated function must return a LegacyFunctionSpecification.

>>> class LegacyExample(object):
...     @legacy_function
...     def evolve():
...          specification = LegacyFunctionSpecification()
...          return specification
...
>>> x = LegacyExample()
>>> x.evolve.specification 
<amuse.rfi.core.LegacyFunctionSpecification object at 0x...>
>>> LegacyExample.evolve 
<amuse.rfi.core.legacy_function object at 0x...>
>>> x.evolve 
<amuse.rfi.core.CodeFunction object at 0x...>
Parameters:

specification_function – The function to be decorated

specification

Returns the specification for the call.

amuse.rfi.core.stop_interfaces(exceptions=[])

Stop the workers of all instantiated interfaces.

All instantiated interfaces will become unstable after this call!