ConfigValue

(class from pyomo.common.config)

class pyomo.common.config.ConfigValue(default=None, domain=None, description=None, doc=None, visibility=0)[source]

Bases: ConfigBase

Store and manipulate a single configuration value.

Parameters:
  • default (optional) – The default value that this ConfigValue will take if no value is provided.

  • domain (Callable, optional) – The domain can be any callable that accepts a candidate value and returns the value converted to the desired type, optionally performing any data validation. The result will be stored into the ConfigValue. Examples include type constructors like int or float. More complex domain examples include callable objects; for example, the In class that ensures that the value falls into an acceptable set or even a complete ConfigDict instance.

  • description (str, optional) – The short description of this value

  • doc (str, optional) – The long documentation string for this value

  • visibility (int, optional) – The visibility of this ConfigValue when generating templates and documentation. Visibility supports specification of “advanced” or “developer” options. ConfigValues with visibility=0 (the default) will always be printed / included. ConfigValues with higher visibility values will only be included when the generation method specifies a visibility greater than or equal to the visibility of this object.

__init__(default=None, domain=None, description=None, doc=None, visibility=0)

Methods

__init__([default, domain, description, ...])

declare_as_argument(*args, **kwds)

Map this Config item to an argparse argument.

display([content_filter, indent_spacing, ...])

Print the current Config value, in YAML format.

domain_name()

generate_documentation([block_start, ...])

Document the this Config object.

generate_yaml_template([indent_spacing, ...])

Document Config object, in YAML format.

import_argparse(parsed_args)

Import parsed arguments back into this Config object

initialize_argparse(parser)

Initialize an ArgumentParser with arguments from this Config object.

name([fully_qualified])

reset()

set_default_value(default)

set_domain(domain)

set_value(value)

unused_user_values()

user_values()

value([accessValue])

Member Documentation

declare_as_argument(*args, **kwds)

Map this Config item to an argparse argument.

Valid arguments include all valid arguments to argparse.ArgumentParser.add_argument() with the exception of default.

In addition, you may provide a group keyword argument that can be:

  • an argument group returned from ~argparse.ArgumentParser.add_argument_group

  • a subparser returned from ~argparse.ArgumentParser.add_subparsers

  • a string specifying the name of a subparser or argument group

  • a tuple of strings specifying a (subparser, group)

display(content_filter=None, indent_spacing=2, ostream=None, visibility=None)

Print the current Config value, in YAML format.

The current values stored in this Config object are output to ostream (or sys.stdout if ostream is None). If visibility is not None, then only items with visibility less than or equal to visibility will be output. Output can be further filtered by providing a content_filter.

generate_documentation(block_start=None, block_end=None, item_start=None, item_body=None, item_end=None, indent_spacing: int = 2, width: int = 78, visibility: int | None = None, format: ConfigFormatter | str = 'latex')

Document the this Config object.

Generate documentation for this config object in the specified format. While it can be called on any class derived from ConfigBase, it is typically used for documenting ConfigDict instances.

Note that unlike display() and generate_yaml_template(), generate_documentation() does not document the current value of any ConfigList containers. Instead, it generates the documentation for the ConfigList domain.

If the format argument is a string, this method is equivalent to:

ConfigFormatter.formats[format]().generate(
    self, indent_spacing, width, visibility
)

Otherwise, if format is a ConfigFormatter instance, then this is simply:

format.generate(self, indent_spacing, width, visibility)
generate_yaml_template(indent_spacing=2, width=78, visibility=0)

Document Config object, in YAML format.

Output a description of this Config object. While similar to display(), this routine has two key differences:

  • The description for each item is output as a comment.

  • The result is returned as a string instead of being sent directly to an output stream

If visibility is not None, then only items with visibility less than or equal to visibility will be output.

import_argparse(parsed_args)

Import parsed arguments back into this Config object

initialize_argparse(parser)

Initialize an ArgumentParser with arguments from this Config object.

Translate items from this Config object that have been marked with declare_as_argument() into argparse arguments.