@@ -96,42 +96,62 @@ def __repr__(self) -> str:
9696
9797
9898@deprecated (
99- target = None ,
100- remove_in = "0.10.0" ,
99+ target = True ,
100+ args_mapping = { "config" : "config" } ,
101101 deprecated_in = "0.9.0" ,
102+ remove_in = "0.10.0" ,
102103)
103- def init_parallel_backend (config : ParallelConfig ) -> ParallelBackend :
104+ def init_parallel_backend (
105+ config : ParallelConfig | None = None , backend_name : str | None = None
106+ ) -> ParallelBackend :
104107 """Initializes the parallel backend and returns an instance of it.
105108
106109 The following example creates a parallel backend instance with the default
107110 configuration, which is a local joblib backend.
108111
112+ If you don't pass any arguments, then by default it will instantiate
113+ the JoblibParallelBackend:
114+
109115 ??? Example
110- ``` python
111- config = ParallelConfig()
112- parallel_backend = init_parallel_backend(config)
116+ ```python
117+ parallel_backend = init_parallel_backend()
113118 ```
114119
115- To create a parallel backend instance with a different backend, e.g. ray,
116- you can pass the backend name as a string to the constructor of
117- [ParallelConfig][pydvl.utils.config.ParallelConfig].
120+ To create a parallel backend instance with for example `ray` as a backend,
121+ you can pass the backend name as a string:.
118122
119123 ??? Example
120124 ```python
121- config = ParallelConfig(backend="ray")
125+ parallel_backend = init_parallel_backend(backend_name="ray")
126+ ```
127+
128+
129+ The following is an example of the deprecated
130+ way for instantiating a parallel backend:
131+
132+ ??? Example
133+ ``` python
134+ config = ParallelConfig()
122135 parallel_backend = init_parallel_backend(config)
123136 ```
124137
125138 Args:
126- config: instance of [ParallelConfig][pydvl.utils.config.ParallelConfig]
139+ backend_name: Name of the backend to instantiate.
140+ config: (**DEPRECATED**) Object configuring parallel computation,
127141 with cluster address, number of cpus, etc.
128142
129143
130144 """
145+ if backend_name is None :
146+ if config is None :
147+ backend_name = "joblib"
148+ else :
149+ backend_name = config .backend
150+
131151 try :
132- parallel_backend_cls = ParallelBackend .BACKENDS [config . backend ]
152+ parallel_backend_cls = ParallelBackend .BACKENDS [backend_name ]
133153 except KeyError :
134- raise NotImplementedError (f"Unexpected parallel backend { config . backend } " )
154+ raise NotImplementedError (f"Unexpected parallel backend { backend_name } " )
135155 return parallel_backend_cls (config ) # type: ignore
136156
137157
0 commit comments