Qiskit Nature Logging Utilities.

Classes

QiskitNatureLogging()

Qiskit Nature Logging.

class QiskitNatureLogging[ソース]#

Qiskit Nature Logging.

A collection of utility methods encapsulating logging functions. The most basic use is:

import logging
from qiskit_nature import logging as nature_logging
nature_logging.set_levels_for_names(
    {"qiskit_nature": logging.DEBUG, "qiskit": logging.DEBUG})

It will print to 『stdout』 DEBUG formatted logs, for the domains included. One can access current logging levels for domains:

from qiskit_nature import logging as nature_logging
dict = nature_logging.get_levels_for_names(["qiskit_nature", "qiskit"])

The result dictionary key is the domain string and the value the logging level

Methods exist also to add, remove logging handler with formatter and one to write to a file:

import logging
from qiskit_nature import logging as nature_logging
nature_logging.log_to_file(
        {"qiskit_nature": logging.DEBUG, "qiskit": logging.DEBUG},
         path="file.log", mode="w"
    )

If mode is not given, 『append』 mode is used.

add_handler(name, handler, formatter=None)[ソース]#

Add handler and optional formatter to a module name.

パラメータ:
  • name (str) – module name

  • handler (Handler) – Logging Handler

  • formatter (Formatter | None) – Logging Formatter

get_levels_for_names(names)[ソース]#

Return logging levels for module names.

パラメータ:

names (List[str]) – list of module names (qiskit_nature.second_q.drivers, qiskit_algorithms etc)

戻り値:

Dictionary mapping names to effective level

戻り値の型:

Dict[str, int]

log_to_file(names, path, mode='a')[ソース]#

Logs modules to file.

パラメータ:
  • names (List[str]) – list of module names (qiskit_nature.second_q.drivers, qiskit_algorithms etc)

  • path (str) – file path

  • mode (str) – file open mode. If it is not specified, 『a』 is used to append

戻り値:

The logging File handler used

戻り値の型:

FileHandler

remove_all_handlers(names)[ソース]#

Remove all handlers from modules.

パラメータ:

names (List[str]) – list of module names (qiskit_nature.second_q.drivers, qiskit_algorithms etc)

remove_default_handler(names)[ソース]#

Remove default handler from modules.

パラメータ:

names (List[str]) – list of module names (qiskit_nature.second_q.drivers, qiskit_algorithms etc)

remove_handler(name, handler)[ソース]#

Remove handler from module.

パラメータ:
  • name (str) – module name

  • handler (Handler) – Logging Handler

set_levels_for_names(name_levels, add_default_handler=True)[ソース]#

Set logging levels for module names.

パラメータ:
  • name_levels (Dict[str, int]) – Dictionary of module names (qiskit_nature.second_q, qiskit_algorithms etc) to desired level

  • add_default_handler (bool) – add or not the default stream handler