API Reference
Citations
few.utils.citations
:
This module is used to collect citations for all modules in the package. This
module is then imported to add citations to module classes using their citation
attribute.
- class few.utils.citations.HyphenUnderscoreAliasModel
Bases:
BaseModel
Pydantic model were hyphen replace underscore in field names.
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function HyphenUnderscoreAliasModel.Config.hyphen_replace>, 'extra': 'ignore', 'frozen': True, 'hyphen_replace': <function HyphenUnderscoreAliasModel.Config.hyphen_replace>}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class few.utils.citations.Author(*, family_names, given_names, orcid=None, affiliation=None, email=None)
Bases:
HyphenUnderscoreAliasModel
Description of a reference author.
- Parameters:
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function HyphenUnderscoreAliasModel.Config.hyphen_replace>, 'extra': 'ignore', 'frozen': True, 'hyphen_replace': <function HyphenUnderscoreAliasModel.Config.hyphen_replace>}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class few.utils.citations.Publisher(*, name)
Bases:
HyphenUnderscoreAliasModel
Description of a publisher.
- Parameters:
name (str)
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function HyphenUnderscoreAliasModel.Config.hyphen_replace>, 'extra': 'ignore', 'frozen': True, 'hyphen_replace': <function HyphenUnderscoreAliasModel.Config.hyphen_replace>}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class few.utils.citations.Identifier(*, type, value, description=None)
Bases:
HyphenUnderscoreAliasModel
Description of an identifier.
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function HyphenUnderscoreAliasModel.Config.hyphen_replace>, 'extra': 'ignore', 'frozen': True, 'hyphen_replace': <function HyphenUnderscoreAliasModel.Config.hyphen_replace>}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class few.utils.citations.ReferenceABC
Bases:
HyphenUnderscoreAliasModel
,ABC
Abstract base class for references.
- abstractmethod to_bibtex()
Convert a reference object to a BibTeX string representation.
- Return type:
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function HyphenUnderscoreAliasModel.Config.hyphen_replace>, 'extra': 'ignore', 'frozen': True, 'hyphen_replace': <function HyphenUnderscoreAliasModel.Config.hyphen_replace>}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class few.utils.citations.ArxivIdentifier(*, reference, primary_class=None)
Bases:
BaseModel
Class representing an arXiv identifier
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class few.utils.citations.ArticleReference(*, abbreviation, authors, title, journal, year, month=None, issue=None, publisher=None, pages=None, start=None, issn=None, doi=None, identifiers=None)
Bases:
ReferenceABC
Description of an article.
- Parameters:
- property arxiv_preprint: ArxivIdentifier | None
Detect an arXiv identifier if any.
an arXiv identifier is: - an identifier of type “other” - which starts with “arxiv:” (case insensitive) - whose second part is either:
The arXiv reference (e.g. “arxiv:1912.07609”)
The primary class followed by ‘/’ and the reference (e.g. “arxiv:gr-qc/1912.07609”)
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function HyphenUnderscoreAliasModel.Config.hyphen_replace>, 'extra': 'ignore', 'frozen': True, 'hyphen_replace': <function HyphenUnderscoreAliasModel.Config.hyphen_replace>}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class few.utils.citations.SoftwareReference(*, authors, title, license=None, url=None, repository=None, identifiers=None, year=None, month=None, version=None)
Bases:
ReferenceABC
Description of a Software
- Parameters:
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function HyphenUnderscoreAliasModel.Config.hyphen_replace>, 'extra': 'ignore', 'frozen': True, 'hyphen_replace': <function HyphenUnderscoreAliasModel.Config.hyphen_replace>}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- few.utils.citations.build_citation_registry()
Read the package CITATION.cff and build the corresponding registry.
- Return type:
CitationRegistry
File manager
- class few.files.FileManager(config=None)
Bases:
object
File manager: handles file download and integrity checks.
- Parameters:
config (Optional[Configuration])
- build_local_cache()
Add to cache all local files from the registry.
- get_file(file_name)
Get file locally and return its path
- open(file, mode='r', **kwargs)
Wrapper for open() built-in with automatic file download if needed.
- Parameters:
file (PathLike)
- property options: FileManagerOptions
Get options of this file manager
- prefetch_all_files()
Ensure all files defined in registry are locally present (or raise errors)
- prefetch_files_by_list(file_names)
Ensure all files in the given list are present (or raise errors for missing files)
- prefetch_files_by_tag(tag)
Ensure all files matching a given tag are locally present (or raise errors)
- Parameters:
tag (str)
- property registry: FileRegistry
Get the registry of this file manager
- class few.files.FileRegistry(*, repositories, files)
Bases:
BaseModel
Representation of the file registry.
- get_repository(name)
Get a repository by its name
- Parameters:
name (str)
- Return type:
Repository | None
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Configuration
Implementation of a centralized configuration management for FEW.
- class few.utils.config.ConfigSource(*values)
Bases:
Enum
Enumeration of config option sources.
- DEFAULT = 'default'
Config value comes from its default value
- CFGFILE = 'config_file'
Config value comes from the configuration file
- ENVVAR = 'environment_var'
Config value comes from environment variable
- CLIOPT = 'command_line'
Config value comes from command line parameter
- SETTER = 'setter'
Config value set by config setter after importing FEW
- class few.utils.config.ConfigEntry(label, description, type=~T, default=None, cfg_entry=None, env_var=None, cli_flags=None, cli_kwargs=None, convert=None, validate=<function ConfigEntry.<lambda>>, overwrite=<function ConfigEntry.<lambda>>)
Bases:
Generic
[T
]Description of a configuration entry.
- Parameters:
- type
Type of the value
alias of
T
- cli_kwargs: Dict[str, Any] | None = None
Supplementary arguments to argparse add_argument method for CLI options
- validate()
Method used to validate the provided option value
- overwrite(new)
Method used to update the value if given by multiple means
- class few.utils.config.ConfigItem(value, source)
Bases:
Generic
[T
]Actual configuration entry with its run-time properties (value, source, …)
- Parameters:
value (T)
source (ConfigSource)
- class few.utils.config.ConfigConsumer(config_file=None, env_vars=None, cli_args=None, set_args=None)
Bases:
ABC
Base class for actual configs.
This class handles building config values from default, file, environment and CLI options. It keeps a list of unused parameters for an other consumer.
- Parameters:
- abstractmethod classmethod config_entries()
Return the list of the class config entries
- Return type:
- few.utils.config.userstr_to_bool(user_str)
Convert a yes/no, on/off or true/false to bool.
- few.utils.config.userinput_to_pathlist(user_input)
Convert a user input to a list of paths
- few.utils.config.userinput_to_strlist(user_input)
Convert a user input to a list of paths
- class few.utils.config.InitialConfigConsumer(env_vars=None, cli_args=None)
Bases:
ConfigConsumer
Class implementing first-pass config consumer.
On first pass, we only detect if there are CLI arguments which disable config file or environment variables.
- get_extras()
Return extra file, env and cli entries for other consumer.
- static config_entries()
Return the list of the class config entries
- Return type:
- class few.utils.config.Configuration(config_file=None, env_vars=None, cli_args=None, set_args=None)
Bases:
ConfigConsumer
Class implementing FEW complete configuration for the library.
- Parameters:
- get_extras()
Return extra file, env and cli entries for other consumer.
- static config_entries()
Return the list of the class config entries
- Return type:
- build_cli_parent_parsers()
Build a Parser that can be used as parent parser from CLI-specific parsers
- Return type:
Global state
Definition of global states (logger, config, file manager, fast backend, …)
- class few.utils.globals.ConfigurationSetter(finalizer=None)
Bases:
object
Helper class to define configuration options.
- set_log_level(level)
Set a specific log level
- Parameters:
- Return type:
- set_file_registry_path(registry_path)
Set the file registry to use
- Parameters:
registry_path (PathLike)
- Return type:
- enable_file_download()
Authorize the file manager to download missing files
- Return type:
- disable_file_download()
Authorize the file manager to download missing files
- Return type:
- set_file_integrity_check(when)
Define when integrity checks should be performed (never, once, always)
- Parameters:
when (str)
- Return type:
- add_file_extra_paths(*paths)
Add supplementary research paths to file manager
- Parameters:
- Return type:
- finalize()
Finalize FEW initialization with specified parameters.
- few.utils.globals.get_file_manager()
Get FEW File Manager
- Return type:
- few.utils.globals.get_config()
Get FEW configuration
- Return type:
- few.utils.globals.get_config_setter(reset=False)
Get a configuration setter.
- Parameters:
reset (bool)
- Return type:
- few.utils.globals.get_backend(backend_name)
Get a backend by its name.
If the backend name is “cuda”, return a CUDA backend if any available. If the backend name is “gpu”, return a GPU backend if any available.
- Parameters:
backend_name (str)
- Return type:
Backend
- few.utils.globals.get_first_backend(backend_names)
Get the first available backend from a list of backend names
- few.utils.globals.has_backend(backend_name)
Test if a backend is available.
If the backend name is “cuda”, return true if any of “cuda11x” or “cuda12x” is available. If the backend name is “gpu”, return true if any GPU backend is available.
- few.utils.globals.initialize(*cli_args)
Initialize FEW configuration, logger and file manager with CLI arguments