Spaces:
Running
Running
Commit
·
e1ac1c9
1
Parent(s):
1efb6f4
Avoid activating package twice with pyjulia
Browse files- pysr/sr.py +17 -9
pysr/sr.py
CHANGED
|
@@ -27,6 +27,8 @@ global_state = dict(
|
|
| 27 |
selection=None,
|
| 28 |
)
|
| 29 |
|
|
|
|
|
|
|
| 30 |
sympy_mappings = {
|
| 31 |
"div": lambda x, y: x / y,
|
| 32 |
"mult": lambda x, y: x * y,
|
|
@@ -513,12 +515,14 @@ def pysr(
|
|
| 513 |
kwargs["def_datasets"] = _make_datasets_julia_str(**kwargs)
|
| 514 |
|
| 515 |
_create_julia_files(**kwargs)
|
|
|
|
| 516 |
if pyjulia:
|
| 517 |
# Read entire file as a single string:
|
| 518 |
with open(kwargs["runfile_filename"], "r") as f:
|
| 519 |
runfile_string = f.read()
|
| 520 |
print("Running main runfile in PyJulia!")
|
| 521 |
Main.eval(runfile_string)
|
|
|
|
| 522 |
else:
|
| 523 |
_final_pysr_process(**kwargs)
|
| 524 |
|
|
@@ -608,6 +612,7 @@ def _create_julia_files(
|
|
| 608 |
pyjulia,
|
| 609 |
**kwargs,
|
| 610 |
):
|
|
|
|
| 611 |
with open(hyperparam_filename, "w") as f:
|
| 612 |
print(def_hyperparams, file=f)
|
| 613 |
|
|
@@ -620,15 +625,18 @@ def _create_julia_files(
|
|
| 620 |
julia_project = pkg_directory
|
| 621 |
else:
|
| 622 |
julia_project = Path(julia_project)
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
print(f
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
|
|
|
|
|
|
|
|
|
| 632 |
print(f'include("{_escape_filename(hyperparam_filename)}")', file=f)
|
| 633 |
|
| 634 |
if not pyjulia:
|
|
|
|
| 27 |
selection=None,
|
| 28 |
)
|
| 29 |
|
| 30 |
+
already_ran_with_pyjulia = False
|
| 31 |
+
|
| 32 |
sympy_mappings = {
|
| 33 |
"div": lambda x, y: x / y,
|
| 34 |
"mult": lambda x, y: x * y,
|
|
|
|
| 515 |
kwargs["def_datasets"] = _make_datasets_julia_str(**kwargs)
|
| 516 |
|
| 517 |
_create_julia_files(**kwargs)
|
| 518 |
+
global already_ran_with_pyjulia
|
| 519 |
if pyjulia:
|
| 520 |
# Read entire file as a single string:
|
| 521 |
with open(kwargs["runfile_filename"], "r") as f:
|
| 522 |
runfile_string = f.read()
|
| 523 |
print("Running main runfile in PyJulia!")
|
| 524 |
Main.eval(runfile_string)
|
| 525 |
+
already_ran_with_pyjulia = True
|
| 526 |
else:
|
| 527 |
_final_pysr_process(**kwargs)
|
| 528 |
|
|
|
|
| 612 |
pyjulia,
|
| 613 |
**kwargs,
|
| 614 |
):
|
| 615 |
+
global already_ran_with_pyjulia
|
| 616 |
with open(hyperparam_filename, "w") as f:
|
| 617 |
print(def_hyperparams, file=f)
|
| 618 |
|
|
|
|
| 625 |
julia_project = pkg_directory
|
| 626 |
else:
|
| 627 |
julia_project = Path(julia_project)
|
| 628 |
+
|
| 629 |
+
if not already_ran_with_pyjulia:
|
| 630 |
+
print(f"import Pkg", file=f)
|
| 631 |
+
print(f'Pkg.activate("{_escape_filename(julia_project)}")', file=f)
|
| 632 |
+
if need_install:
|
| 633 |
+
print(f"Pkg.instantiate()", file=f)
|
| 634 |
+
print("Pkg.update()", file=f)
|
| 635 |
+
print("Pkg.precompile()", file=f)
|
| 636 |
+
elif update:
|
| 637 |
+
print(f"Pkg.update()", file=f)
|
| 638 |
+
print(f"using SymbolicRegression", file=f)
|
| 639 |
+
|
| 640 |
print(f'include("{_escape_filename(hyperparam_filename)}")', file=f)
|
| 641 |
|
| 642 |
if not pyjulia:
|