Add Jurse3 protocol with cache

This commit is contained in:
Florent Guiotte 2021-09-17 19:01:16 +02:00
parent 2081f87293
commit 4a3e1bf442
2 changed files with 36 additions and 0 deletions

View File

@ -10,3 +10,4 @@
#from .jurse import Jurse #from .jurse import Jurse
from .jurse2 import Jurse2 from .jurse2 import Jurse2
from .jurse3 import Jurse3

View File

@ -0,0 +1,35 @@
#!/usr/bin/env python
# file jurse3.py
# author Florent Guiotte <florent.guiotte@irisa.fr>
# version 0.0
# date 17 sept. 2021
import importlib
from joblib import Memory
from pathlib import Path
from . import Jurse2
CACHE = './cache'
class Jurse3(Jurse2):
"""Jurse2 protocl with cache
Same as Jurse2 but enable caching results to speed up
hyperparameters tunning.
"""
def __init__(self, expe):
super().__init__(expe)
self.memory = Memory(CACHE if Path(CACHE).exists else None, verbose=0)
def _compute_descriptors(self, data):
script = self._expe['descriptors_script']
desc = importlib.import_module(script['name'])
run = self.memory.cache(desc.run)
att = run(*data, **script['parameters'])
return att