diff --git a/qiskit/optimization/__init__.py b/qiskit/optimization/__init__.py index 5f58c844d..f94b1c5d3 100644 --- a/qiskit/optimization/__init__.py +++ b/qiskit/optimization/__init__.py @@ -2,7 +2,7 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2019. +# (C) Copyright IBM 2019, 2020. # # 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 @@ -28,3 +28,9 @@ ising """ + +from ._logging import (get_qiskit_optimization_logging, + set_qiskit_optimization_logging) + +__all__ = ['get_qiskit_optimization_logging', + 'set_qiskit_optimization_logging'] diff --git a/qiskit/optimization/_logging.py b/qiskit/optimization/_logging.py new file mode 100644 index 000000000..7ab2fdfa5 --- /dev/null +++ b/qiskit/optimization/_logging.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2020. +# +# 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. + +"""Utilities for Optimization logging.""" + +from typing import Optional +from qiskit.aqua import (QiskitLogDomains, + get_logging_level, + set_logging_level) + + +def get_qiskit_optimization_logging() -> int: + """ + Returns the current Qiskit Optimization logging level + + Returns: + int: logging level + """ + return get_logging_level(QiskitLogDomains.DOMAIN_OPTIMIZATION) + + +def set_qiskit_optimization_logging(level: int, filepath: Optional[str] = None) -> None: + """ + Updates the Qiskit Optimization logging with the appropriate logging level + + Args: + level: minimum severity of the messages that are displayed. + filepath: file to receive logging data + """ + set_logging_level(level, [QiskitLogDomains.DOMAIN_OPTIMIZATION], filepath)