@@ -39,21 +39,14 @@ managing the resulting inference for a single model and set of inputs.
3939Compile the Stan model
4040^^^^^^^^^^^^^^^^^^^^^^
4141
42- The: :class: `CmdStanModel ` class provides methods
43- to compile and run the Stan program.
44- A CmdStanModel object can be instantiated by specifying
45- either a Stan file or the executable file, or both.
46- If only the Stan file path is specified, the constructor will
47- check for the existence of a correspondingly named exe file in
48- the same directory. If found, it will use this as the exe file path.
49-
50- By default, when a CmdStanModel object is instantiated from a Stan file,
51- the constructor will compile the model as needed.
52- The constructor argument `compile ` controls this behavior.
53-
54- * ``compile=False ``: never compile the Stan file.
55- * ``compile="Force" ``: always compile the Stan file.
56- * ``compile=True ``: (default) compile the Stan file as needed, i.e., if no exe file exists or if the Stan file is newer than the exe file.
42+ The :class: `CmdStanModel ` class provides methods to compile and run the Stan
43+ program. A CmdStanModel object can be instantiated by specifying a Stan file,
44+ the executable file, or both. If only the Stan file path is specified, the
45+ constructor will check for the existence of a correspondingly named executable in
46+ the same directory. If found, it will use this as the exe file path.
47+
48+ When a CmdStanModel object is instantiated from a Stan file, the constructor
49+ will compile the model if the executable is non-existent or out-of-date.
5750
5851.. code-block :: python
5952
@@ -67,8 +60,8 @@ The constructor argument `compile` controls this behavior.
6760 my_model.exe_file
6861 my_model.code()
6962
70- The CmdStanModel class also provides the :meth: ` ~ CmdStanModel.compile ` method,
71- which can be called at any point to (re)compile the model as needed .
63+ The `` force_compile=True `` argument can be passed to the CmdStanModel
64+ constructor, which will force (re)compilation of the model.
7265
7366Model compilation is carried out via the GNU Make build tool.
7467The CmdStan ``makefile `` contains a set of general rules which
@@ -83,28 +76,30 @@ Model compilation is done in two steps:
8376* The C++ compiler compiles the generated code and links in
8477 the necessary supporting libraries.
8578
86- Therefore, both the constructor and the ``compile `` method
87- allow optional arguments ``stanc_options `` and ``cpp_options `` which
88- specify options for each compilation step.
89- Options are specified as a Python dictionary mapping
90- compiler option names to appropriate values.
79+ The constructor accepts arguments to specify both ``stanc `` and C++ compilation
80+ options, if desired. Passing `multithreading=True ` enables the **STAN_THREADS **
81+ C++ flag, which is needed to parallelize within-chain computations, such as
82+ with ``reduce_sum ``, or to parallelize the NUTS-HMC sampler across chains.
83+ Passing ``stanc_optimizations=True `` will enable ``O1 `` optimizations in the
84+ ``stanc `` compiler.
9185
92- In order parallelize within-chain computations using the
93- Stan language ``reduce_sum `` function, or to parallelize
94- running the NUTS-HMC sampler across chains,
95- the Stan model must be compiled with
96- C++ compiler flag **STAN_THREADS **.
97- While any value can be used,
98- we recommend the value ``True ``, e.g.:
86+ Outside of these common options, the constructor accepts the optional arguments
87+ ``stanc_options `` and ``cpp_options ``, which allow specifying arbitrary
88+ compilation options. Some more advanced Stan features, like MPI or OpenCL
89+ support, require using these. Note that if the lower-level compilation options
90+ conflict with an argument like ``multithreading=True ``, the option in
91+ ``stanc_options `` or ``cpp_options `` takes precedence.
9992
93+ An example model compilation that enables multithreading and
94+ basic optimization can be done like so:
10095
10196.. code-block :: python
10297
10398 import os
10499 from cmdstanpy import CmdStanModel
105100
106101 my_stanfile = os.path.join(' .' , ' my_model.stan' )
107- my_model = CmdStanModel(stan_file = my_stanfile, cpp_options = { ' STAN_THREADS ' : ' true ' } )
102+ my_model = CmdStanModel(stan_file = my_stanfile, multithreading = True , stanc_optimizations = True )
108103
109104
110105 Assemble input and initialization data
0 commit comments