Module Contents

flambe.compile.utils.all_subclasses(class_: Type[Any]) → Set[Type[Any]][source]

Return a set of all subclasses for a given class object

Recursively collects all subclasses of class_ down the object hierarchy into one set.

Parameters:class (Type[Any]) – Class to retrieve all subclasses for
Returns:All subclasses of class_
Return type:Set[Type[Any]]
flambe.compile.utils.make_component(class_: type, tag_namespace: Optional[str] = None, only_module: Optional[str] = None, parent_component_class: Optional[Type] = None, exclude: Optional[List[str]] = None) → None[source]

Make class and all its children a Component

For example a call to make_component(torch.optim.Adam, “torch”) will make the tag !torch.Adam accessible in any yaml configs. This does NOT monkey patch (aka swizzle) torch, but instead creates a dynamic subclass which will be used by the yaml constructor i.e. only classes loaded from the config will be affected, anything imported and used in code.

  • class (type) – To be registered with yaml as a component, along with all its children
  • tag_prefix (str) – Added to beginning of all the tags
  • only_module (str) – Module prefix used to limit the scope of what gets registered
  • parent_component_class (Type) – Parent class to use for creating a new component class; should be a subclass of :class:~flambe.compile.Component (defaults to Component)
  • exclude (List[str], optional) – A list of modules to ignore

Return type:


flambe.compile.utils._is_url(resource: str) → bool[source]

Whether a given resource is a remote URL.

Resolve by searching for a scheme.

Parameters:resource (str) – The given resource
Returns:If the resource is a remote URL.
Return type:bool
flambe.compile.utils.get_frozen_deps() → Iterable[str][source]

Get the frozen dependencies that are locally installed.

This should yield the same results as runnning ‘pip freeze’.

Returns:The frozen dependencies as strings.
Return type:Iterable[str]
flambe.compile.utils.write_deps(filename: str, deps: Optional[Iterable[str]] = None) → None[source]

Write dependencies on a filename, following Python’s convention for requiremnets.

  • filename (str) – The filename where the dependencies will be written.
  • deps (Optional[Iterable[str]]) – Optional dependencies to write. If not provided, this method will get the dependencies automatically. This parameter should be used for testing purposes only.