def active(cls): # load the currently active auth env if cls.auth_env is None: from omegaml import _base_config cls.auth_env = load_class( getattr(_base_config, 'OMEGA_AUTH_ENV', 'omegaml.client.auth.AuthenticationEnv')) return cls.auth_env
def create_experiment(self, name, provider=None, *args, **kwargs): om = self.runtime.omega provider = provider or 'default' trackercls = load_class( om.defaults.OMEGA_TRACKING_PROVIDERS.get(provider)) tracker = trackercls(name, *args, store=om.datasets, **kwargs) meta = om.models.put(tracker, name, noversion=True) return tracker.experiment(name)
def get(self, name, version=-1, force_python=False, lazy=False, **kwargs): meta = self.data_store.metadata(name) data = meta.gridfile.read() # we get back a raw message, convert back to actual protobuf type # note the type must be loadable. will not work for arbitrary types pbtype = meta.kind_meta['protobuf_type'] message = load_class(pbtype)() message.ParseFromString(data) return message
def extend_instance(obj, cls, *args, **kwargs): """Apply mixins to a class instance after creation""" # source https://stackoverflow.com/a/31075641 from omegaml import load_class cls = load_class(cls) if cls not in obj.__class__.mro(): base_cls = obj.__class__ base_cls_name = 'Extended{}'.format( obj.__class__.__name__.split('.')[0]) obj.__class__ = type(base_cls_name, (cls, base_cls), {}) if hasattr(obj, '_init_mixin'): obj._init_mixin(*args, **kwargs)
def extend_instance(obj, cls, *args, conditional=None, **kwargs): """Apply mixins to a class instance after creation""" # source https://stackoverflow.com/a/31075641 from omegaml import load_class cls = load_class(cls) base_mro = obj.__class__.mro() should_apply = True if not callable(conditional) else conditional(cls, obj) if should_apply and cls not in base_mro: base_cls = obj.__class__ base_cls_name = base_mro[-2].__name__ obj.__class__ = type(base_cls_name, (cls, base_cls), {}) if hasattr(obj, '_init_mixin'): obj._init_mixin(*args, **kwargs)