ThoughtForge Client

This class manages communication between the local client and the ThoughtForge servers. To implement a ThoughtForge client, inherit from the base class.

ThoughtForge Client Session Base Class

class 
thoughtforge_client.thoughtforge_client.BaseThoughtForgeClientSession(json_specification, 
host=None, port=None, protocol='https', api_key=None, model_data=None)

This class is a base class for implementing client applications on the ThoughtForge platform. It manages the protocol for talking to the server and is inteded to be inherited by users to implement simple interactive simulations.

See also
Please see examples at https://github.com/thoughtforge-ai/thoughtforge-examples for usage examples of this class.

Parameters:

  • file_name (str) – The parameter file for specifying sensors, motors and model configuration
  • host (str) – Host address for the destination ThoughtForge server. Defaults to None. If left unset, will be populated from the environment variable ‘THOUGHTFORGE_HOST’
  • port (int) – Host port for the destination ThoughtForge server. Defaults to None. If left unset, will be populated from the environment variable ‘THOUGHTFORGE_PORT’
  • model_data (dict) – Optional parameter for supplying saved model data at initialization of the sim.

debug_data_received_notification(debug_data_dict)

This function is called automatically when debug data is being collected. Implement this function in a user client session to perform custom runtime debugging.

Note
Debug mode can be enabled in a client params file by setting “enable_debug”: true
Note
Here are examples of things to look at:
print("Global stability rate:", round(debug_data_dict['global_stability_rate'], 6))
print("Global energy estimate", round(debug_data_dict['global_energy_estimate'], 6))
print("Per-block stability rates:", debug_data_dict['block_stability_rates'])
print("Per-block energy estimates:", debug_data_dict['block_energy_estimates'])
print("Per-block stable times:", debug_data_dict['block_stable_times'])

Parameters:
debug_data_dict (dict) – A dictionary of global and block-level debug statistics

get_num_motors()
returns the number of motors that have been added to the session modelR
Returns:
The number of Motors.
Return type:
int

get_num_sensors()
‍returns the number of sensors that have been added to the session modelReturns:
The number of sensors.
Return type:
int

preprocess_specification(json_specification)

This function allows clients to preprocess their json specifications before sending to the server

session_initialization_notification()

This function is called to notify the start of the session. This is an opportunity to perform initialization that is needed.

sim_ended_notification()

This function can optionally be implemented by users to handle end-of-session needs or to report on results

sim_started_notification()

This function can optionally be implemented by users to initialize any simulation environment parameters, and set the initial sensor state from the simulation. If this function isn’t implemented, initial sensor values are assumed to be 0.

Returns:
initial sensor state of the simulation
Return type:
dict

stop_sim()

This function requests stopping of the simulation. Client applications can call this to request shutdown of the simulation loop

update(motor_action_dict)

Implement this function in client code to update environment state and return sensor data.

update() is called automatically during simulation and is intended to be the primary point of entry for users to define the interaction between the thoughtforge model and the specific simulation environment.

Parameters:

motor_action_dict (dict) – A dictionary of motor names to motor values generated by the model

Returns:
A dictionary of sensor names to sensor values to send to the model
Return type:
dict