Skip to content

Issues with MLP convergence in dl.multilevel_modeling #777

@Mari123i

Description

@Mari123i

Please make sure these conditions are met

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of pertpy.
  • (optional) I have confirmed this bug exists on the main branch.

Report

Hello, I ran the tutorial exactly with the example data. Unfortunatley I get a bunch of convergence warnings.

Code:

'''
all_results, new_mcps = dl.multilevel_modeling(
ct_subs=ct_subs,
mcp_scores=mcps,
ws_dict=ws,
confounder="gender",
)


/home/l/lkandushi/anaconda3/envs/pert_env/lib/python3.12/site-packages/statsmodels/base/model.py:607: 
ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
  warnings.warn("Maximum Likelihood optimization failed to "

/home/l/lkandushi/anaconda3/envs/pert_env/lib/python3.12/site-packages/statsmodels/regression/mixed_linear_model.py
:2200: ConvergenceWarning: Retrying MixedLM optimization with lbfgs
  warnings.warn(

/home/l/lkandushi/anaconda3/envs/pert_env/lib/python3.12/site-packages/statsmodels/regression/mixed_linear_model.py
:2237: ConvergenceWarning: The MLE may be on the boundary of the parameter space.
  warnings.warn(msg, ConvergenceWarning)

/home/l/lkandushi/anaconda3/envs/pert_env/lib/python3.12/site-packages/statsmodels/regression/mixed_linear_model.py
:2261: ConvergenceWarning: The Hessian matrix at the estimated parameter values is not positive definite.
  warnings.warn(msg, ConvergenceWarning)

/home/l/lkandushi/anaconda3/envs/pert_env/lib/python3.12/site-packages/statsmodels/base/model.py:607: 
ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
  warnings.warn("Maximum Likelihood optimization failed to "
/home/l/lkandushi/anaconda3/envs/pert_env/lib/python3.12/site-packages/statsmodels/regression/mixed_linear_model.py
:2200: ConvergenceWarning: Retrying MixedLM optimization with lbfgs
  warnings.warn(
/home/l/lkandushi/anaconda3/envs/pert_env/lib/python3.12/site-packages/statsmodels/regression/mixed_linear_model.py

:2237: ConvergenceWarning: The MLE may be on the boundary of the parameter space.
  warnings.warn(msg, ConvergenceWarning)
/home/l/lkandushi/anaconda3/envs/pert_env/lib/python3.12/site-packages/statsmodels/base/model.py:607: 
ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
  warnings.warn("Maximum Likelihood optimization failed to "
/home/l/lkandushi/anaconda3/envs/pert_env/lib/python3.12/site-packages/statsmodels/regression/mixed_linear_model.py

:2200: ConvergenceWarning: Retrying MixedLM optimization with lbfgs

At some point with another dataset this went on for an hour before failing at this point:

p_val.replace(0, min(p for p in p_val if p is not None and p > 0)) in  def _get_cor_zscores(self, estimate: pd.Series, p_val: pd.Series). I assume the errors are related and no p-values are produced but I wasn't able to check.



### Versions

```python
| Package | Version |
| ------- | ------- |
| pandas  | 2.2.3   |
| pertpy  | 0.11.2  |
| scanpy  | 1.11.1  |
| anndata | 0.11.4  |
| numpy   | 1.26.4  |

| Dependency               | Version             |
| ------------------------ | ------------------- |
| pycparser                | 2.22                |
| nvidia-cuda-cupti-cu12   | 12.6.80             |
| decorator                | 5.1.1               |
| umap-learn               | 0.5.7               |
| nvidia-cuda-nvrtc-cu12   | 12.6.77             |
| seaborn                  | 0.13.2              |
| pyzmq                    | 26.2.0              |
| session-info2            | 0.1.2               |
| urllib3                  | 2.3.0               |
| psutil                   | 6.1.1               |
| executing                | 2.2.0               |
| lightning-utilities      | 0.14.3              |
| flax                     | 0.10.6              |
| jupyter_client           | 8.6.3               |
| toolz                    | 1.0.0               |
| nvidia-nvjitlink-cu12    | 12.6.85             |
| threadpoolctl            | 3.6.0               |
| ipykernel                | 6.29.5              |
| pillow                   | 11.2.1              |
| fsspec                   | 2025.5.0            |
| lamin_utils              | 0.14.0              |
| nvidia-cusparse-cu12     | 12.5.4.2            |
| nvidia-nvtx-cu12         | 12.6.77             |
| docrep                   | 0.3.2               |
| filelock                 | 3.18.0              |
| pynndescent              | 0.5.13              |
| nvidia-cufile-cu12       | 1.11.1.6            |
| msgpack                  | 1.1.0               |
| nvidia-nccl-cu12         | 2.26.2              |
| pyparsing                | 3.2.3               |
| sparsecca                | 0.3.1               |
| Pygments                 | 2.19.1              |
| fast-array-utils         | 1.2.1               |
| parso                    | 0.8.4               |
| xarray                   | 2025.4.0            |
| scikit-learn             | 1.5.2               |
| importlib_resources      | 6.5.2               |
| packaging                | 24.2                |
| optax                    | 0.2.4               |
| rich                     | 14.0.0              |
| patsy                    | 1.0.1               |
| wcwidth                  | 0.2.13              |
| triton                   | 3.3.0               |
| pytz                     | 2025.2              |
| sparse                   | 0.17.0              |
| PyYAML                   | 6.0.2               |
| statsmodels              | 0.14.4              |
| simplejson               | 3.20.1              |
| PubChemPy                | 1.0.4               |
| nvidia-cufft-cu12        | 11.3.0.4            |
| asttokens                | 3.0.0               |
| certifi                  | 2024.12.14          |
| nvidia-cudnn-cu12        | 9.5.1.17            |
| six                      | 1.17.0              |
| tqdm                     | 4.67.1              |
| nvidia-cuda-runtime-cu12 | 12.6.77             |
| typing_extensions        | 4.12.2              |
| jax                      | 0.6.0               |
| nvidia-curand-cu12       | 10.3.7.77           |
| pyomo                    | 6.9.2               |
| defusedxml               | 0.7.1               |
| idna                     | 3.10                |
| adjustText               | 1.3.0               |
| ply                      | 3.11                |
| numba                    | 0.60.0              |
| ml_dtypes                | 0.5.1               |
| jupyter_core             | 5.7.2               |
| attrs                    | 25.1.0              |
| scikit-misc              | 0.5.1               |
| scvi-tools               | 1.3.1.post1         |
| prompt_toolkit           | 3.0.50              |
| pyarrow                  | 20.0.0              |
| networkx                 | 3.4.2               |
| nvidia-cusolver-cu12     | 11.7.1.2            |
| charset-normalizer       | 3.4.1               |
| ipython                  | 8.31.0              |
| sympy                    | 1.14.0              |
| jaxtyping                | 0.3.2               |
| mudata                   | 0.3.1               |
| comm                     | 0.2.2               |
| legacy-api-wrap          | 1.4.1               |
| cycler                   | 0.12.1              |
| python-dateutil          | 2.9.0.post0         |
| tornado                  | 6.4.2               |
| lineax                   | 0.0.8               |
| debugpy                  | 1.8.12              |
| etils                    | 1.12.2              |
| natsort                  | 8.4.0               |
| h5py                     | 3.13.0              |
| absl-py                  | 2.2.2               |
| jedi                     | 0.19.2              |
| pyro-ppl                 | 1.9.1               |
| cffi                     | 1.17.1              |
| lightning                | 2.5.1.post0         |
| opt_einsum               | 3.4.0               |
| blitzgsea                | 1.3.54              |
| torchmetrics             | 1.7.1               |
| prompt-toolkit           | 3.0.50              |
| stack-data               | 0.6.3               |
| ipywidgets               | 8.1.5               |
| llvmlite                 | 0.43.0              |
| ml_collections           | 1.1.0               |
| setuptools               | 75.8.0              |
| pure-eval                | 0.2.3               |
| numpyro                  | 0.18.0              |
| kiwisolver               | 1.4.8               |
| matplotlib               | 3.10.3              |
| multipledispatch         | 1.0.0 (0.6.0)       |
| wadler_lindig            | 0.1.6               |
| joblib                   | 1.5.0               |
| pure_eval                | 0.2.3               |
| decoupler                | 1.8.0               |
| traitlets                | 5.14.3              |
| requests                 | 2.32.3              |
| matplotlib-inline        | 0.1.7               |
| platformdirs             | 4.3.6               |
| jaxopt                   | 0.8.5               |
| scipy                    | 1.15.3              |
| jaxlib                   | 0.6.0               |
| mpmath                   | 1.3.0               |
| torch                    | 2.7.0 (2.7.0+cu126) |
| ott-jax                  | 0.5.0               |
| equinox                  | 0.12.2              |
| nvidia-cublas-cu12       | 12.6.4.1            |
| pytorch-lightning        | 2.5.1.post0         |
| chex                     | 0.1.89              |

| Component | Info                                                                             |
| --------- | -------------------------------------------------------------------------------- |
| Python    | 3.12.9 | packaged by Anaconda, Inc. | (main, Feb  6 2025, 18:56:27) [GCC 11.2.0] |
| OS        | Linux-6.4.0-150600.23.47-default-x86_64-with-glibc2.38                           |
| Updated   | 2025-05-22 00:30                                                                 |

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions