@@ -1635,6 +1635,7 @@ def pathfinder(
16351635 refresh : Optional [int ] = None ,
16361636 time_fmt : str = "%Y%m%d%H%M%S" ,
16371637 timeout : Optional [float ] = None ,
1638+ num_threads : Optional [int ] = None ,
16381639 ) -> CmdStanPathfinder :
16391640 """
16401641 Run CmdStan's Pathfinder variational inference algorithm.
@@ -1737,6 +1738,10 @@ def pathfinder(
17371738 :param timeout: Duration at which Pathfinder times
17381739 out in seconds. Defaults to None.
17391740
1741+ :param num_threads: Number of threads to request for parallel execution.
1742+ A number other than ``1`` requires the model to have been compiled
1743+ with STAN_THREADS=True.
1744+
17401745 :return: A :class:`CmdStanPathfinder` object
17411746
17421747 References
@@ -1763,6 +1768,17 @@ def pathfinder(
17631768 "available for CmdStan versions 2.34 and later"
17641769 )
17651770
1771+ if num_threads is not None :
1772+ if (
1773+ num_threads != 1
1774+ and exe_info .get ('STAN_THREADS' , '' ).lower () != 'true'
1775+ ):
1776+ raise ValueError (
1777+ "Model must be compiled with 'STAN_THREADS=true' to use"
1778+ " 'num_threads' argument"
1779+ )
1780+ os .environ ['STAN_NUM_THREADS' ] = str (num_threads )
1781+
17661782 if num_paths == 1 :
17671783 if num_single_draws is None :
17681784 num_single_draws = draws
0 commit comments