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:
BaseModelPydantic model were hyphen replace underscore in field names.
- model_config = {'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:
HyphenUnderscoreAliasModelDescription of a reference author.
- Parameters:
- model_config = {'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:
HyphenUnderscoreAliasModelDescription of a publisher.
- Parameters:
name (str)
- model_config = {'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:
HyphenUnderscoreAliasModelDescription of an identifier.
- model_config = {'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,ABCAbstract base class for references.
- abstractmethod to_bibtex()
Convert a reference object to a BibTeX string representation.
- Return type:
- model_config = {'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:
BaseModelClass representing an arXiv identifier
- model_config = {}
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:
ReferenceABCDescription 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 = {'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:
ReferenceABCDescription of a Software
- Parameters:
- model_config = {'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:
objectFile manager: handles file download and integrity checks.
- Parameters:
config (Optional[Configuration])
- property options: FileManagerOptions
Get options of this file manager
- property registry: FileRegistry
Get the registry of this file manager
- build_local_cache()
Add to cache all local files from the registry.
- try_get_local_file(file_name, use_cache=False)
Try to get file locally and return its path
- get_file(file_name)
Get file locally and return its path
- try_get_file(file_name)
Get file and, if no strategy works, return None
- prefetch_files_by_list(file_names, skip_disabled=False)
Ensure all files in the given list are present (or raise errors for missing files)
- prefetch_files_by_tag(tag, skip_disabled=False)
Ensure all files matching a given tag are locally present (or raise errors)
- prefetch_all_files(discarded_tags=None, skip_disabled=False)
Ensure all files defined in registry are locally present (or raise errors)
- class few.files.FileRegistry(*, repositories, files)
Bases:
BaseModelRepresentation of the file registry.
- get_repository(name)
Get a repository by its name
- Parameters:
name (str)
- Return type:
Repository | None
- model_config = {}
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:
EnumEnumeration 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 TypeVar(‘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:
ABCBase 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:
ConfigConsumerClass implementing first-pass config consumer.
On first pass, we only detect if there are CLI arguments which disable config file or environment variables.
- 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:
ConfigConsumerClass 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:
objectHelper 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:
- disable_file_tags(*tags)
Disable files associated to given tags
- Parameters:
tags (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 “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