예제 #1
0
    def test_parallel_experiment(self):
        """
        Test running an experiment in parallel
        Returns
        -------
  
        """
        relative_path_to_file = '../models/Teacup.mdl'
        directory = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
        mdl_file = os.path.join(directory, relative_path_to_file)
         
        model = PysdModel(mdl_file=mdl_file)
         
        model.uncertainties = [RealParameter('Room Temperature', 33, 120)]
        model.outcomes = [TimeSeriesOutcome('Teacup Temperature')]

        with MultiprocessingEvaluator(model, 2) as evaluator:
            perform_experiments(model, 5, evaluator=evaluator)
예제 #2
0
    model = NetLogoModel('predprey',
                         wd="./models/predatorPreyNetlogo",
                         model_file="Wolf Sheep Predation.nlogo")
    model.run_length = 100
    model.replications = 1

    model.uncertainties = [
        RealParameter("grass-regrowth-time", 1, 99),
        RealParameter("initial-number-sheep", 1, 200),
        RealParameter("initial-number-wolves", 1, 200),
        RealParameter("sheep-reproduce", 1, 20),
        RealParameter("wolf-reproduce", 1, 20),
    ]

    model.outcomes = [
        TimeSeriesOutcome('sheep'),
        TimeSeriesOutcome('wolves'),
        TimeSeriesOutcome('grass'),
        TimeSeriesOutcome('TIME')
    ]

    #perform experiments
    n = 10

    with MultiprocessingEvaluator(model) as evaluator:
        results = perform_experiments(model, n, evaluator=evaluator)

    fn = r'./data/{} runs.tar.gz'.format(n)
    save_results(results, fn)

    print "finish"
예제 #3
0
    model.uncertainties = uncertainties

    model.outcomes = [ArrayOutcome('stedin_capacity'),
                      ArrayOutcome('stedin_load'),
                      ArrayOutcome('tennet_capacity'),
                      ArrayOutcome('tennet_load'),
                      ArrayOutcome('gasunie_capacity'),
                      ArrayOutcome('investments'),
                      ArrayOutcome('stedin capex'),
                      ArrayOutcome('tennet capex'),
                      ArrayOutcome('gasunie capex'),
                      ArrayOutcome('collaborative capex'),
                      ArrayOutcome('h2_import'),
                      ArrayOutcome('stedin_lost'),
                      ArrayOutcome('first_failure'),
                      ArrayOutcome('missed_over_time')
                      ]

    _logger.info(f"{len(uncertainties)} uncertainties defined")
    _logger.info(f"{len(model.replications)} replications defined")


    n_scenarios = 2500
    print(datetime.datetime.now())
    # with SequentialEvaluator(model) as evaluator:
    with MultiprocessingEvaluator(model, n_processes=56) as evaluator:
        results = evaluator.perform_experiments(n_scenarios, uncertainty_sampling=MC)

    save_results(results, f'./results/{n_scenarios}_scenarios_{len(model.replications)} replications_{datetime.datetime.now()}_MC.tar.gz')
    print(datetime.datetime.now())