File size: 1,751 Bytes
ce60798
4037c2d
6baa534
976f8d8
4037c2d
 
 
 
 
 
 
 
 
68ea1be
 
6baa534
68ea1be
6baa534
e530637
 
4037c2d
 
 
3856951
d3026af
4300bea
d42f10b
d3026af
6baa534
bcaffe2
 
68ea1be
6baa534
 
 
80fecb9
6baa534
 
 
4bc0a76
 
68ea1be
 
 
 
4ee8cdb
68ea1be
 
4ee8cdb
 
 
 
68ea1be
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Functions for initializing the Julia environment and installing deps."""
import os
import warnings

# Required to avoid segfaults (https://juliapy.github.io/PythonCall.jl/dev/faq/)
if os.environ["PYTHON_JULIACALL_HANDLE_SIGNALS"] not in {"yes", ""}:
    warnings.warn(
        "PYTHON_JULIACALL_HANDLE_SIGNALS environment variable is set to something other than 'yes' or ''. "
        + "You will experience segfaults if running with multithreading."
    )

os.environ["PYTHON_JULIACALL_HANDLE_SIGNALS"] = "yes"

import juliacall
import juliapkg

jl = juliacall.newmodule("PySR")

from juliacall import convert as jl_convert

jl.seval("using PythonCall: PythonCall")
PythonCall = jl.PythonCall

juliainfo = None
julia_initialized = False
julia_kwargs_at_initialization = None
julia_activated_env = None


def _get_io_arg(quiet):
    io = "devnull" if quiet else "stderr"
    return f"io={io}"


def _escape_filename(filename):
    """Turn a path into a string with correctly escaped backslashes."""
    str_repr = str(filename)
    str_repr = str_repr.replace("\\", "\\\\")
    return str_repr


def _backend_version_assertion():
    backend_version = jl.seval("string(SymbolicRegression.PACKAGE_VERSION)")
    expected_backend_version = juliapkg.status(target="SymbolicRegression").version
    if backend_version != expected_backend_version:  # pragma: no cover
        warnings.warn(
            f"PySR backend (SymbolicRegression.jl) version {backend_version} "
            f"does not match expected version {expected_backend_version}. "
            "Things may break. "
        )


def _load_cluster_manager(cluster_manager):
    jl.seval(f"using ClusterManagers: addprocs_{cluster_manager}")
    return jl.seval(f"addprocs_{cluster_manager}")