meld.interfaces.ICommunicator

class meld.interfaces.ICommunicator[source]

Bases: ABC

Interface for communication between leader and workers

__init__()

Methods

__init__()

barrier()

Wait until all workers reach this point

broadcast_all_states_to_workers(states)

Broadcast all states to all workers.

distribute_alphas_to_workers(all_alphas)

Distribute alphas to workers

distribute_states_to_workers(all_states)

Distribute a block of states to each worker.

gather_energies_from_workers(energies_on_leader)

Receive energies from each worker.

gather_states_from_workers(state_on_leader)

Receive states from all workers

initialize()

Initialize and start MPI

is_leader()

Is this the leader node?

negotiate_device_id()

Negotiate CUDA device id

receive_all_states_from_leader()

Receive all states from leader.

receive_alphas_from_leader()

Receive a block of alphas from leader.

receive_states_from_leader()

Get the block of states to run for this step

send_energies_to_leader(energies)

Send a block of energies to the leader.

send_states_to_leader(block)

Send a block of states to the leader

Attributes

n_atoms

number of atoms

n_replicas

number of replicas

n_workers

number of workers

rank

rank of this worker

abstract barrier()[source]

Wait until all workers reach this point

Return type

None

abstract broadcast_all_states_to_workers(states)[source]

Broadcast all states to all workers.

Parameters

states (Sequence[IState]) – a list of states

Return type

None

abstract distribute_alphas_to_workers(all_alphas)[source]

Distribute alphas to workers

Parameters

all_alphas (List[float]) – the alpha values to be distributed

Return type

List[float]

Returns

the block of alpha values for the leader

abstract distribute_states_to_workers(all_states)[source]

Distribute a block of states to each worker.

Parameters

all_states (Sequence[IState]) – states to be distributed

Return type

List[IState]

Returns

the block of states to run on the leader node

abstract gather_energies_from_workers(energies_on_leader)[source]

Receive energies from each worker.

Parameters

energies_on_leader (ndarray) – the energies from the leader

Return type

ndarray

Returns

a square matrix of every state on every replica to be used for replica exchange

Note

Each row of the output matrix represents a different Hamiltonian. Each column represents a different state. Each worker will compute multiple rows of the output matrix.

abstract gather_states_from_workers(state_on_leader)[source]

Receive states from all workers

Parameters

states_on_leader – the block of states on the leader after simulating

Return type

List[IState]

Returns

A list of states, one from each replica.

abstract initialize()[source]

Initialize and start MPI

Return type

None

abstract is_leader()[source]

Is this the leader node?

Return type

bool

Returns

True if we are the leader, otherwise False

abstract property n_atoms: int

number of atoms

abstract property n_replicas: int

number of replicas

abstract property n_workers: int

number of workers

abstract negotiate_device_id()[source]

Negotiate CUDA device id

Return type

int

Returns

the cuda device id to use

abstract property rank: int

rank of this worker

abstract receive_all_states_from_leader()[source]

Receive all states from leader.

Return type

Sequence[IState]

Returns

a list of states to calculate the energy of

abstract receive_alphas_from_leader()[source]

Receive a block of alphas from leader.

Return type

List[float]

Returns

the block of alpha values for this worker

abstract receive_states_from_leader()[source]

Get the block of states to run for this step

Return type

List[IState]

Returns

the block of states to run for this step

abstract send_energies_to_leader(energies)[source]

Send a block of energies to the leader.

Parameters

energies (ndarray) – block of energies to send to the leader

Return type

None

Note

Each row represents a different Hamiltonian. Each column represents a different state.

abstract send_states_to_leader(block)[source]

Send a block of states to the leader

Parameters

block (Sequence[IState]) – block of states to send to the leader.

Return type

None