Skip to content

example t07 optuna_calibration error #428

@yycccyk

Description

@yycccyk

Describe the bug

Examples that have not been modified run incorrectly
'Covasim_calibration. db' is being used by another program that doesn't know what it is

To reproduce

Steps to reproduce the behavior:

For model issues:

'''
Example for running built-in calibration with Optuna
'''

import sciris as sc
import covasim as cv

# Create default simulation
pars = sc.objdict(
    pop_size       = 10_000,
    start_day      = '2020-02-01',
    end_day        = '2020-04-11',
    beta           = 0.015,
    rel_death_prob = 1.0,
    interventions  = cv.test_num(daily_tests='data'),
    verbose        = 0,
)
sim = cv.Sim(pars=pars, datafile='example_data.csv')

# Parameters to calibrate -- format is best, low, high
calib_pars = dict(
    beta           = [pars.beta, 0.005, 0.20],
    rel_death_prob = [pars.rel_death_prob, 0.5, 3.0],
)

if __name__ == '__main__':

    # Run the calibration
    n_trials = 25
    n_workers = 4

    calib = sim.calibrate(calib_pars=calib_pars, n_trials=n_trials, n_workers=n_workers)

    # Plot the results
    calib.plot(to_plot=['cum_tests', 'cum_diagnoses', 'cum_deaths'])

Screenshots or outputs

Traceback (most recent call last):
File "D:\pycharm\PyCharm 2024.1.4\plugins\python\helpers\pydev\pydevconsole.py", line 364, in runcode
coro = func()
File "", line 1, in
File "D:\pycharm\PyCharm 2024.1.4\plugins\python\helpers\pydev_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "D:\pycharm\PyCharm 2024.1.4\plugins\python\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "E:\github-models\covasim-3.1.4\examples\t07_optuna_calibration.py", line 32, in
calib = sim.calibrate(calib_pars=calib_pars, n_trials=n_trials, n_workers=n_workers)
File "E:\github-models\covasim-3.1.4\covasim\sim.py", line 1202, in calibrate
calib.calibrate()
File "E:\github-models\covasim-3.1.4\covasim\analysis.py", line 1558, in calibrate
self.make_study()
File "E:\github-models\covasim-3.1.4\covasim\analysis.py", line 1532, in make_study
self.remove_db()
File "E:\github-models\covasim-3.1.4\covasim\analysis.py", line 1521, in remove_db
os.remove(self.run_args.db_name)
PermissionError: [WinError 32] Another program is using this file and the process cannot access it. : 'covasim_calibration.db'

Platform (please complete the following information):

  • Covasim version: [e.g.3.1.4]
  • OS: [windows]
  • Other platform information: [using Anaconda Python]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions