Beispiel #1
0
def _get_sources(CMakeLists: str, start_token: str, end_token: str):
    # Read in sources from CMakeLists.txt
    CMakeLists = str(_highs_dir() / CMakeLists)
    with open(CMakeLists, 'r', encoding='utf-8') as f:
        s = f.read()

        # Find block where sources are listed
        start_idx = s.find(start_token) + len(start_token)
        end_idx = s[start_idx:].find(end_token) + len(s[:start_idx])
        sources = s[start_idx:end_idx].split('\n')
        sources = [s.strip() for s in sources if s[0] != '#']

    sources = [str(_highs_dir() / "src" / s) for s in sources]
    return sources
Beispiel #2
0
def _get_version(CMakeLists: str, start_token: str, end_token: str = ')'):
    # Grab some more info about HiGHS from root CMakeLists
    CMakeLists = str(_highs_dir() / CMakeLists)
    with open(CMakeLists, 'r', encoding='utf-8') as f:
        s = f.read()
        start_idx = s.find(start_token) + len(start_token) + 1
        end_idx = s[start_idx:].find(end_token) + len(s[:start_idx])
    return s[start_idx:end_idx].strip()
Beispiel #3
0
def check_highs_submodule():
    from scipy._lib._highs_utils import _highs_dir

    if not os.path.exists(_highs_dir() / 'README.md'):
        raise RuntimeError("Missing the `highs` submodule! Run `git submodule "
                           "update --init` to fix this.")
Beispiel #4
0
def configuration(parent_package='', top_path=None):

    from numpy.distutils.misc_util import Configuration
    config = Configuration('_highs', parent_package, top_path)

    # HiGHS info
    _major_dot_minor = _get_version('CMakeLists.txt', 'project(HIGHS VERSION',
                                    'LANGUAGES CXX C')
    HIGHS_VERSION_MAJOR, HIGHS_VERSION_MINOR = _major_dot_minor.split('.')
    HIGHS_VERSION_PATCH = _get_version('CMakeLists.txt', 'HIGHS_VERSION_PATCH')
    GITHASH = 'n/a'
    HIGHS_DIR = str(_highs_dir().resolve())

    # Here are the pound defines that HConfig.h would usually provide;
    # We provide an empty HConfig.h file and do the defs and undefs
    # here:
    TODAY_DATE = datetime.today().strftime('%Y-%m-%d')
    DEFINE_MACROS = [
        ('CMAKE_BUILD_TYPE', '"Release"'),
        ('HiGHSRELEASE', None),
        ('IPX_ON', 'ON'),
        ('HIGHS_GITHASH', '"%s"' % GITHASH),
        ('HIGHS_COMPILATION_DATE', '"' + TODAY_DATE + '"'),
        ('HIGHS_VERSION_MAJOR', HIGHS_VERSION_MAJOR),
        ('HIGHS_VERSION_MINOR', HIGHS_VERSION_MINOR),
        ('HIGHS_VERSION_PATCH', HIGHS_VERSION_PATCH),
        ('HIGHS_DIR', '"' + HIGHS_DIR + '"'),
        # ('NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION', None),
    ]
    UNDEF_MACROS = [
        'OPENMP',  # unconditionally disable openmp
        'EXT_PRESOLVE',
        'SCIP_DEV',
        'HiGHSDEV',
        'OSI_FOUND',
    ]

    # Compile BASICLU as a static library to appease clang:
    # (won't allow -std=c++11/14 option for C sources)
    basiclu_sources = _get_sources('src/CMakeLists.txt',
                                   'set(basiclu_sources\n', ')')
    highs_root = _highs_dir()
    config.add_library(
        'basiclu',
        sources=basiclu_sources,
        include_dirs=[
            'src',
            str(highs_root / 'src'),
            str(highs_root / 'src/util'),
            str(highs_root / 'extern'),
            join(str(highs_root), 'src', 'ipm', 'basiclu', 'include'),
        ],
        language='c',
        macros=DEFINE_MACROS,
        _pre_build_hook=basiclu_pre_build_hook,
    )

    # highs_wrapper:
    ipx_sources = _get_sources('src/CMakeLists.txt', 'set(ipx_sources\n', ')')
    highs_sources = _get_sources('src/CMakeLists.txt', 'set(sources\n', ')')
    highs_sources += [str(highs_root / "src/ipm/IpxWrapper.cpp")]
    ext = config.add_extension(
        '_highs_wrapper',
        sources=([join('cython', 'src', '_highs_wrapper.cxx')] +
                 highs_sources + ipx_sources),
        include_dirs=[
            # highs_wrapper
            'src',
            str(highs_root / 'src'),
            str(highs_root / 'src/util'),
            str(highs_root / 'extern'),
            join(str(highs_root), 'cython', 'src'),
            join(str(highs_root), 'src', 'lp_data'),
            # highs
            join(str(highs_root), 'src', 'io'),
            join(str(highs_root), 'src', 'ipm', 'ipx', 'include'),
            # IPX
            join(str(highs_root), 'src', 'ipm', 'ipx', 'include'),
            join(str(highs_root), 'src', 'ipm', 'basiclu', 'include'),
        ],
        language='c++',
        libraries=['basiclu'],
        define_macros=DEFINE_MACROS,
        undef_macros=UNDEF_MACROS,
    )
    # Add c++11/14 support:
    ext._pre_build_hook = pre_build_hook

    # Export constants and enums from HiGHS:
    ext = config.add_extension(
        '_highs_constants',
        sources=[join('cython', 'src', '_highs_constants.cxx')],
        include_dirs=[
            'src',
            str(highs_root / 'src'),
            str(highs_root / 'src/util'),
            str(highs_root / 'extern'),
            join(str(highs_root), 'cython', 'src'),
            join(str(highs_root), 'src', 'io'),
            join(str(highs_root), 'src', 'lp_data'),
            join(str(highs_root), 'src', 'simplex'),
        ],
        language='c++',
    )
    ext._pre_build_hook = pre_build_hook

    config.add_data_files(os.path.join('cython', 'src', '*.pxd'))

    return config