Skip to content

Commit 9de4d94

Browse files
gnuilleGuillem Ramirez Miranda
andauthored
Add trace-compile configuration and internal config helpers (#743)
* Add trace-compile configuration and internal config helpers * tweak implementation of new options and document --------- Co-authored-by: Guillem Ramirez Miranda <guillem@avatarcognition.com> Co-authored-by: Christopher Rowley <github.com/cjdoris>
1 parent 175f807 commit 9de4d94

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Added `juliacall.TypeValue.__numpy_dtype__` attribute to allow converting Julia types
55
to the corresponding NumPy dtype, like `numpy.dtype(jl.Int)`.
66
* JuliaCall now launches Julia with 1 thread by default.
7+
* Added options `trace_compile` and `trace_compile_timing` to JuliaCall.
78
* Bug fixes.
89

910
## 0.9.31 (2025-12-17)

docs/src/juliacall.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ be configured in two ways:
142142
| `-X juliacall-heap-size-hint=<N>` | `PYTHON_JULIACALL_HEAP_SIZE_HINT=<N>` | Hint for initial heap size in bytes. |
143143
| `-X juliacall-exe=<file>` | `PYTHON_JULIACALL_EXE=<file>` | Path to Julia binary to use (overrides JuliaPkg). |
144144
| `-X juliacall-project=<dir>` | `PYTHON_JULIACALL_PROJECT=<dir>` | Path to the Julia project to use (overrides JuliaPkg). |
145+
| `-X juliacall-trace-compile=<stderr\|name>` | `PYTHON_JULIACALL_TRACE_COMPILE=<stderr\|name>` | Print precompile statements. |
146+
| `-X juliacall-trace-compile-timing` | `PYTHON_JULIACALL_TRACE_COMPILE_TIMING=<yes\|no>` | Include timings with precompile statements. |
145147

146148
## [Multi-threading](@id py-multi-threading)
147149

pysrc/juliacall/__init__.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def init():
6464
"For updates, see https://github.com/pytorch/pytorch/issues/78829."
6565
)
6666

67-
def option(name, default=None, xkey=None, envkey=None):
67+
def option(name, default=None, xkey=None, envkey=None, allowflag=False):
6868
"""Get an option.
6969
7070
Options can be set as command line arguments '-X juliacall-{name}={value}' or as
@@ -73,13 +73,28 @@ def option(name, default=None, xkey=None, envkey=None):
7373
k = xkey or 'juliacall-'+name.lower().replace('_', '-')
7474
v = sys._xoptions.get(k)
7575
if v is not None:
76+
if v is True:
77+
if not allowflag:
78+
raise ValueError(f'-X{k}: expecting an argument')
79+
return True, f'-X{k}'
7680
return v, f'-X{k}={v}'
7781
k = envkey or 'PYTHON_JULIACALL_'+name.upper()
7882
v = os.getenv(k)
7983
if v is not None:
8084
return v, f'{k}={v}'
8185
return default, f'<default>={default}'
8286

87+
def flag(name, default=None, **kw):
88+
v, s = option(name, allowflag=True, **kw)
89+
if v is None:
90+
return default, s
91+
elif v is True or v == 'yes':
92+
return True, s
93+
elif v == 'no':
94+
return False, s
95+
else:
96+
raise ValueError(f'{s}: expecting yes or no')
97+
8398
def choice(name, choices, default=None, **kw):
8499
v, s = option(name, **kw)
85100
if v is None:
@@ -128,7 +143,11 @@ def args_from_config(config):
128143
val = 'no'
129144
else:
130145
continue
131-
argv.append('--' + opt[4:].replace('_', '-') + '=' + val)
146+
arg = '--' + opt[4:].replace('_', '-')
147+
if val is True:
148+
argv.append(arg)
149+
elif val is not None:
150+
argv.append(f"{arg}={val}")
132151
argv = [s.encode("utf-8") for s in argv]
133152

134153
argc = len(argv)
@@ -145,6 +164,8 @@ def args_from_config(config):
145164
CONFIG['opt_home'] = bindir = path_option('home', check_exists=True, envkey='PYTHON_JULIACALL_BINDIR')[0]
146165
CONFIG['opt_check_bounds'] = choice('check_bounds', ['yes', 'no', 'auto'])[0]
147166
CONFIG['opt_compile'] = choice('compile', ['yes', 'no', 'all', 'min'])[0]
167+
CONFIG["opt_trace_compile"] = option('trace_compile')[0]
168+
CONFIG["opt_trace_compile_timing"] = flag('trace_compile_timing')[0]
148169
CONFIG['opt_compiled_modules'] = choice('compiled_modules', ['yes', 'no'])[0]
149170
CONFIG['opt_depwarn'] = choice('depwarn', ['yes', 'no', 'error'])[0]
150171
CONFIG['opt_inline'] = choice('inline', ['yes', 'no'])[0]

0 commit comments

Comments
 (0)