From afcb72a8119e11be98e2147ad547811330284bba Mon Sep 17 00:00:00 2001 From: Robert Dyro Date: Fri, 5 May 2023 15:47:39 -0700 Subject: [PATCH 1/8] adding the trace-compile option to the julia initialization --- src/julia/options.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/julia/options.py b/src/julia/options.py index 00ba9801..0a2fd4da 100644 --- a/src/julia/options.py +++ b/src/julia/options.py @@ -174,6 +174,7 @@ class JuliaOptions(object): inline = Choices("inline", yes_no_etc()) check_bounds = Choices("check_bounds", yes_no_etc()) threads = IntEtc("threads", etc={"auto"}) + trace_compile = String("trace-compile") def __init__(self, **kwargs): unsupported = [] From da65c1dab2bc55e196f20a0ec939efe6707697dd Mon Sep 17 00:00:00 2001 From: Robert Dyro Date: Sat, 6 May 2023 09:38:11 -0700 Subject: [PATCH 2/8] fixing supported options documentation --- src/julia/options.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/julia/options.py b/src/julia/options.py index 0a2fd4da..82dc0494 100644 --- a/src/julia/options.py +++ b/src/julia/options.py @@ -145,6 +145,9 @@ def yes_no_etc(*etc): threads: {int, 'auto'} How many threads to use. + +trace_compile: str + Trace precompile statements during execution to the given file. """ @@ -174,7 +177,7 @@ class JuliaOptions(object): inline = Choices("inline", yes_no_etc()) check_bounds = Choices("check_bounds", yes_no_etc()) threads = IntEtc("threads", etc={"auto"}) - trace_compile = String("trace-compile") + trace_compile = String("trace_compile") def __init__(self, **kwargs): unsupported = [] From 7e015471e6ae143c797a729cb47da90acfed42e1 Mon Sep 17 00:00:00 2001 From: Robert Dyro Date: Sun, 7 May 2023 09:56:38 -0700 Subject: [PATCH 3/8] adding a test to the new trace_compile option --- src/julia/tests/test_trace_compile.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/julia/tests/test_trace_compile.py diff --git a/src/julia/tests/test_trace_compile.py b/src/julia/tests/test_trace_compile.py new file mode 100644 index 00000000..f2904d05 --- /dev/null +++ b/src/julia/tests/test_trace_compile.py @@ -0,0 +1,23 @@ +import os +from pathlib import Path +from subprocess import check_call + +import pytest + +from .test_compatible_exe import runcode + + +def test_trace_file_created(tmpdir): + currdir = os.getcwd() + os.chdir(str(tmpdir)) + runcode( + """ + from julia.api import Julia + jl = Julia(trace_compile="trace_compile.jl") + + from julia import Main + Main.sin(2.0) + """ + ) + os.chdir(currdir) + assert (Path(tmpdir) / "trace_compile.jl").exists() From fdd5fd25a2477495b2d2d26bc55a9b47c4e27810 Mon Sep 17 00:00:00 2001 From: Robert Dyro Date: Sun, 7 May 2023 11:19:50 -0700 Subject: [PATCH 4/8] hopefully fixing the trace compile file creating via full path specification --- src/julia/tests/test_trace_compile.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/julia/tests/test_trace_compile.py b/src/julia/tests/test_trace_compile.py index f2904d05..e23da084 100644 --- a/src/julia/tests/test_trace_compile.py +++ b/src/julia/tests/test_trace_compile.py @@ -8,16 +8,17 @@ def test_trace_file_created(tmpdir): - currdir = os.getcwd() - os.chdir(str(tmpdir)) + trace_compile_path = Path(tmpdir) / "trace_compile.jl" runcode( """ from julia.api import Julia - jl = Julia(trace_compile="trace_compile.jl") + jl = Julia(trace_compile="{}") from julia import Main Main.sin(2.0) - """ + """.format( + str(trace_compile_path) + ) ) - os.chdir(currdir) - assert (Path(tmpdir) / "trace_compile.jl").exists() + assert (trace_compile_path).exists() + assert len(trace_compile_path.read_text().strip()) > 0 From 4491f771ac95956656f03640b32e07a5eb72ffac Mon Sep 17 00:00:00 2001 From: Robert Dyro Date: Sun, 7 May 2023 12:23:32 -0700 Subject: [PATCH 5/8] trace compile path appears to be placed weirdly on windows, skipping this test --- src/julia/tests/test_trace_compile.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/julia/tests/test_trace_compile.py b/src/julia/tests/test_trace_compile.py index e23da084..b78eab5c 100644 --- a/src/julia/tests/test_trace_compile.py +++ b/src/julia/tests/test_trace_compile.py @@ -5,8 +5,10 @@ import pytest from .test_compatible_exe import runcode +from .utils import skip_in_windows +@skip_in_windows def test_trace_file_created(tmpdir): trace_compile_path = Path(tmpdir) / "trace_compile.jl" runcode( From f0981f2512c7ebbfdf8ff5759f9dedde02d66982 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 17 Jan 2024 15:08:55 -0800 Subject: [PATCH 6/8] adding expected precompile call test --- src/julia/tests/test_trace_compile.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/julia/tests/test_trace_compile.py b/src/julia/tests/test_trace_compile.py index b78eab5c..1ec16e8d 100644 --- a/src/julia/tests/test_trace_compile.py +++ b/src/julia/tests/test_trace_compile.py @@ -1,8 +1,5 @@ -import os +import re from pathlib import Path -from subprocess import check_call - -import pytest from .test_compatible_exe import runcode from .utils import skip_in_windows @@ -12,9 +9,9 @@ def test_trace_file_created(tmpdir): trace_compile_path = Path(tmpdir) / "trace_compile.jl" runcode( - """ + f""" from julia.api import Julia - jl = Julia(trace_compile="{}") + jl = Julia(trace_compile="{trace_compile_path}") from julia import Main Main.sin(2.0) @@ -24,3 +21,9 @@ def test_trace_file_created(tmpdir): ) assert (trace_compile_path).exists() assert len(trace_compile_path.read_text().strip()) > 0 + + # check whether the sin precompilation directive is included in the file + trace_compile_content = Path(trace_compile_path).read_text().strip() + lines = [x for x in trace_compile_content.split("\n") if len(x) > 0] + expected_precompile_line = r"precompile\(Tuple\{typeof\([A-Za-z]+\.sin\), Float64\}\)" + assert any([re.match(expected_precompile_line, x) is not None for x in lines]) \ No newline at end of file From 1c3d83ed0a690fe37fc4c4579f59e4a7c5f04240 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 17 Jan 2024 15:11:32 -0800 Subject: [PATCH 7/8] fixing formatting error --- src/julia/tests/test_trace_compile.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/julia/tests/test_trace_compile.py b/src/julia/tests/test_trace_compile.py index 1ec16e8d..49f93edf 100644 --- a/src/julia/tests/test_trace_compile.py +++ b/src/julia/tests/test_trace_compile.py @@ -25,5 +25,9 @@ def test_trace_file_created(tmpdir): # check whether the sin precompilation directive is included in the file trace_compile_content = Path(trace_compile_path).read_text().strip() lines = [x for x in trace_compile_content.split("\n") if len(x) > 0] - expected_precompile_line = r"precompile\(Tuple\{typeof\([A-Za-z]+\.sin\), Float64\}\)" - assert any([re.match(expected_precompile_line, x) is not None for x in lines]) \ No newline at end of file + expected_precompile_line = ( + r"precompile\(Tuple\{typeof\([A-Za-z]+\.sin\), Float64\}\)" + ) + assert any( + [re.match(expected_precompile_line, x) is not None for x in lines] + ) From 7bd924f72e0b5ac8c2db88cb03903d008e691c6a Mon Sep 17 00:00:00 2001 From: root Date: Wed, 17 Jan 2024 15:32:23 -0800 Subject: [PATCH 8/8] another fix to formatting --- src/julia/tests/test_trace_compile.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/julia/tests/test_trace_compile.py b/src/julia/tests/test_trace_compile.py index 49f93edf..0789330e 100644 --- a/src/julia/tests/test_trace_compile.py +++ b/src/julia/tests/test_trace_compile.py @@ -28,6 +28,4 @@ def test_trace_file_created(tmpdir): expected_precompile_line = ( r"precompile\(Tuple\{typeof\([A-Za-z]+\.sin\), Float64\}\)" ) - assert any( - [re.match(expected_precompile_line, x) is not None for x in lines] - ) + assert any([re.match(expected_precompile_line, x) is not None for x in lines])