def git_info(filename=None, check=False, comments=None, old_info=None, die=False, indent=2, verbose=True, frame=2, **kwargs): ''' Get current git information and optionally write it to disk. Simplest usage is cv.git_info(__file__) Args: filename (str): name of the file to write to or read from check (bool): whether or not to compare two git versions comments (dict): additional comments to include in the file old_info (dict): dictionary of information to check against die (bool): whether or not to raise an exception if the check fails indent (int): how many indents to use when writing the file to disk verbose (bool): detail to print frame (int): how many frames back to look for caller info kwargs (dict): passed to sc.loadjson() (if check=True) or sc.savejson() (if check=False) **Examples**:: cv.git_info() # Return information cv.git_info(__file__) # Writes to disk cv.git_info('covasim_version.gitinfo') # Writes to disk cv.git_info('covasim_version.gitinfo', check=True) # Checks that current version matches saved file ''' # Handle the case where __file__ is supplied as the argument if isinstance(filename, str) and filename.endswith('.py'): filename = filename.replace('.py', '.gitinfo') # Get git info calling_file = sc.makefilepath(sc.getcaller(frame=frame, tostring=False)['filename']) cv_info = {'version':cvv.__version__} cv_info.update(sc.gitinfo(__file__, verbose=False)) caller_info = sc.gitinfo(calling_file, verbose=False) caller_info['filename'] = calling_file info = {'covasim':cv_info, 'called_by':caller_info} if comments: info['comments'] = comments # Just get information and optionally write to disk if not check: if filename is not None: output = sc.savejson(filename, info, indent=indent, **kwargs) else: output = info return output # Check if versions match, and optionally raise an error else: if filename is not None: old_info = sc.loadjson(filename, **kwargs) string = '' old_cv_info = old_info['covasim'] if 'covasim' in old_info else old_info if cv_info != old_cv_info: # pragma: no cover string = f'Git information differs: {cv_info} vs. {old_cv_info}' if die: raise ValueError(string) elif verbose: print(string) return
def debuginfo(output=False): import sciris as sc outstr = '\nHealthPrior debugging info:\n' outstr += ' Version: %s\n' % version outstr += ' Branch: %s\n' % sc.gitinfo()['branch'] outstr += ' SHA: %s\n' % sc.gitinfo()['hash'] outstr += ' Date: %s\n' % sc.gitinfo()['date'] outstr += ' Path: %s\n' % HPpath() if output: return outstr else: print(outstr) return None
def git_info(filename=None, check=False, old_info=None, die=False, verbose=True, **kwargs): ''' Get current git information and optionally write it to disk. Args: filename (str): name of the file to write to or read from check (bool): whether or not to compare two git versions old_info (dict): dictionary of information to check against die (bool): whether or not to raise an exception if the check fails **Examples**:: cv.git_info('covasim_version.json') # Writes to disk cv.git_info('covasim_version.json', check=True) # Checks that current version matches saved file ''' info = sc.gitinfo(__file__) if not check: # Just get information if filename is not None: output = sc.savejson(filename, info, **kwargs) else: output = info else: if filename is not None: old_info = sc.loadjson(filename, **kwargs) string = '' if info != old_info: string = f'Git information differs: {info} vs. {old_info}' if die: raise ValueError(string) elif verbose: print(string) return output
def version_info(): print( f'Loading SynthPops v{spv.__version__} ({spv.__versiondate__}) from {spd.settings.thisdir}' ) print(f'Data folder: {spd.settings.datadir}') try: gitinfo = sc.gitinfo(__file__) print(f'Git information:') sc.pp(gitinfo) except: pass # Don't worry if git info isn't available return
def get_version_info(): ''' Return the information about the project. ''' gitinfo = sc.gitinfo(__file__) version_info = { 'version': hp.version, 'date': hp.versiondate, 'gitbranch': gitinfo['branch'], 'githash': gitinfo['hash'], 'gitdate': gitinfo['date'], 'server': socket.gethostname(), 'cpu': '%0.1f%%' % psutil.cpu_percent(), } return version_info
def __init__(self, name='Default', burdenfile=None, interventionsfile=None, country=None, makepackage=True, verbose=2): ''' Initialize the project ''' ## Define the structure sets self.burdensets = sc.odict() self.intervsets = sc.odict() self.packagesets = sc.odict() ## Define other quantities self.name = name self.country = country self.uid = sc.uuid() self.created = sc.now() self.modified = sc.now() self.version = hp.version self.gitinfo = sc.gitinfo(__file__) self.filename = None # File path, only present if self.save() is used ## Load burden spreadsheet, if available if burdenfile: self.loadburden(filename=burdenfile, verbose=verbose) ## Load interventions spreadsheet, if available if interventionsfile: self.loadinterventions(filename=interventionsfile, verbose=verbose) ## Combine into health package, if available if makepackage and burdenfile and interventionsfile: self.makepackage() return None
# This code is used to build the pars_* file containing parameter configuations and corresponding rand_seed values. import os import sciris as sc import optuna as op import numpy as np import pandas as pd import create_sim as cs import covasim_schools as cvsch import covasim as cv import synthpops as sp cv.check_save_version('1.7.6', folder='gitinfo', comments={'SynthPops':sc.gitinfo(sp.__file__)}) pop_size = 2.25e5 folder = 'v20201019' children_equally_sus = False alternate_symptomaticity = True # This is the data we're trying to fit to_fit = { 'cases_begin': 75, # per 100k over 2-weeks 'cases_end': 75, # per 100k over 2-weeks 're': 1.0, 'prevalence': 0.002, 'yield': 0.024, # 2.4% positive 'tests': 225, # per 100k (per day) - 225 is 5000 tests in 2.23M pop per day } # And here are the weights for each element weight = { 'cases_begin': 1, # per 100k over 2-weeks
import os import numpy as np import covasim as cv import create_sim as cs import sciris as sc import matplotlib.pyplot as plt import covasim_schools as cvsch import testing_scenarios as t_s import synthpops as sp from calibrate_model import evaluate_sim from pathlib import Path cv.check_save_version('1.7.6', folder='gitinfo', comments={'SynthPops': sc.gitinfo(sp.__file__)}) do_run = True children_equally_sus = False alternate_symptomaticity = True assert (not children_equally_sus or not alternate_symptomaticity) par_inds = (0, 30) # First and last parameters to run pop_size = 2.25e5 # 1e5 2.25e4 2.25e5 batch_size = 30 folder = 'v20201019' if children_equally_sus: stem = f'calib_cheqsu_{par_inds[0]}-{par_inds[1]}' calibfile = os.path.join( folder,
def set_metadata(obj): ''' Set standard metadata for an object ''' obj.version = spv.__version__ obj.created = sc.now() obj.git_info = sc.gitinfo(__file__, verbose=False) return
average_teacher_teacher_degree=3, average_student_all_staff_ratio=15, average_additional_staff_degree=20, ) if __name__ == '__main__': T = sc.tic() pop = sp.make_population(**pars) elapsed = sc.toc(T, output=True) for person in [6, 66, 666]: print(f'\n\nPerson {person}') sc.pp(pop[person]) print('\n\n') print(sc.gitinfo(sp.__file__)) print(sp.version.__version__) popkeys = list(pop.keys()) stridekeys = [popkeys[i] for i in range(0, len(pop), stride)] subpop = {k: pop[k] for k in stridekeys} if do_save: sc.savejson(f'pop_v{sp.version.__version__}.json', subpop, indent=2) print('\n\n') pps = pars["n"] / elapsed print( f'Total time: {elapsed:0.3f} s for {pars["n"]} people ({pps:0.0f} people/second)' )