# Path: elfi/utils.py
# def observed_name(name):
#     """Return `_name_observed`."""
#     return "_{}_observed".format(name)
# 
# def random_seed():
#     """Extract the seed from numpy RandomState.
# 
#     Alternative would be to use os.urandom(4) cast as int.
#     """
#     return np.random.RandomState().get_state()[1][1]
# 
# def scipy_from_str(name):
#     """Return the scipy.stats distribution corresponding to `name`."""
#     name = name.lower()
#     name = SCIPY_ALIASES.get(name, name)
#     return getattr(ss, name)


import inspect
import logging
import os
import pickle
import re
import uuid
import numpy as np
import scipy.spatial
import elfi.client
from functools import partial
from elfi.model.graphical_model import GraphicalModel
from elfi.model.utils import distance_as_discrepancy, rvs_from_distribution
from elfi.store import OutputPool
from elfi.utils import observed_name, random_seed, scipy_from_str
    def compile_operation(state):
        """Compile a callable operation that samples the associated distribution.

        Parameters
        ----------
        state : dict

        """
        size = state['size']
        distribution = state['distribution']
        if not (size is None or isinstance(size, tuple)):
            size = (size, )

        # Note: sending the scipy distribution object also pickles the global numpy random
        # state with it. If this needs to be avoided, the object needs to be constructed
        # on the worker.
        if isinstance(distribution, str):
            distribution = scipy_from_str(distribution)

        if not hasattr(distribution, 'rvs'):
            raise ValueError("Distribution {} " "must implement a rvs method".format(distribution))

        op = partial(rvs_from_distribution, distribution=distribution, size=size)
        return op

    @property
    def distribution(self):
        """Return the distribution object."""
        distribution = self.state['attr_dict']['distribution']
        if isinstance(distribution, str):

# Path: elfi/utils.py
# def observed_name(name):
#     """Return `_name_observed`."""
#     return "_{}_observed".format(name)
# 
# def random_seed():
#     """Extract the seed from numpy RandomState.
# 
#     Alternative would be to use os.urandom(4) cast as int.
#     """
#     return np.random.RandomState().get_state()[1][1]
# 
# def scipy_from_str(name):
#     """Return the scipy.stats distribution corresponding to `name`."""
#     name = name.lower()
#     name = SCIPY_ALIASES.get(name, name)
#     return getattr(ss, name)


# Path: elfi/model/elfi_model.py
import inspect
import logging
import os
import pickle
import re
import uuid
import numpy as np
import scipy.spatial
import elfi.client
from functools import partial
from elfi.model.graphical_model import GraphicalModel
from elfi.model.utils import distance_as_discrepancy, rvs_from_distribution
from elfi.store import OutputPool
from elfi.utils import observed_name, random_seed, scipy_from_str

    def compile_operation(state):
        """Compile a callable operation that samples the associated distribution.

        Parameters
        ----------
        state : dict

        """
        size = state['size']
        distribution = state['distribution']
        if not (size is None or isinstance(size, tuple)):
            size = (size, )

        # Note: sending the scipy distribution object also pickles the global numpy random
        # state with it. If this needs to be avoided, the object needs to be constructed
        # on the worker.
        if isinstance(distribution, str):
            distribution = scipy_from_str(distribution)

        if not hasattr(distribution, 'rvs'):
            raise ValueError("Distribution {} " "must implement a rvs method".format(distribution))

        op = partial(rvs_from_distribution, distribution=distribution, size=size)
        return op

    @property
    def distribution(self):
        """Return the distribution object."""
        distribution = self.state['attr_dict']['distribution']
        if isinstance(distribution, str):

            distribution = scipy_from_str(distribution)