Skip to content

Commit

Permalink
Merge branch 'qutip:master' into heom_mauro_inputoutpuit
Browse files Browse the repository at this point in the history
  • Loading branch information
nwlambert authored Dec 23, 2024
2 parents 8946824 + c5761bb commit 912a6ed
Show file tree
Hide file tree
Showing 49 changed files with 220 additions and 82 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
# between 13 and 14, mac changed from intel chip to apple silicon
os: [ubuntu-latest, windows-latest, macos-13, macos-latest]
env:
# Set up wheels matrix. This is CPython 3.10--3.12 for all OS targets.
CIBW_BUILD: "cp3{10,11,12}-*"
# Set up wheels matrix. This is CPython 3.10--3.13 for all OS targets.
CIBW_BUILD: "cp3{10,11,12,13}-*"
# Numpy and SciPy do not supply wheels for i686 or win32 for
# Python 3.10+, so we skip those:
CIBW_SKIP: "*-musllinux* *-manylinux_i686 *-win32"
Expand All @@ -126,8 +127,8 @@ jobs:
- name: Install cibuildwheel
run: |
# cibuildwheel does the heavy lifting for us. Tested on
# 2.19, but should be fine at least up to any minor new release.
python -m pip install 'cibuildwheel==2.19.*'
# 2.22, but should be fine at least up to any minor new release.
python -m pip install 'cibuildwheel==2.22.*'
- name: Build wheels
shell: bash
Expand Down Expand Up @@ -163,7 +164,7 @@ jobs:
- name: Check wheels
run: |
ls -R wheels
if ! [[ $(ls wheels/*.whl | wc -l) == 9 ]]; then exit 1; fi
if ! [[ $(ls wheels/*.whl | wc -l) == 16 ]]; then exit 1; fi
if ! ls wheels/*.tar.gz 1> /dev/null 2>&1; then exit 1; fi
if ! ls wheels/*.zip 1> /dev/null 2>&1; then exit 1; fi
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ jobs:
# Mac
# Mac has issues with MKL since september 2022.
- case-name: macos
# setup-miniconda not compatible with macos-latest presently.
# https://github.com/conda-incubator/setup-miniconda/issues/344
os: macos-latest
python-version: "3.12"
numpy-build: ">=2.0.0"
Expand All @@ -97,7 +95,7 @@ jobs:
nomkl: 1

- case-name: macos - numpy fallback
os: macos-latest
os: macos-13 # Test on intel cpus
python-version: "3.11"
numpy-build: ">=2.0.0"
numpy-requirement: ">=1.25,<1.26"
Expand Down Expand Up @@ -145,6 +143,7 @@ jobs:
python -m pip install loky tqdm mpmath # extras
python -m pip install "coverage${{ matrix.coverage-requirement }}" chardet
python -m pip install pytest-cov coveralls pytest-fail-slow
python -m pip install setuptools
if [[ "${{ matrix.pypi }}" ]]; then
pip install "numpy${{ matrix.numpy-build }}"
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.1.0.dev
5.2.0.dev
73 changes: 73 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,79 @@ Change Log

.. towncrier release notes start
QuTiP 5.1.0 (2024-12-12)
========================

Features
--------

- It adds odd parity support to HEOM's fermionic solver (#2261, by Gerardo Jose Suarez)
- Create `SMESolver.run_from_experiment`, which allows to run stochastic evolution from know noise or measurements. (#2318)
- Add types hints. (#2327, #2473)
- Weighted trajectories in trajectory solvers (enables improved sampling for nm_mcsolve) (#2369, by Paul Menczel)
- Updated `qutip.core.metrics.dnorm` to have an efficient speedup when finding the difference of two unitaries. We use a result on page 18 of
D. Aharonov, A. Kitaev, and N. Nisan, (1998). (#2416, by owenagnel)
- Allow mixed initial conditions for mcsolve and nm_mcsolve. (#2437, by Paul Menczel)
- Add support for `jit` and `grad` in qutip.core.metrics (#2461, by Rochisha Agarwal)
- Allow merging results from stochastic solvers. (#2474)
- Support measurement statistics for `jax` and `jaxdia` dtypes (#2493, by Rochisha Agarwal)
- Enable mcsolve with jax.grad using numpy_backend (#2499, by Rochisha Agarwal)
- Add propagator method to steadystate (#2508)
- Introduces the qutip.core.environment module, which contains classes that characterize bosonic and fermionic thermal environments. (#2534, by Gerardo Jose Suarez)
- Implements a `einsum` function for Qobj dimensions (Evaluates the Einstein summation convention on the operands.) (#2545, by Franco Mayo)
- Wave function calculations have been sped up with a Cython implementation.
It optimizes the update method of the HarmonicOscillatorWaveFunction class in distribution.py. (#2553, by Matheus Gomes Cordeiro)
- Speed up `kraus_to_super` by adding a `sparse` option. (#2569, by Sola85)


Bug Fixes
---------

- Fix a dimension problem for the argument color of Bloch.add_states
Clean-up of the code in Bloch.add_state
Add Bloch.add_arc and Bloch.add_line in the guide on Bloch class (#2445, by PositroniumJS)
- Fix HTMLProgressBar display (#2475)
- Make expm, cosm, sinm work with jax. (#2484, by Rochisha Agarwal)
- Fix stochastic solver step method (#2491)
- `clip` gives deprecation warning, that might be a problem in the future. Hence switch to `where` (#2507, by Rochisha Agarwal)
- Fix brmesolve detection of contant vs time-dependent system. (#2530)
- `propagator` now accepts list format `c_ops` like `mesolve` does. (#2532)
- Fix compatibility issue with matplotlib>=3.9 in matrix_histogram (#2544, by Andreas Maeder)
- Resolve incompatibility of TwoModeQuadratureCorrelation class (#2548, by quantum-menace)
- Fix sparse eigen solver issue with many degenerate eigen values. (#2586)
- Fix getting tensor permutation for uneven super operators. (#2561)


Documentation
-------------

- Improve guide-settings page. (#2403)
- Tidy up formatting of type aliases in the api documentation (#2436, by Paul Menczel)
- Update documentation
- Update contributors
- Improve apidoc readability (#2523)
- Fix error in simdiag docstring (#2585, by Sola85)


Miscellaneous
-------------

- Add auto_real_casting options. (#2329)
- Add dispatcher for sqrtm (#2453, by Rochisha Agarwal)
- Make `e_ops`, `args` and `options` keyword only.
Solver were inconsistent with `e_ops` usually following `c_ops` but sometime
preceding it. Setting it as keyword only remove the need to memorize the
signature of each solver. (#2489)
- Introduces a new `NumpyBackend `class that enables dynamic selection of the numpy_backend used in `qutip`.
The class facilitates switching between different numpy implementations ( `numpy` and `jax.numpy` mainly ) based on the configuration specified in `settings.core`. (#2490, by Rochisha Agarwal)
- Improve mkl lookup function. (#2497)
- Deterministic trajectories are not counted in ``ntraj``. (#2502)
- Allow tests to be executed multiple times in one Python session (#2538, by Zhang Maiyun)
- Improve performance of qutip.Qobj by using static numpy version check (#2557, by Pieter Eendebak)
- Fix towncrier check (#2542)



QuTiP 5.0.4 (2024-08-30)
========================

Expand Down
1 change: 0 additions & 1 deletion doc/changes/2261.feature

This file was deleted.

2 changes: 0 additions & 2 deletions doc/changes/2318.feature

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2327.feature

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2329.misc

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2369.feature

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2403.doc

This file was deleted.

2 changes: 0 additions & 2 deletions doc/changes/2416.feature

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2436.doc

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2437.feature

This file was deleted.

3 changes: 0 additions & 3 deletions doc/changes/2445.bugfix

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2453.feature

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2461.feature

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2473.misc

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2474.feature

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2484.bugfix

This file was deleted.

4 changes: 0 additions & 4 deletions doc/changes/2489.misc

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2490.feature

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2491.bugfix

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2493.feature

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2497.misc

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2499.feature

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2502.feature

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2507.bugfix

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2508.feature

This file was deleted.

3 changes: 0 additions & 3 deletions doc/changes/2523.misc

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2530.bugfix

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2532.bugfix

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2534.feature

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2538.misc

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2542.bugfix

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2544.bugfix

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2545.feature

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2548.bugfix

This file was deleted.

2 changes: 0 additions & 2 deletions doc/changes/2553.feature

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2557.misc

This file was deleted.

1 change: 0 additions & 1 deletion doc/changes/2569.feature

This file was deleted.

28 changes: 22 additions & 6 deletions qutip/core/data/dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ cdef extern from *:
void PyDataMem_FREE(void *ptr)


@cython.overflowcheck(True)
cdef size_t _mul_mem_checked(size_t a, size_t b, size_t c=0):
if c != 0:
return a * b * c
return a * b


# Creation functions like 'identity' and 'from_csr' aren't exported in __all__
# to avoid naming clashes with other type modules.
__all__ = [
Expand Down Expand Up @@ -122,7 +129,9 @@ cdef class Dense(base.Data):
low-level C code).
"""
cdef Dense out = Dense.__new__(Dense)
cdef size_t size = self.shape[0]*self.shape[1]*sizeof(double complex)
cdef size_t size = (
_mul_mem_checked(self.shape[0], self.shape[1], sizeof(double complex))
)
cdef double complex *ptr = <double complex *> PyDataMem_NEW(size)
if not ptr:
raise MemoryError(
Expand Down Expand Up @@ -169,7 +178,9 @@ cdef class Dense(base.Data):
dimensions. This is not a view onto the data, and changes to new array
will not affect the original data structure.
"""
cdef size_t size = self.shape[0]*self.shape[1]*sizeof(double complex)
cdef size_t size = (
_mul_mem_checked(self.shape[0], self.shape[1], sizeof(double complex))
)
cdef double complex *ptr = <double complex *> PyDataMem_NEW(size)
if not ptr:
raise MemoryError(
Expand Down Expand Up @@ -257,7 +268,9 @@ cpdef Dense empty(base.idxint rows, base.idxint cols, bint fortran=True):
"""
cdef Dense out = Dense.__new__(Dense)
out.shape = (rows, cols)
out.data = <double complex *> PyDataMem_NEW(rows * cols * sizeof(double complex))
out.data = <double complex *> PyDataMem_NEW(
_mul_mem_checked(rows, cols, sizeof(double complex))
)
if not out.data:
raise MemoryError(
"Could not allocate memory to create an empty "
Expand All @@ -282,7 +295,9 @@ cpdef Dense zeros(base.idxint rows, base.idxint cols, bint fortran=True):
cdef Dense out = Dense.__new__(Dense)
out.shape = (rows, cols)
out.data =\
<double complex *> PyDataMem_NEW_ZEROED(rows * cols, sizeof(double complex))
<double complex *> PyDataMem_NEW_ZEROED(
_mul_mem_checked(rows, cols), sizeof(double complex)
)
if not out.data:
raise MemoryError(
"Could not allocate memory to create a zero "
Expand Down Expand Up @@ -311,8 +326,9 @@ cpdef Dense from_csr(CSR matrix, bint fortran=False):
cdef Dense out = Dense.__new__(Dense)
out.shape = matrix.shape
out.data = (
<double complex *>
PyDataMem_NEW_ZEROED(out.shape[0]*out.shape[1], sizeof(double complex))
<double complex *> PyDataMem_NEW_ZEROED(
_mul_mem_checked(out.shape[0], out.shape[1]), sizeof(double complex)
)
)
if not out.data:
raise MemoryError(
Expand Down
3 changes: 2 additions & 1 deletion qutip/core/data/eigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,9 @@ def eigs_csr(data, /, isherm=None, vecs=True, sort='low', eigvals=0,

if vecs and isherm:
i = 0
degen_tol = (2 * tol or 1e-15 * data.shape[0])
while i < len(evals):
num_degen = np.sum(np.abs(evals - evals[i]) < (2 * tol or 1e-14))
num_degen = np.sum(np.abs(evals[i:] - evals[i]) < degen_tol)
# orthogonalize vectors 1 .. k with respect to the first, then
# 2 .. k with respect to the second, and so on. Relies on both the
# order of each pair and the ordering of pairs returned by
Expand Down
6 changes: 3 additions & 3 deletions qutip/core/dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def dims_to_tensor_shape(dims):
tensor_shape : tuple
NumPy shape of the corresponding tensor.
"""
perm = dims_to_tensor_perm(dims)
perm = np.argsort(dims_to_tensor_perm(dims))
dims = flatten(dims)
return tuple(map(partial(getitem, dims), perm))

Expand Down Expand Up @@ -936,10 +936,10 @@ def _get_tensor_perm(self):
# dims_to_tensor_perm
stepl = self.to_.step()
stepr = self.from_.step()
return list(np.concatenate([
return list(np.argsort(np.concatenate([
np.argsort(stepl)[::-1],
np.argsort(stepr)[::-1] + len(stepl)
]))
])))

def remove(self, idx: int | list[int]) -> "Dimensions":
"""
Expand Down
23 changes: 18 additions & 5 deletions qutip/simdiag.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ def _degen(tol, vecs, ops, i=0):
return vecs_new


def simdiag(ops, evals: bool = True, *,
tol: float = 1e-14, safe_mode: bool = True):
def simdiag(
ops,
evals: bool = True, *,
tol: float = 1e-14,
safe_mode: bool = True,
use_dense_solver: bool = True,
):
"""Simultaneous diagonalization of commuting Hermitian matrices.
Parameters
Expand All @@ -58,15 +63,20 @@ def simdiag(ops, evals: bool = True, *,
tol : float, default: 1e-14
Tolerance for detecting degenerate eigenstates.
safe_mode : bool, default: True
safe_mode : bool, default: True
Whether to check that all ops are Hermitian and commuting. If set to
``False`` and operators are not commuting, the eigenvectors returned
will often be eigenvectors of only the first operator.
use_dense_solver: bool, default: True
Whether to force use of numpy dense eigen solver. When ``False``
sparse operators will use scipy sparse eigen solver which is not
appropriate for this use.
Returns
-------
eigs : tuple
Tuple of arrays representing eigvecs and eigvals of quantum objects
Tuple of arrays representing eigvals and eigvecs of quantum objects
corresponding to simultaneous eigenvectors and eigenvalues for each
operator.
Expand All @@ -89,7 +99,10 @@ def simdiag(ops, evals: bool = True, *,
if (A * B - B * A).norm() / (A * B).norm() > tol:
raise TypeError('Matrices must commute.')

# TODO: rewrite using Data object
if use_dense_solver:
# Do not use sparse eigen solver.
ops = [op.to("Dense") for op in ops]

eigvals, eigvecs = _data.eigs(ops[0].data, True, True)
eigvecs = eigvecs.to_array()

Expand Down
Loading

0 comments on commit 912a6ed

Please sign in to comment.