salmon.backend.sampler
.Sampler
- class salmon.backend.sampler.Sampler(ident: str = '')
Run a sampling algorithm. Provides hooks to connect with the database and the Dask cluster.
- Parameters
- identstr
The algorithm idenfifier. This value is used to identify the algorithm in the database.
- Attributes
clear
Should the queries be cleared from the database?
Methods
clear_queries
(rj)Clear all queries that this sampler has posted from the database.
get_answers
(rj[, clear])Get all answers the frontend has received.
Get the model underlying the algorithm.
post_queries
(queries, scores[, rj, done])Post scored queries to the database.
process_answers
(answers)Process answers.
redis_client
([decode_responses])Get the database (/Redis client)
reset
(client, rj[, futures])Stop the algorithm.
run
(client)Run the algorithm.
save
()Save the sampler's state and current embedding to the database.
Serialize a query (so it can go in the database).
- property clear
Should the queries be cleared from the database?
- clear_queries(rj: RedisClient) bool
Clear all queries that this sampler has posted from the database.
- get_answers(rj: RedisClient, clear: bool = True) List[Answer]
Get all answers the frontend has received.
- get_model() Dict[str, Any]
Get the model underlying the algorithm.
- Returns
- stateDict[str, Any]
The state of the algorithm. This can be used for display on the dashboard or with an HTTP get request.
- post_queries(queries: List[Query], scores: List[float], rj: Optional[RedisClient] = None, done=None) int
Post scored queries to the database.
- Parameters
- queriesList[Query]
Queries to post to the database
- scoresList[float]
The scores for each query
- rjRedisClient, optional
The databaase
- Returns
- n_queriesint
The number of queries posted to the database.
- process_answers(answers: List[Answer])
Process answers.
- Parameters
- answersList[Answers]
Each answer is a dictionary. Each answer certainly has the keys “head”, “left”, “right” and “winner”, and may have the key “puid” for participant UID.
- Returns
- datadict
An update to self.__dict__.
- redis_client(decode_responses=True) RedisClient
Get the database (/Redis client)
- reset(client, rj, futures=None)
Stop the algorithm. The algorithm will be deleted shortly after this function is called.
- run(client: DaskClient)
Run the algorithm.
- Parameters
- clientDaskClient
A client to Dask.
- rjRedisClient
A Redist Client, a rejson.Client
Notes
This function runs the adaptive algorithm. Because it’s asynchronous, this function should return if
"reset" in rj.keys() and rj.jsonget("reset")
.
- save() bool
Save the sampler’s state and current embedding to the database.
- serialize_query(q: Query) str
Serialize a query (so it can go in the database).