Skip to content

Commit

Permalink
Changes to be compatible with jsonargparse v4 (#92)
Browse files Browse the repository at this point in the history
Summary:
### Motivation
I have noticed that this project has as dependency jsonargparse and makes use of the `ActionJsonSchema` class. Scheduled for tomorrow (Nov 16th 2021) jsonargparse v4.0.0 will be released and it includes a breaking change in the behavior of `ActionJsonSchema`. The change is that the values parsed with this action will no longer be a nested namespace but a nested dict instead.

### Changes proposed
This pull request includes a small change so that there is compatibility with the newer versions of jsonargparse.

Pull Request resolved: #92

Test Plan:
I tested by using `pplbench examples/example.json` with jsonargparse v4.0.0rc1 making sure that it worked just like with previous versions.

### Types of changes
- [x] Docs change / refactoring / dependency upgrade
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

### Checklist
- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have read the **[CONTRIBUTING](https://github.com/facebookresearch/pplbench/blob/main/CONTRIBUTING.md)** document.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
- [x] The title of my pull request is a short description of the requested changes.

Reviewed By: jpchen

Differential Revision: D32424133

Pulled By: horizon-blue

fbshipit-source-id: 20500fadbe41206169d57f8ed9f4925fcd5fba82
  • Loading branch information
mauvilsa authored and facebook-github-bot committed Jan 26, 2022
1 parent a8adddf commit b141bf8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 1 addition & 2 deletions pplbench/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import pydoc
import sys
import time
from argparse import Namespace
from types import SimpleNamespace
from typing import Any

Expand Down Expand Up @@ -40,7 +39,7 @@ class SimpleNamespaceEncoder(json.JSONEncoder):
"""define class for encoding config object"""

def default(self, object):
if isinstance(object, SimpleNamespace) or isinstance(object, Namespace):
if isinstance(object, SimpleNamespace):
return object.__dict__
elif isinstance(object, jsonargparse.Path):
return {}
Expand Down
5 changes: 4 additions & 1 deletion pplbench/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import sys
from types import SimpleNamespace
from typing import List, Optional
from unittest import mock

from jsonargparse import ActionJsonSchema, ArgumentParser
from jsonargparse import ActionJsonSchema, ArgumentParser, dict_to_namespace

from .lib import model_helper, ppl_helper, reports, utils

Expand Down Expand Up @@ -146,6 +147,8 @@ def read_config(args: Optional[List[str]]) -> SimpleNamespace:
parser = ArgumentParser()
parser.add_argument("config", action=ActionJsonSchema(schema=SCHEMA), help="%s")
config = parser.parse_args(args).config
with mock.patch("jsonargparse.namespace.Namespace", SimpleNamespace):
config = dict_to_namespace(config)

# default num_warmup to half of num_sample
if not hasattr(config, "num_warmup"):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
long_description_content_type="text/markdown",
python_requires=">=3.7",
install_requires=[
"jsonargparse>=2.32.2",
"jsonargparse>=4.0.0",
"jsonschema>=3.2.0",
"numpy>=1.18.5",
"scipy>=1.5.0",
Expand Down

0 comments on commit b141bf8

Please sign in to comment.