Releases: eladrich/pyrallis
Improved Decoding Mechanism :microscope:
Improved decoding mechanism to support inherited types, one can still use the existing register
functionality
pyrallis.decode.register(SomeClass, lambda x: SomeClass(x))
But can also register parent classes as well
pyrallis.decode.register(BaseClass, lambda t, x: t(x), include_subclasses=True)
Also revised the dispatch mechanism from singledispatch to a new dedicated wrapper (singledispatch tries to dispatch by class instead of value which isn't suited for decoding, but worked only thanks to the default behavior)
Added pyrallis.set_config_type to support json and toml
Added an option to change the configuration format used by pyrallis globally, or for a specific context.
This will affect pyrallis.parse
, pyrallis.dump
and pyrallis.load
to use the desired format
import pyrallis
pyrallis.set_config_type('json')
# or
with pyrallis.config_type('json'):
pyrallis.dump(cfg)
Changed enum parsing mechanism to be name based + bug fixes
Changed enum parsing to be based on enum field names instead of values.
As discussed in #8 , this allows one to support enums with non-string values such as
class LRMethod1(Enum):
onecycle: torch.optim.lr_scheduler = OneCycleLR
lambdalr: torch.optim.lr_scheduler = LambdaLR
Instead of allowing only enums of the form:
class LRMethod2(Enum):
onecycle: str = "onecycle"
constant: str = "constant"
The release also includes:
- Minor improvement in error mechanism
- Bug fixes when using the default collections such as Dict and List
Added omit_defaults in dump and improved --help
Implemented the suggestion from issue #1 to add an omit_defaults option to the dump function
pyrallis.dump(cfg, omit_defaults=True)
Also simplified the wrapper classes in the process and improved the --help
command to be more concise.
Modified API with pyrallis.parse and --config_path
Two breaking API changes
- Added the new
pyrallis.parse
call instead of thepyrallis.ArgumentParser.parse_args()
cfg = pyrallis.parse(config_class=TrainConfig)
- Modified the configuration argument name from --CONFIG to --config_path
$ python train_model.py --config_path=some_config.yaml --exp_name=my_first_exp
Required Arguments Bug Fix
Fixed a bug with nested dataclasses, where if the dataclass had a required argument the dataclass wrapper could not initialize the dataclass to define its default value and raised an exception.
@dataclass
class LogConfig:
exp_dir: str
@dataclass
class TrainConfig:
log: LogConfig= field(default_factory=LogConfig)
Type Hint Fixes
Fixed type hints in pyrallis.decode
and pyrallis.ArgumentParser
for better code analysis
Improved Error Mechanism
Improved error mechanism to be more informative, showing the field that caused the exception
$ python -m examples.demo --compute.workers=five
pyrallis.utils.ParsingError: Failed when parsing value='five' into field "<class '__main__.ComputeConfig'>.workers" of type <class 'int'>.
Underlying error: invalid literal for int() with base 10: 'five'
Bug fixes for different python versions
Fixed two bugs found when testing different python versions:
- Started using collections.abc as expected (python 3.10)
- Fixed a bug where assumed .name field does not exist (python 3.6)
Updates for PyPi Publication
Updated readme to use raw resources so that PyPi renders them correctly