How to use the pyodesys.util.import_ function in pyodesys

To help you get started, we’ve selected a few pyodesys examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bjodah / pyodesys / pyodesys / native / gsl.py View on Github external
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function)

import copy
import os
from ..util import import_
from ._base import _NativeCodeBase, _NativeSysBase, _compile_kwargs

_config, get_include = import_('pygslodeiv2', '_config', 'get_include')


class NativeGSLCode(_NativeCodeBase):
    """ Looks for the environment variable: ``PYODESYS_BLAS`` (``gslcblas``) """
    wrapper_name = '_gsl_wrapper'

    def __init__(self, *args, **kwargs):
        self.compile_kwargs = copy.deepcopy(_compile_kwargs)
        self.compile_kwargs['include_dirs'].append(get_include())
        self.compile_kwargs['libraries'].extend(_config.env['GSL_LIBS'].split(','))
        self.compile_kwargs['libraries'].extend(os.environ.get('PYODESYS_BLAS', _config.env['BLAS']).split(','))
        super(NativeGSLCode, self).__init__(*args, **kwargs)


class NativeGSLSys(_NativeSysBase):
    _NativeCode = NativeGSLCode
github bjodah / pyodesys / pyodesys / native / cvode.py View on Github external
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function)

import copy
import os
import sys

from ..util import import_
from ._base import _NativeCodeBase, _NativeSysBase, _compile_kwargs

get_include, config, _libs = import_("pycvodes", "get_include", "config", "_libs")

if sys.version_info < (3, 6, 0):
    class ModuleNotFoundError(ImportError):
        pass


class NativeCvodeCode(_NativeCodeBase):
    wrapper_name = '_cvode_wrapper'

    try:
        _realtype = config['REAL_TYPE']
        _indextype = config['INDEX_TYPE']
    except ModuleNotFoundError:
        _realtype = '#error "realtype_failed-to-import-pycvodes-or-too-old-version"'
        _indextype = '#error "indextype_failed-to-import-pycvodes-or-too-old-version"'
github bjodah / pyodesys / pyodesys / results.py View on Github external
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function)

import numpy as np

from .plotting import plot_result, plot_phase_plane, info_vlines
from .util import import_

CubicSpline = import_('scipy.interpolate', 'CubicSpline')
interp1d = import_('scipy.interpolate', 'interp1d')


class Result(object):

    def __init__(self, xout, yout, params, info, odesys):
        self.xout = xout
        self.yout = yout
        self.params = params
        self.info = info
        self.odesys = odesys

    def copy(self):
        return Result(self.xout.copy(), self.yout.copy(), self.params.copy(),
                      self.info.copy(), self.odesys)
github bjodah / pyodesys / pyodesys / symbolic.py View on Github external
from __future__ import absolute_import, division, print_function

from collections import OrderedDict
from itertools import repeat, chain
import warnings

import numpy as np

from .util import import_
from .core import ODESys, RecoverableError
from .util import (
    transform_exprs_dep, transform_exprs_indep, _ensure_4args, _Callback
)

Backend = import_('sym', 'Backend')


def _get_indep_name(names):
    if 'x' not in names:
        indep_name = 'x'
    else:
        i = 0
        indep_name = 'indep0'
        while indep_name in names:
            i += 1
            indep_name = 'indep%d' % i
    return indep_name


def _get_ny_nparams_from_kw(ny, nparams, kwargs):
    if kwargs.get('dep_by_name', False):
github bjodah / pyodesys / pyodesys / results.py View on Github external
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function)

import numpy as np

from .plotting import plot_result, plot_phase_plane, info_vlines
from .util import import_

CubicSpline = import_('scipy.interpolate', 'CubicSpline')
interp1d = import_('scipy.interpolate', 'interp1d')


class Result(object):

    def __init__(self, xout, yout, params, info, odesys):
        self.xout = xout
        self.yout = yout
        self.params = params
        self.info = info
        self.odesys = odesys

    def copy(self):
        return Result(self.xout.copy(), self.yout.copy(), self.params.copy(),
                      self.info.copy(), self.odesys)

    def __len__(self):
github bjodah / pyodesys / pyodesys / integrators.py View on Github external
# -*- coding: utf-8 -*-
"""
This module is for demonstration purposes only and the integrators here
are not meant for production use. Consider them provisional, i.e., API here
may break without prior deprecation.
"""

import math
import warnings

import numpy as np
from .util import import_

lu_factor, lu_solve = import_('scipy.linalg', 'lu_factor', 'lu_solve')


class RK4_example_integrator:
    """
    This is an example of how to implement a custom integrator.
    It uses fixed step size and is usually not useful for real problems.
    """

    with_jacobian = False

    @staticmethod
    def integrate_adaptive(rhs, jac, y0, x0, xend, dx0, **kwargs):
        if kwargs:
            warnings.warn("Ignoring keyword-argumtents: %s" % ', '.join(kwargs.keys()))
        xspan = xend - x0
        n = int(math.ceil(xspan/dx0))
github bjodah / pyodesys / pyodesys / native / odeint.py View on Github external
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function)

import copy

from ..util import import_
from ._base import _NativeCodeBase, _NativeSysBase, _compile_kwargs

pyodeint = import_('pyodeint')


class NativeOdeintCode(_NativeCodeBase):
    wrapper_name = '_odeint_wrapper'

    def __init__(self, *args, **kwargs):
        self.compile_kwargs = copy.deepcopy(_compile_kwargs)
        self.compile_kwargs['include_dirs'].append(pyodeint.get_include())
        self.compile_kwargs['libraries'].extend(['m'])
        super(NativeOdeintCode, self).__init__(*args, **kwargs)


class NativeOdeintSys(_NativeSysBase):
    _NativeCode = NativeOdeintCode
    _native_name = 'odeint'