def run_simulation(<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, observers=(), progressbar=<NUM_LIT:0>, rndseed=None,<EOL>factory=None, <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>else:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>".format(key, value))<EOL><DEDENT><DEDENT>import ecell4_base<EOL>if unit.HAS_PINT:<EOL><INDENT>if isinstance(t, unit._Quantity):<EOL><INDENT>if unit.STRICT and not unit.check_dimensionality(t, '<STR_LIT>'):<EOL><INDENT>raise ValueError("<STR_LIT>".format(t.dimensionality, t.u))<EOL><DEDENT>t = t.to_base_units().magnitude<EOL><DEDENT>if isinstance(volume, unit._Quantity):<EOL><INDENT>if unit.STRICT:<EOL><INDENT>if isinstance(volume.magnitude, ecell4_base.core.Real3) and not unit.check_dimensionality(volume, '<STR_LIT>'):<EOL><INDENT>raise ValueError("<STR_LIT>".format(<EOL>volume.dimensionality, volume.u))<EOL><DEDENT>elif not unit.check_dimensionality(volume, '<STR_LIT>'):<EOL><INDENT>raise ValueError("<STR_LIT>".format(<EOL>volume.dimensionality, volume.u))<EOL><DEDENT><DEDENT>volume = volume.to_base_units().magnitude<EOL><DEDENT>if not isinstance(solver, str) and isinstance(solver, collections.Iterable):<EOL><INDENT>solver = [<EOL>value.to_base_units().magnitude if isinstance(value, unit._Quantity) else value<EOL>for value in solver]<EOL><DEDENT><DEDENT>if factory is not None:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>")<EOL><DEDENT>elif isinstance(solver, str):<EOL><INDENT>f = get_factory(solver)<EOL><DEDENT>elif isinstance(solver, collections.Iterable):<EOL><INDENT>f = get_factory(*solver)<EOL><DEDENT>else:<EOL><INDENT>f = solver<EOL><DEDENT>if rndseed is not None:<EOL><INDENT>f = f.rng(ecell4_base.core.GSLRandomNumberGenerator(rndseed))<EOL><DEDENT>if model is None:<EOL><INDENT>model = get_model(is_netfree, without_reset)<EOL><DEDENT>w = f.world(volume)<EOL>edge_lengths = w.edge_lengths()<EOL>if unit.HAS_PINT:<EOL><INDENT>y0 = y0.copy()<EOL>for key, value in y0.items():<EOL><INDENT>if isinstance(value, unit._Quantity):<EOL><INDENT>if not unit.STRICT:<EOL><INDENT>y0[key] = value.to_base_units().magnitude<EOL><DEDENT>elif unit.check_dimensionality(value, '<STR_LIT>'):<EOL><INDENT>y0[key] = value.to_base_units().magnitude<EOL><DEDENT>elif unit.check_dimensionality(value, '<STR_LIT>'):<EOL><INDENT>volume = w.volume() if not isinstance(w, ecell4_base.spatiocyte.SpatiocyteWorld) else w.actual_volume()<EOL>y0[key] = value.to_base_units().magnitude * volume<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>".format(<EOL>key, value.dimensionality, value.u))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if not isinstance(w, ecell4_base.ode.ODEWorld):<EOL><INDENT>w.bind_to(model)<EOL><DEDENT>for (name, shape) in (structures.items() if isinstance(structures, dict) else structures):<EOL><INDENT>if isinstance(shape, str):<EOL><INDENT>w.add_structure(ecell4_base.core.Species(name), get_shape(shape))<EOL><DEDENT>elif isinstance(shape, collections.Iterable):<EOL><INDENT>w.add_structure(ecell4_base.core.Species(name), get_shape(*shape))<EOL><DEDENT>else:<EOL><INDENT>w.add_structure(ecell4_base.core.Species(name), shape)<EOL><DEDENT><DEDENT>if isinstance(w, ecell4_base.ode.ODEWorld):<EOL><INDENT>for serial, n in y0.items():<EOL><INDENT>w.set_value(ecell4_base.core.Species(serial), n)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for serial, n in y0.items():<EOL><INDENT>w.add_molecules(ecell4_base.core.Species(serial), n)<EOL><DEDENT><DEDENT>if not isinstance(t, collections.Iterable):<EOL><INDENT>t = [float(t) * i / <NUM_LIT:100> for i in range(<NUM_LIT>)]<EOL><DEDENT>if species_list is not None:<EOL><INDENT>obs = ecell4_base.core.TimingNumberObserver(t, species_list)<EOL><DEDENT>else:<EOL><INDENT>obs = ecell4_base.core.TimingNumberObserver(t)<EOL><DEDENT>sim = f.simulator(w, model)<EOL>if not isinstance(observers, collections.Iterable):<EOL><INDENT>observers = (observers, )<EOL><DEDENT>if return_type not in ('<STR_LIT>', '<STR_LIT:none>', None):<EOL><INDENT>observers = (obs, ) + tuple(observers)<EOL><DEDENT>if progressbar > <NUM_LIT:0>:<EOL><INDENT>from .progressbar import progressbar as pb<EOL>pb(sim, timeout=progressbar, flush=True).run(t[-<NUM_LIT:1>], observers)<EOL><DEDENT>else:<EOL><INDENT>sim.run(t[-<NUM_LIT:1>], observers)<EOL><DEDENT>if return_type in ('<STR_LIT>', '<STR_LIT:m>'):<EOL><INDENT>if isinstance(opt_args, (list, tuple)):<EOL><INDENT>viz.plot_number_observer(obs, *opt_args, **opt_kwargs)<EOL><DEDENT>elif isinstance(opt_args, dict):<EOL><INDENT>viz.plot_number_observer(obs, **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>viz.plot_number_observer_with_nya(obs, *opt_args, **opt_kwargs)<EOL><DEDENT>elif isinstance(opt_args, dict):<EOL><INDENT>viz.plot_number_observer_with_nya(obs, **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 obs<EOL><DEDENT>elif return_type in ('<STR_LIT>', '<STR_LIT:a>'):<EOL><INDENT>return obs.data()<EOL><DEDENT>elif return_type in ('<STR_LIT>', '<STR_LIT:d>'):<EOL><INDENT>import pandas<EOL>import numpy<EOL>data = numpy.array(obs.data()).T<EOL>return pandas.concat([<EOL>pandas.DataFrame(dict(Time=data[<NUM_LIT:0>], Value=data[i + <NUM_LIT:1>],<EOL>Species=sp.serial(), **opt_kwargs))<EOL>for i, sp in enumerate(obs.targets())])<EOL><DEDENT>elif return_type in ('<STR_LIT>', '<STR_LIT:w>'):<EOL><INDENT>return sim.world()<EOL><DEDENT>elif return_type is None or return_type in ('<STR_LIT:none>', ):<EOL><INDENT>return<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'.format(str(return_type))<EOL>+ '<STR_LIT>')<EOL><DEDENT>
Run a simulation with the given model and plot the result on IPython
    notebook with matplotlib.

    Parameters
    ----------
    t : array or Real
        A sequence of time points for which to solve for 'm'.
    y0 : dict
        Initial condition.
    volume : Real or Real3, optional
        A size of the simulation volume.
        Keyword 'v' is a shortcut for specifying 'volume'.
    model : Model, optional
        Keyword 'm' is a shortcut for specifying 'model'.
    solver : str, tuple or Factory, optional
        Solver type. Choose one from 'ode', 'gillespie', 'spatiocyte', 'meso',
        'bd' and 'egfrd'. Default is 'ode'.
        When tuple is given, the first value must be str as explained above.
        All the rest is used as arguments for the corresponding factory class.
        Keyword 's' is a shortcut for specifying 'solver'.
    species_list : list of str, optional
        A list of names of Species observed. If None, log all.
        Default is None.
    return_type : str, optional
        Choose a type of return value from 'array', 'observer',
        'matplotlib', 'nyaplot', 'world', 'dataframe', 'none' or None.
        If None or 'none', return and plot nothing. Default is 'matplotlib'.
        'dataframe' requires numpy and pandas libraries.
        Keyword 'r' is a shortcut for specifying 'return_type'.
    opt_args: list, tuple or dict, optional
        Arguments for plotting. If return_type suggests no plotting, just ignored.
    opt_kwargs: dict, optional
        Arguments for plotting. If return_type suggests no plotting or
        opt_args is a list or tuple, just ignored.
        i.e.) viz.plot_number_observer(obs, *opt_args, **opt_kwargs)
    is_netfree: bool, optional
        Whether the model is netfree or not. When a model is given as an
        argument, just ignored. Default is False.
    structures : list or dict, optional
        A dictionary which gives pairs of a name and shape of structures.
        Not fully supported yet.
    observers : Observer or list, optional
        A list of extra observer references.
    progressbar : float, optional
        A timeout for a progress bar in seconds.
        When the value is not more than 0, show nothing.
        Default is 0.
    rndseed : int, optional
        A random seed for a simulation.
        This argument will be ignored when 'solver' is given NOT as a string.

    Returns
    -------
    value : list, TimingNumberObserver, World 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 an observer.
        When ``return_type`` is 'world', return the last state of ``World``.
        Return nothing if else.