Mongo
MongoBuffer class
MongoBuffer
MongoBuffer (pool:Optional[tspace.storage.pool.mongo.MongoPool]=None, batch_size:int, driver:tspace.config.drivers.Driver, truck:tspace.config.vehicles.Truck, meta:tspace.data.core.ObservationMeta, db_config:tspace.config.db.DBConfig, torque_table_row_names:list[str], query:Optional[tspace.data.core.PoolQuery]=None, logger:Opti onal[<module'logging'from'/opt/hostedtoolcache/Python/3.11.9 /x64/lib/python3.11/logging/__init__.py'>]=None, dict_logger:Optional[dict]=None)
*A Buffer connected with a MongoDB database pool
Args:
batch_size: number of documents for batch sampling
driver: driver of the vehicle
truck: subject vehicle
meta: metadata of the observation
db_config: config for mongodb (str) or DBConfig (dict)
the key leads to a config with db_name and collection name with a switch for record or episode:
- string for db server name
- or string of the format "usr:password@host:port"
for mongo_cluster:
Host="10.10.0.4", # url for the database server
port="23000", # port for the database server
user_name="admin", # username for the database server
password="ty02ydhVqDj3QFjT", # password for the database server
==> mongo_key = "admin:ty02ydhVqDj3QFjT@10.10.0.4:23000"
torque_table_row_names: list of torque table row names, e.g. ['r0, r1, ..., r9']
query: query for the pool
pool: pool of the database, a [`MongoPool`](https://Binjian.github.io/tspace/05.storage.pool.mongo.html#mongopool) instance
logger: logger for the buffer
dict_logger: dict logger for the buffer*
MongoBuffer.__post_init__
MongoBuffer.__post_init__ ()
set logger and load pool
MongoBuffer.load
MongoBuffer.load ()
load pool from database
MongoBuffer.find
MongoBuffer.find (idx)
find a record by index
MongoBuffer.close
MongoBuffer.close ()
close the pool and the database
MongoBuffer.sample
MongoBuffer.sample ()
*Sampling a batch of records or episodes from the pool.
Decoding the batch observations from mongodb nested dicts to pandas dataframe flatten is used to adapt to model interface
Return:
A quadruple of numpy arrays (states, actions, rewards, next_states)*
MongoBuffer.decode_batch_records
MongoBuffer.decode_batch_records (df:pandas.core.frame.DataFrame)
*Sample a batch of records from the pool.
Args:
df: dataframe of sampled from the record collection of the pool
Return:
A quadruple of numpy arrays (states, actions, rewards, next_states)*