Qiskit Nature Logging Utilities.

Classes

QiskitNatureLogging()

Qiskit Nature Logging.

class QiskitNatureLogging[source]#

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)[source]#

Add handler and optional formatter to a module name.

Parameters:
  • name (str) – module name

  • handler (Handler) – Logging Handler

  • formatter (Formatter | None) – Logging Formatter

get_levels_for_names(names)[source]#

Return logging levels for module names.

Parameters:

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

Returns:

Dictionary mapping names to effective level

Return type:

Dict[str, int]

log_to_file(names, path, mode='a')[source]#

Logs modules to file.

Parameters:
  • 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

Returns:

The logging File handler used

Return type:

FileHandler

remove_all_handlers(names)[source]#

Remove all handlers from modules.

Parameters:

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

remove_default_handler(names)[source]#

Remove default handler from modules.

Parameters:

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

remove_handler(name, handler)[source]#

Remove handler from module.

Parameters:
  • name (str) – module name

  • handler (Handler) – Logging Handler

set_levels_for_names(name_levels, add_default_handler=True)[source]#

Set logging levels for module names.

Parameters:
  • 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