User Guide
Creating a database
To create a database, use the class Manager. A manager class takes a path name, schema name and unique identifier for a job: dbmanager.Manager.__init__() function:
To attach a parametric space to a job, initialize the manager class with parameters
dbmanager.Manager.initialize() function:
To register an output field,
Managerclass accepts a numpy array. One can describe as many output fields as one requires. In current version, an output field can either be scalar or 1D arrays. Make use of functiondbmanager.Manager.registerQuantities()to register outfields.To push the output field values to the database, use the function
`dbmanager.Manager.pushQuantity()
To finalize a run use the dbmanager.Manager.finalize() function:
The following is the an example script to create a schema.
import time
from dbmanager import Manager
import argparse
import numpy as np
path = '.'
schema = 'trial'
parser = argparse.ArgumentParser()
parser.add_argument('--model', type=str, default='old')
parser.add_argument('--flux', type=float, default=1e-3)
parser.add_argument('--porosity', type=float, default=0.4)
parser.add_argument('--nodes', type=int, default=5)
parser.add_argument('--time', type=float, default=1)
parser.add_argument('--dt', type=float, default=1e-1)
args = parser.parse_args()
outputs = {'x' : np.zeros((1, args.nodes)),
'y' : 0}
nb_steps = 10
# define and initialize the manager
manager = Manager(path, schema, uid='test')
manager.initialize(parameters=vars(args))
manager.registerQuantities(outputs)
# if simualtions produces additional outputs, can register
# its name and format in manager, at the finalize stage manager
# will count the number of particular outputs produced and will
# update the database
additionals = {'flux' : 'pvd', 'stress' : 'txt'}
manager.registerAdditionals(additionals)
# run your simulations and push quantities to manager
for i in range(nb_steps):
stress = np.ones((10, 2))
outputs['x'] = np.ones((1, args.nodes))*i
outputs['y'] = i
manager.pushQuantity(outputs)
# get the location of database to save additional outputs in other formats
database_location = manager.getDatabaseLocation()
np.savetxt(database_location + '/stress-01.txt', stress)
# finalize the manager at the end of the simulation
manager.finalize()
Retrieving data
To retrieve data, use the class dbmanager.Digger.
To list all the parametric points (or total jobs) within a schema, use the function
dbmanager.Digger.showParametericSpace()
To chose a specific a point (or job) from the parameteric space, we
provide a dedicated class Job.
To choose a parameteric point, make use of the function
dbmanager.Job.digID()Furthermore, to show the output fields present for the job, on can use
dbmanager.Job.showDatabaseSpace()functionTo retreive, the data for a specific job, two function are provided.
dbmanager.Job.digQuantitiesForJob()allows the user to retreive data for a specific output field only.
The following is the an example script to retrieve data from a schema.
from dbmanager import Digger, bcolors
import matplotlib.pyplot as plt
path = '.'
schema = 'trial'
digger = Digger(path,schema)
# check the parameteric space of the schema
digger.showParametericSpace(shell_display=True)
digger.plotParametericSpace()
# Point in the parametric space
param_dict = { 'model' : 'old',
'dt' : 1e-1,
'time' : 1.0,
'nodes' : 5,
'flux' : 1e-3,
'porosity': 0.4}
# check the database space for a particular point in parameteric space
digger.job.showDatabaseSpace(param_dict, shell_display=True)
# check the additional space for a particular point in parameteric space
digger.job.showAdditionalSpace(param_dict, shell_display=True)
digger.job.showParameterSpace(param_dict, shell_display=True)
print('Job id', digger.job.digID(param_dict)[0])
# extract output for a particular point in parameteric space
val = digger.job.digQuantitiesForJob(['y'], digger.job.digID(param_dict)[0])
print(f"{bcolors.PARAMETERSPACE}Value of y ={bcolors.ENDC}", val['y'])