Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dynare-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dynare
dynare-python
Commits
0f0624b4
Commit
0f0624b4
authored
1 month ago
by
Daniel Sali
Browse files
Options
Downloads
Patches
Plain Diff
Lazy initialization of the Julia environment on dynare() call
parent
24fb1814
No related branches found
No related tags found
1 merge request
!9
RC 0.2.0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/dynare/__init__.py
+34
-4
34 additions, 4 deletions
src/dynare/__init__.py
with
34 additions
and
4 deletions
src/dynare/__init__.py
+
34
−
4
View file @
0f0624b4
import
logging
import
os
# Added import
import
os
import
functools
from
juliacall
import
Main
as
jl
from
.dynare
import
dynare
...
...
@@ -42,6 +43,16 @@ def setup_logging(
def
check_julia_and_dynare
():
"""
Check Julia installation and report on Dynare package status.
If you wish to use an existing conda environment with Julia and Dynare,
please set the environment variables appropriate for your setup as described at:
https://juliapy.github.io/PythonCall.jl/stable/pythoncall/#pythoncall-config
Julia configuration can be customized as described at:
https://juliapy.github.io/PythonCall.jl/stable/juliacall/#julia-config
"""
# Check Julia
julia_path
=
jl
.
seval
(
"
Sys.BINDIR
"
)
_
=
jl
.
seval
(
"
Base.active_project()
"
)
...
...
@@ -55,14 +66,33 @@ def check_julia_and_dynare():
_has_run
=
False
def
_run_once
():
def
ensure_initialized
():
"""
Ensure Julia and Dynare packages are initialized.
This can be called explicitly by users who want to control when initialization happens.
"""
global
_has_run
if
not
_has_run
:
check_julia_and_dynare
()
jl
.
seval
(
"
using Pkg
"
)
_has_run
=
True
logger
.
debug
(
"
Julia environment initialized
"
)
def
lazy_init
(
func
):
"""
Decorator to ensure initialization before calling a function.
"""
@functools.wraps
(
func
)
def
wrapper
(
*
args
,
**
kwargs
):
ensure_initialized
()
return
func
(
*
args
,
**
kwargs
)
return
wrapper
_run_once
()
# Make dynare function lazy-initialized
dynare
=
lazy_init
(
dynare
)
__all__
=
[
"
dynare
"
,
"
setup_logging
"
]
__all__
=
[
"
dynare
"
,
"
setup_logging
"
,
"
ensure_initialized
"
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment