Skip to content

Commit

Permalink
Merge branch 'master' into qutip-qtrl-0.1.X
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgestar committed Feb 12, 2024
2 parents a0684f2 + 6d9826d commit 6df1df6
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 34 deletions.
12 changes: 12 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
Changelog
*********

Version 0.1.1 (February 12, 2024)
+++++++++++++++++++++++++++++++++

This is a patch release of qutip-qtrl that provides updates to support the QuTiP 5.0.0a2 release.

Bug Fixes
---------

- Fixed progress bar initialization and usage (#13, #15, Patrick Hopf).
- Replaced the logging utilities that were removed from QuTiP v5 with a vendored copy in this package (#9, Èric Giguere).
- Applied black to setup.py and doc/conf.py scripts (#8, Simon Cross).


Version 0.1.0 (March 12, 2023)
++++++++++++++++++++++++++++++
Expand Down
4 changes: 2 additions & 2 deletions src/qutip_qtrl/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import qutip_qtrl.io as qtrlio

# QuTiP logging
import qutip.logging_utils
import qutip_qtrl.logging_utils

logger = qutip.logging_utils.get_logger("qutip.control.dump")
logger = qutip_qtrl.logging_utils.get_logger("qutip.control.dump")

DUMP_DIR = "~/.qtrl_dump"

Expand Down
4 changes: 2 additions & 2 deletions src/qutip_qtrl/dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import qutip_qtrl.dump as qtrldump

# QuTiP logging
import qutip.logging_utils as logging
import qutip_qtrl.logging_utils as logging

logger = logging.get_logger()

Expand Down Expand Up @@ -135,7 +135,7 @@ class Dynamics(object):
----------
log_level : integer
level of messaging output from the logger.
Options are attributes of qutip.logging_utils,
Options are attributes of qutip_qtrl.logging_utils,
in decreasing levels of messaging, are:
DEBUG_INTENSE, DEBUG_VERBOSE, DEBUG, INFO, WARN, ERROR, CRITICAL
Anything WARN or above is effectively 'quiet' execution,
Expand Down
4 changes: 2 additions & 2 deletions src/qutip_qtrl/fidcomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import qutip_qtrl.errors as errors

# QuTiP logging
import qutip.logging_utils as logging
import qutip_qtrl.logging_utils as logging

logger = logging.get_logger()

Expand Down Expand Up @@ -80,7 +80,7 @@ class FidelityComputer(object):
----------
log_level : integer
level of messaging output from the logger.
Options are attributes of qutip.logging_utils,
Options are attributes of qutip_qtrl.logging_utils,
in decreasing levels of messaging, are:
DEBUG_INTENSE, DEBUG_VERBOSE, DEBUG, INFO, WARN, ERROR, CRITICAL
Anything WARN or above is effectively 'quiet' execution,
Expand Down
19 changes: 8 additions & 11 deletions src/qutip_qtrl/grape.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
from qutip.ui.progressbar import BaseProgressBar
from qutip_qtrl.cy_grape import cy_overlap, cy_grape_inner

import qutip.logging_utils
import qutip_qtrl.logging_utils

logger = qutip.logging_utils.get_logger("qutip.control.grape")
logger = qutip_qtrl.logging_utils.get_logger("qutip.control.grape")


class GRAPEResult:
Expand Down Expand Up @@ -142,7 +142,7 @@ def grape_unitary(
with GRAPE, a time-dependent Hamiltonian that is defined by the
control pulses, as well as the resulting propagator.
"""
progress_bar = progress_bar or BaseProgressBar()
progress_bar = progress_bar or BaseProgressBar(R)
if eps is None:
eps = 0.1 * (2 * np.pi) / (times[-1])

Expand Down Expand Up @@ -170,9 +170,8 @@ def grape_unitary(
if beta:
warnings.warn("Causion: Using experimental feature time-penalty")

progress_bar.start(R)
for r in range(R - 1):
progress_bar.update(r)
progress_bar.update()

dt = times[1] - times[0]

Expand Down Expand Up @@ -316,7 +315,7 @@ def cy_grape_unitary(
with GRAPE, a time-dependent Hamiltonian that is defined by the
control pulses, as well as the resulting propagator.
"""
progress_bar = progress_bar or BaseProgressBar()
progress_bar = progress_bar or BaseProgressBar(R)

if eps is None:
eps = 0.1 * (2 * np.pi) / (times[-1])
Expand Down Expand Up @@ -359,9 +358,8 @@ def cy_grape_unitary(
alpha_val = alpha if alpha else 0.0
beta_val = beta if beta else 0.0

progress_bar.start(R)
for r in range(R - 1):
progress_bar.update(r)
progress_bar.update()

dt = times[1] - times[0]

Expand Down Expand Up @@ -500,7 +498,7 @@ def grape_unitary_adaptive(
with GRAPE, a time-dependent Hamiltonian that is defined by the
control pulses, as well as the resulting propagator.
"""
progress_bar = progress_bar or BaseProgressBar()
progress_bar = progress_bar or BaseProgressBar(R)

if eps is None:
eps = 0.1 * (2 * np.pi) / (times[-1])
Expand Down Expand Up @@ -553,9 +551,8 @@ def _fidelity_function(x):
_r = 0
_prev_overlap = 0

progress_bar.start(R)
for r in range(R - 1):
progress_bar.update(r)
progress_bar.update()

_r = r
eps_log[r] = eps_vec[best_k]
Expand Down
2 changes: 1 addition & 1 deletion src/qutip_qtrl/loadparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

# QuTiP logging
from qutip import Qobj
import qutip.logging_utils as logging
import qutip_qtrl.logging_utils as logging

logger = logging.get_logger()

Expand Down
114 changes: 114 additions & 0 deletions src/qutip_qtrl/logging_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
"""
This module contains internal-use functions for configuring and writing to
debug logs, using Python's internal logging functionality by default.
"""

# IMPORTS
from __future__ import absolute_import
import inspect
import logging

from qutip.settings import settings

# EXPORTS
NOTSET = logging.NOTSET
DEBUG_INTENSE = logging.DEBUG - 4
DEBUG_VERBOSE = logging.DEBUG - 2
DEBUG = logging.DEBUG
INFO = logging.INFO
WARN = logging.WARN
ERROR = logging.ERROR
CRITICAL = logging.CRITICAL

__all__ = ["get_logger"]

# META-LOGGING

metalogger = logging.getLogger(__name__)
metalogger.addHandler(logging.NullHandler())


# FUNCTIONS


def get_logger(name=None):
"""
Returns a Python logging object with handlers configured
in accordance with ~/.qutiprc. By default, this will do
something sensible to integrate with IPython when running
in that environment, and will print to stdout otherwise.
Note that this function uses a bit of magic, and thus should
not be considered part of the QuTiP API. Rather, this function
is for internal use only.
Parameters
----------
name : str
Name of the logger to be created. If not passed,
the name will automatically be set to the name of the
calling module.
"""
if name is None:
try:
calling_frame = inspect.stack()[1][0]
calling_module = inspect.getmodule(calling_frame)
name = (
calling_module.__name__
if calling_module is not None
else "<none>"
)

except Exception:
metalogger.warn("Error creating logger.", exc_info=1)
name = "<unknown>"

logger = logging.getLogger(name)

policy = settings.log_handler

if policy == "default":
# Let's try to see if we're in IPython mode.
policy = "basic" if settings.ipython else "stream"

metalogger.debug(
"Creating logger for {} with policy {}.".format(name, policy)
)

if policy == "basic":
# Add no handlers, just let basicConfig do it all.
# This is nice for working with IPython, since
# it will use its own handlers instead of our StreamHandler
# below.
if settings.debug:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig()

elif policy == "stream":
formatter = logging.Formatter(
"[%(asctime)s] %(name)s[%(process)s]: "
"%(funcName)s: %(levelname)s: %(message)s",
"%Y-%m-%d %H:%M:%S",
)
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)

# We're handling things here, so no propagation out.
logger.propagate = False

elif policy == "null":
# We need to add a NullHandler so that debugging works
# at all, but this policy leaves it to the user to
# make their own handlers. This is particularly useful
# for capturing to logfiles.
logger.addHandler(logging.NullHandler())

if settings.debug:
logger.setLevel(logging.DEBUG)
else:
logger.setLevel(logging.WARN)

return logger
6 changes: 3 additions & 3 deletions src/qutip_qtrl/optimconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import numpy as np

# QuTiP logging
import qutip.logging_utils
import qutip_qtrl.logging_utils

logger = qutip.logging_utils.get_logger("qutip.control.optimconfig")
logger = qutip_qtrl.logging_utils.get_logger("qutip.control.optimconfig")
import qutip_qtrl.io as qtrlio


Expand All @@ -26,7 +26,7 @@ class OptimConfig(object):
----------
log_level : integer
level of messaging output from the logger.
Options are attributes of qutip.logging_utils,
Options are attributes of qutip_qtrl.logging_utils,
in decreasing levels of messaging, are:
DEBUG_INTENSE, DEBUG_VERBOSE, DEBUG, INFO, WARN, ERROR, CRITICAL
Anything WARN or above is effectively 'quiet' execution,
Expand Down
4 changes: 2 additions & 2 deletions src/qutip_qtrl/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
import qutip_qtrl.pulsegen as pulsegen
import qutip_qtrl.dump as qtrldump

import qutip.logging_utils as logging
import qutip_qtrl.logging_utils as logging

logger = logging.get_logger()

Expand Down Expand Up @@ -128,7 +128,7 @@ class Optimizer(object):
----------
log_level : integer
level of messaging output from the logger. Options are attributes of
qutip.logging_utils, in decreasing levels of messaging, are:
qutip_qtrl.logging_utils, in decreasing levels of messaging, are:
DEBUG_INTENSE, DEBUG_VERBOSE, DEBUG, INFO, WARN, ERROR, CRITICAL
Anything WARN or above is effectively 'quiet' execution, assuming
everything runs as expected. The default NOTSET implies that the level
Expand Down
2 changes: 1 addition & 1 deletion src/qutip_qtrl/propcomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from qutip_qtrl import errors

# QuTiP logging
import qutip.logging_utils as logging
import qutip_qtrl.logging_utils as logging

logger = logging.get_logger()

Expand Down
4 changes: 2 additions & 2 deletions src/qutip_qtrl/pulsegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import qutip_qtrl.dynamics as dynamics
import qutip_qtrl.errors as errors

import qutip.logging_utils as logging
import qutip_qtrl.logging_utils as logging

logger = logging.get_logger()

Expand Down Expand Up @@ -140,7 +140,7 @@ class PulseGen:
log_level : integer
level of messaging output from the logger.
Options are attributes of qutip.logging_utils,
Options are attributes of qutip_qtrl.logging_utils,
in decreasing levels of messaging, are:
DEBUG_INTENSE, DEBUG_VERBOSE, DEBUG, INFO, WARN, ERROR, CRITICAL
Anything WARN or above is effectively 'quiet' execution,
Expand Down
12 changes: 6 additions & 6 deletions src/qutip_qtrl/pulseoptim.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
import qutip_qtrl.fidcomp as fidcomp
import qutip_qtrl.propcomp as propcomp
import qutip_qtrl.pulsegen as pulsegen
import qutip.logging_utils as logging
import qutip_qtrl.logging_utils as logging

logger = logging.get_logger()

Expand Down Expand Up @@ -331,7 +331,7 @@ def optimize_pulse(
log_level : integer
Level of messaging output from the logger. Options are attributes of
:obj:`qutip.logging_utils`, in decreasing levels of messaging, are:
:obj:`qutip_qtrl.logging_utils`, in decreasing levels of messaging, are:
DEBUG_INTENSE, DEBUG_VERBOSE, DEBUG, INFO, WARN, ERROR, CRITICAL.
Anything WARN or above is effectively 'quiet' execution, assuming
everything runs as expected. The default NOTSET implies that the level
Expand Down Expand Up @@ -740,7 +740,7 @@ def optimize_pulse_unitary(
log_level : integer
Level of messaging output from the logger. Options are attributes of
:obj:`qutip.logging_utils` in decreasing levels of messaging, are:
:obj:`qutip_qtrl.logging_utils` in decreasing levels of messaging, are:
DEBUG_INTENSE, DEBUG_VERBOSE, DEBUG, INFO, WARN, ERROR, CRITICAL
Anything WARN or above is effectively 'quiet' execution, assuming
everything runs as expected. The default NOTSET implies that the level
Expand Down Expand Up @@ -1069,7 +1069,7 @@ def opt_pulse_crab(
log_level : integer
level of messaging output from the logger. Options are attributes of
:obj:`qutip.logging_utils`, in decreasing levels of messaging, are:
:obj:`qutip_qtrl.logging_utils`, in decreasing levels of messaging, are:
DEBUG_INTENSE, DEBUG_VERBOSE, DEBUG, INFO, WARN, ERROR, CRITICAL
Anything WARN or above is effectively 'quiet' execution, assuming
everything runs as expected. The default NOTSET implies that the level
Expand Down Expand Up @@ -1382,7 +1382,7 @@ def opt_pulse_crab_unitary(
log_level : integer
Level of messaging output from the logger. Options are attributes of
:obj:`qutip.logging_utils`, in decreasing levels of messaging, are:
:obj:`qutip_qtrl.logging_utils`, in decreasing levels of messaging, are:
DEBUG_INTENSE, DEBUG_VERBOSE, DEBUG, INFO, WARN, ERROR, CRITICAL.
Anything WARN or above is effectively 'quiet' execution, assuming
everything runs as expected. The default NOTSET implies that the level
Expand Down Expand Up @@ -1727,7 +1727,7 @@ def create_pulse_optimizer(
log_level : integer
level of messaging output from the logger.
Options are attributes of qutip.logging_utils,
Options are attributes of qutip_qtrl.logging_utils,
in decreasing levels of messaging, are:
DEBUG_INTENSE, DEBUG_VERBOSE, DEBUG, INFO, WARN, ERROR, CRITICAL
Anything WARN or above is effectively 'quiet' execution,
Expand Down
Loading

0 comments on commit 6df1df6

Please sign in to comment.