def ensemble_simulations(<EOL>t, y0=None, volume=<NUM_LIT:1.0>, model=None, solver='<STR_LIT>',<EOL>is_netfree=False, species_list=None, without_reset=False,<EOL>return_type='<STR_LIT>', opt_args=(), opt_kwargs=None,<EOL>structures=None, rndseed=None,<EOL>n=<NUM_LIT:1>, nproc=None, method=None, errorbar=True,<EOL>**kwargs):
y0 = y0 or {}<EOL>opt_kwargs = opt_kwargs or {}<EOL>structures = structures or {}<EOL>for key, value in kwargs.items():<EOL><INDENT>if key == '<STR_LIT:r>':<EOL><INDENT>return_type = value<EOL><DEDENT>elif key == '<STR_LIT:v>':<EOL><INDENT>volume = value<EOL><DEDENT>elif key == '<STR_LIT:s>':<EOL><INDENT>solver = value<EOL><DEDENT>elif key == '<STR_LIT:m>':<EOL><INDENT>model = value<EOL><DEDENT><DEDENT>if model is None:<EOL><INDENT>model = ecell4.util.decorator.get_model(is_netfree, without_reset)<EOL><DEDENT>if species_list is None:<EOL><INDENT>species_list = list_species(model, y0.keys())<EOL><DEDENT>if rndseed is None:<EOL><INDENT>myseed = genseeds(n)<EOL><DEDENT>elif (not isinstance(rndseed, bytes) or len(rndseed) != n * <NUM_LIT:4> * <NUM_LIT:2>):<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>")<EOL><DEDENT>jobs = [{'<STR_LIT:t>': t, '<STR_LIT>': y0, '<STR_LIT>': volume, '<STR_LIT>': model, '<STR_LIT>': solver, '<STR_LIT>': species_list, '<STR_LIT>': structures, '<STR_LIT>': myseed}]<EOL>if method is None or method.lower() == "<STR_LIT>":<EOL><INDENT>retval = run_serial(singlerun, jobs, n=n, **kwargs)<EOL><DEDENT>elif method.lower() == "<STR_LIT>":<EOL><INDENT>retval = run_sge(singlerun, jobs, n=n, nproc=nproc, **kwargs)<EOL><DEDENT>elif method.lower() == "<STR_LIT>":<EOL><INDENT>retval = run_slurm(singlerun, jobs, n=n, nproc=nproc, **kwargs)<EOL><DEDENT>elif method.lower() == "<STR_LIT>":<EOL><INDENT>retval = run_multiprocessing(singlerun, jobs, n=n, nproc=nproc, **kwargs)<EOL><DEDENT>elif method.lower() == "<STR_LIT>":<EOL><INDENT>retval = run_azure(singlerun, jobs, n=n, nproc=nproc, **kwargs)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>')<EOL><DEDENT>if return_type is None or return_type in ("<STR_LIT:none>", ):<EOL><INDENT>return<EOL><DEDENT>assert len(retval) == len(jobs) == <NUM_LIT:1><EOL>if return_type in ("<STR_LIT>", '<STR_LIT:a>'):<EOL><INDENT>return retval[<NUM_LIT:0>]<EOL><DEDENT>import numpy<EOL>class DummyObserver:<EOL><INDENT>def __init__(self, inputs, species_list, errorbar=True):<EOL><INDENT>if len(inputs) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>t = numpy.array(inputs[<NUM_LIT:0>], numpy.float64).T[<NUM_LIT:0>]<EOL>mean = sum([numpy.array(data, numpy.float64).T[<NUM_LIT:1>: ] for data in inputs])<EOL>mean /= len(inputs)<EOL>self.__data = numpy.vstack([t, mean]).T<EOL>if errorbar:<EOL><INDENT>var = sum([(numpy.array(data, numpy.float64).T[<NUM_LIT:1>: ] - mean) ** <NUM_LIT:2><EOL>for data in inputs]) / len(inputs)<EOL>stdev = numpy.sqrt(var)<EOL>stder = stdev / numpy.sqrt(len(inputs))<EOL>self.__error = numpy.vstack([t, stder]).T<EOL><DEDENT>else:<EOL><INDENT>self.__error = None<EOL><DEDENT>self.__species_list = [ecell4_base.core.Species(serial) for serial in species_list]<EOL><DEDENT>def targets(self):<EOL><INDENT>return self.__species_list<EOL><DEDENT>def data(self):<EOL><INDENT>return self.__data<EOL><DEDENT>def t(self):<EOL><INDENT>return self.__data.T[<NUM_LIT:0>]<EOL><DEDENT>def error(self):<EOL><INDENT>return self.__error<EOL><DEDENT>def save(self, filename):<EOL><INDENT>with open(filename, '<STR_LIT:w>') as fout:<EOL><INDENT>writer = csv.writer(fout, delimiter='<STR_LIT:U+002C>', lineterminator='<STR_LIT:\n>')<EOL>writer.writerow(['<STR_LIT>'.format(sp.serial()) for sp in self.__species_list])<EOL>writer.writerows(self.data())<EOL><DEDENT><DEDENT><DEDENT>if return_type in ("<STR_LIT>", '<STR_LIT:m>'):<EOL><INDENT>if isinstance(opt_args, (list, tuple)):<EOL><INDENT>ecell4.util.viz.plot_number_observer_with_matplotlib(<EOL>DummyObserver(retval[<NUM_LIT:0>], species_list, errorbar), *opt_args, **opt_kwargs)<EOL><DEDENT>elif isinstance(opt_args, dict):<EOL><INDENT>ecell4.util.viz.plot_number_observer_with_matplotlib(<EOL>DummyObserver(retval[<NUM_LIT:0>], species_list, errorbar), **opt_args)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(<EOL>repr(opt_args)))<EOL><DEDENT><DEDENT>elif return_type in ("<STR_LIT>", '<STR_LIT:n>'):<EOL><INDENT>if isinstance(opt_args, (list, tuple)):<EOL><INDENT>ecell4.util.viz.plot_number_observer_with_nya(<EOL>DummyObserver(retval[<NUM_LIT:0>], species_list, errorbar), *opt_args, **opt_kwargs)<EOL><DEDENT>elif isinstance(opt_args, dict):<EOL><INDENT>ecell4.util.viz.plot_number_observer_with_nya(<EOL>DummyObserver(retval[<NUM_LIT:0>], species_list, errorbar), **opt_args)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(<EOL>repr(opt_args)))<EOL><DEDENT><DEDENT>elif return_type in ("<STR_LIT>", '<STR_LIT:o>'):<EOL><INDENT>return DummyObserver(retval[<NUM_LIT:0>], species_list, errorbar)<EOL><DEDENT>elif return_type in ("<STR_LIT>", '<STR_LIT:d>'):<EOL><INDENT>import pandas<EOL>return [<EOL>pandas.concat([<EOL>pandas.DataFrame(dict(Time=numpy.array(data).T[<NUM_LIT:0>],<EOL>Value=numpy.array(data).T[i + <NUM_LIT:1>],<EOL>Species=serial))<EOL>for i, serial in enumerate(species_list)])<EOL>for data in retval[<NUM_LIT:0>]]<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'.format(str(return_type))<EOL>+ '<STR_LIT>')<EOL><DEDENT>
Run simulations multiple times and return its ensemble.
Arguments are almost same with ``ecell4.util.simulation.run_simulation``.
`observers` and `progressbar` is not available here.

Parameters
----------
n : int, optional
    A number of runs. Default is 1.
nproc : int, optional
    A number of processors. Ignored when method='serial'.
    Default is None.
method : str, optional
    The way for running multiple jobs.
    Choose one from 'serial', 'multiprocessing', 'sge', 'slurm', 'azure'.
    Default is None, which works as 'serial'.
**kwargs : dict, optional
    Optional keyword arugments are passed through to `run_serial`,
    `run_sge`, or `run_multiprocessing`.
    See each function for more details.

Returns
-------
value : list, DummyObserver, or None
    Return a value suggested by ``return_type``.
    When ``return_type`` is 'array', return a time course data.
    When ``return_type`` is 'observer', return a DummyObserver.
    DummyObserver is a wrapper, which has the almost same interface
    with NumberObservers.
    Return nothing if else.

See Also
--------
ecell4.util.simulation.run_simulation
ecell4.extra.ensemble.run_serial
ecell4.extra.ensemble.run_sge
ecell4.extra.ensemble.run_slurm
ecell4.extra.ensemble.run_multiprocessing
ecell4.extra.ensemble.run_azure