-
Notifications
You must be signed in to change notification settings - Fork 212
Allow users to set a logging level when running a program #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # This code is part of Qiskit. | ||
| # | ||
| # (C) Copyright IBM 2022. | ||
| # | ||
| # This code is licensed under the Apache License, Version 2.0. You may | ||
| # obtain a copy of this license in the LICENSE.txt file in the root directory | ||
| # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
| # | ||
| # Any modifications or derivative works of this code must retain this | ||
| # copyright notice, and modified files need to carry a notice indicating | ||
| # that they have been altered from the originals. | ||
|
|
||
| """Runtime options that control the execution environment.""" | ||
|
|
||
| import re | ||
| import logging | ||
| from dataclasses import dataclass | ||
| from typing import Optional | ||
|
|
||
| from .exceptions import IBMInputValueError | ||
|
|
||
|
|
||
| @dataclass | ||
| class RuntimeOptions: | ||
| """Class for representing runtime execution options. | ||
|
|
||
| Args: | ||
| backend_name: target backend to run on. This is required for legacy runtime. | ||
| image: the runtime image used to execute the program, specified in | ||
| the form of ``image_name:tag``. Not all accounts are | ||
| authorized to select a different image. | ||
| log_level: logging level to set in the execution environment. The default | ||
| level is ``WARNING``. | ||
| """ | ||
|
|
||
| backend_name: Optional[str] = None | ||
| image: Optional[str] = None | ||
| log_level: Optional[str] = None | ||
|
|
||
| def validate(self, auth: str) -> None: | ||
| """Validate options. | ||
|
|
||
| Args: | ||
| auth: authentication type. | ||
|
|
||
| Raises: | ||
| IBMInputValueError: If one or more option is invalid. | ||
| """ | ||
| if self.image and not re.match( | ||
| "[a-zA-Z0-9]+([/.\\-_][a-zA-Z0-9]+)*:[a-zA-Z0-9]+([.\\-_][a-zA-Z0-9]+)*$", | ||
| self.image, | ||
| ): | ||
| raise IBMInputValueError('"image" needs to be in form of image_name:tag') | ||
|
|
||
| if auth == "legacy" and not self.backend_name: | ||
| raise IBMInputValueError( | ||
| '"backend_name" is required field in "options" for legacy runtime.' | ||
| ) | ||
|
|
||
| if self.log_level and not isinstance( | ||
| logging.getLevelName(self.log_level.upper()), int | ||
| ): | ||
| raise IBMInputValueError( | ||
| f"{self.log_level} is not a valid log level. The valid log levels are: `DEBUG`, " | ||
| f"`INFO`, `WARNING`, `ERROR`, and `CRITICAL`." | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.