1- import sys
2- from firedrake .configuration import setup_cache_dirs
1+ # The range of PETSc versions supported by Firedrake. Note that unlike in
2+ # firedrake-configure and pyproject.toml where we want to be strict about
3+ # the specific version, here we are more permissive. This is to catch the
4+ # case where users don't update their PETSc for a really long time or
5+ # accidentally install a too-new release that isn't yet supported.
6+ PETSC_SUPPORTED_VERSIONS = ">=3.23.0"
7+
8+
9+ def init_petsc ():
10+ import os
11+ import sys
12+ import petsctools
13+
14+ # We conditionally pass '-options_left no' as in some circumstances (e.g.
15+ # when running pytest) PETSc complains that command line options are not
16+ # PETSc options.
17+ if os .getenv ("FIREDRAKE_DISABLE_OPTIONS_LEFT" ) == "1" :
18+ petsctools .init (sys .argv + ["-options_left" , "no" ], version_spec = PETSC_SUPPORTED_VERSIONS )
19+ else :
20+ petsctools .init (sys .argv , version_spec = PETSC_SUPPORTED_VERSIONS )
21+
22+
23+ # Ensure petsc is initialised right away
24+ init_petsc ()
325
426# Set up the cache directories before importing PyOP2.
27+ from firedrake .configuration import setup_cache_dirs
28+
529setup_cache_dirs ()
630
7- # Ensure petsc is initialised by us before anything else gets in there.
8- # We conditionally pass '-options_left no' as in some circumstances (e.g.
9- # when running pytest) PETSc complains that command line options are not
10- # PETSc options.
11- import os
12- import petsc4py
13- if os .getenv ("FIREDRAKE_DISABLE_OPTIONS_LEFT" ) == "1" :
14- petsc4py .init (sys .argv + ["-options_left" , "no" ])
15- else :
16- petsc4py .init (sys .argv )
17- del os , petsc4py
1831
1932# Initialise PETSc events for both import and entire duration of program
33+ import petsctools
2034from firedrake import petsc
21- _is_logging = "log_view" in petsc .OptionsManager .commandline_options
35+ _is_logging = "log_view" in petsctools .OptionsManager .commandline_options
2236if _is_logging :
2337 _main_event = petsc .PETSc .Log .Event ("firedrake" )
2438 _main_event .begin ()
2943 import atexit
3044 atexit .register (lambda : _main_event .end ())
3145 del atexit
46+ del petsctools
3247del petsc
3348
3449from ufl import *
85100# from firedrake._deprecation import output
86101# sys.modules["firedrake.output"] = output
87102from firedrake .output import *
103+ import sys
88104sys .modules ["firedrake.plot" ] = plot
89105from firedrake .plot import *
90106
@@ -104,7 +120,7 @@ def set_blas_num_threads():
104120
105121 """
106122 from ctypes import cdll
107- from firedrake . petsc import get_blas_library
123+ from petsctools import get_blas_library
108124
109125 try :
110126 blas_lib_path = get_blas_library ()
0 commit comments