Hectiq Lab

Messages

Requires pyhectiqlab 3.1.0 or later.

The messages are used to communicate to active runs. You can send messages to a run and retrieve them from the run. It is mainly use to change parameters, or take actions on the run (saving models, evaluation, etc.).

Publish a message

You can publish a message to the server using the SDK or the web application. Usually, the messages are published using the CLI or the web application. If run is not given, the message goes to the current run. From the CLI, give the run ID.

hectiq-lab Message.publish --run "9sk7x6" --key "learning-rate" --value 0.001 
NameTypeDefaultDescription
runOptional[Union[str, int]]NoneThe run ID or rank. If the rank is used, then the project must be specified. If None, the current run is used.
keystrThe key of the message.
valueAnyThe value of the message.
projectOptional[str]The project ID. Must be specified if run is the rank.
wait_responseboolFalseSet to true to publish sync. If False, the message is published in background.

Retrieve messages

You can retrieve pending messages from the server using get_message. You must provide the key of the message you want to retrieve. If the message is not available, the method will return None.

import pyhectiqlab.functional as hl
message = hl.get_message(key="learning-rate")
if message:
    message.ack() # Prevents the message from being retrieved again.
    print(message.value)
NameTypeDefaultDescription
keystrThe key of the message.
run_idOptional[str]The run ID. If not specified, the run ID is taken from the environment.

The method returns a Message object, or None. It has the following attributes:

NameTypeDescription
keystrThe key of the message.
valuestrThe value of the message.
ack()methodAcknowledge the message.

We recommend acknowledging the message before processing it to prevent it from being retrieved again or by another client.

The message must be acknowledged. Otherwise, it will be retrieved again.

If you wish to retrieve all messages, you can use the get_all_messages method. This method returns a list of Message objects.

import pyhectiqlab.functional as hl
messages = hl.get_all_messages()
for message in messages:
    message.ack()
    print(message.key, message.value)

Optimization

Messages are not fetched every time the hl.get_message (or Message.get) method is called. It is fetched at most every few seconds.

If you call this method at high frequency (multiple times per second), the message will be fetched every 5 seconds. The message is fetched in a separate thread, but the method get_message returns immediately. Hence, the messages are fetched in the background, and the method will return your message when it is available. This is to prevent the client from waiting for the message to be available.

On this page