{"id":9359,"library":"theano-pymc","title":"Theano-PyMC","description":"Theano-PyMC is a Python library that serves as an optimizing compiler for evaluating mathematical expressions on CPUs and GPUs, featuring efficient symbolic differentiation. It is a fork of the original Theano library, specifically maintained by the PyMC developers to support PyMC3. Its current version is 1.1.2, released in January 2021. While PyMC has since transitioned to other backends (Aesara, then PyTensor), Theano-PyMC remains the foundational backend for PyMC3, meaning its release cadence is tied to critical compatibility and bug fixes for that specific PyMC version.","status":"maintenance","version":"1.1.2","language":"en","source_language":"en","source_url":"https://github.com/majidaldo/Theano-PyMC","tags":["numerical computation","symbolic differentiation","GPU","deep learning","Bayesian inference","PyMC3 backend","compiler"],"install":[{"cmd":"pip install Theano-PyMC","lang":"bash","label":"Via pip"},{"cmd":"conda install -c conda-forge theano-pymc","lang":"bash","label":"Via conda-forge"}],"dependencies":[{"reason":"Core dependency for multi-dimensional array operations.","package":"numpy","optional":false},{"reason":"Optional dependency for extended scientific computing functionalities.","package":"scipy","optional":true},{"reason":"Required for C/C++ compilation of optimized Theano functions for performance. Otherwise, Theano defaults to slower Python implementations.","package":"g++","optional":true}],"imports":[{"symbol":"theano","correct":"import theano"},{"note":"While 'T' was common in older Theano examples, 'tt' is now the widely adopted convention, especially within the PyMC ecosystem.","wrong":"import theano.tensor as T","symbol":"tensor","correct":"import theano.tensor as tt"},{"note":"Used to compile symbolic expressions into callable Python functions.","symbol":"function","correct":"from theano import function"},{"note":"Used for variables whose values can be changed after the function is compiled, often for model parameters or observed data in iterative computations.","symbol":"shared","correct":"from theano import shared"}],"quickstart":{"code":"import theano\nimport theano.tensor as tt\nfrom theano import function\n\n# Define symbolic variables\nx = tt.dscalar('x') # A double-precision scalar\ny = tt.dscalar('y')\n\n# Define a symbolic expression\nz = x ** 2 + y\n\n# Compile the expression into a callable function\nf = function([x, y], z)\n\n# Evaluate the function with numerical values\nresult = f(2.0, 3.0)\nprint(f\"Result of x^2 + y for x=2, y=3: {result}\")\n\n# Example with shared variable\nimport numpy as np\nfrom theano import shared\n\nshared_val = shared(np.array(10.0, dtype=theano.config.floatX), name='shared_val')\noutput = x * shared_val\ng_func = function([x], output)\n\nprint(f\"Result with shared_val=10 and x=5: {g_func(5.0)}\")\nshared_val.set_value(np.array(20.0, dtype=theano.config.floatX))\nprint(f\"Result with shared_val=20 and x=5: {g_func(5.0)}\")","lang":"python","description":"This quickstart demonstrates how to define symbolic variables, construct a mathematical expression, and compile it into an efficient, callable function using `theano.function`. It also shows the use of `theano.shared` variables, which allow their underlying numerical value to be updated without recompiling the Theano function, crucial for iterative algorithms or fitting models with changing data."},"warnings":[{"fix":"For PyMC3, ensure you are using a compatible NumPy version (e.g., NumPy < 1.20.0). For newer PyMC versions, they have moved to Aesara/PyTensor, which addresses these compatibilities.","message":"Theano-PyMC's compatibility with NumPy versions above 1.19.x can be problematic due to the deprecation of `np.bool` and other internal changes. Using newer NumPy versions with older Theano-PyMC (or PyMC3 versions that depend on it) will lead to `AttributeError`.","severity":"breaking","affected_versions":"<1.1.2 with NumPy >= 1.20.0"},{"fix":"Ensure `g++` (or an equivalent C/C++ compiler) is installed and correctly configured in your system's PATH. On Linux, install `build-essential`. On Windows, consider MinGW or Visual C++ build tools. Theano's configuration flags can be checked and modified, e.g., `theano.config.cxx = ''` to silence the warning if you intentionally use Python-only execution.","message":"Theano-PyMC relies on C/C++ compilers (like `g++`) for optimal performance by compiling symbolic graphs into efficient machine code. Without a detected compiler, it will silently fall back to slower Python implementations, severely degrading performance.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For new projects or if using PyMC >= 4.0, you should use `PyTensor` (imported as `pytensor`) instead of `theano-pymc`. If maintaining PyMC3 code, Theano-PyMC is the correct backend.","message":"The broader PyMC project has transitioned from Theano-PyMC to `Aesara` and then `PyTensor` as its primary backend for symbolic computation. While Theano-PyMC remains important for PyMC3, direct new development or feature additions for Theano-PyMC as a standalone library are minimal, focusing on critical fixes for PyMC3.","severity":"deprecated","affected_versions":"Since PyMC 4.0"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Downgrade NumPy to a compatible version, typically `<1.20.0`. For example: `pip install 'numpy<1.20.0'` or `conda install 'numpy<1.20.0'`.","cause":"Using Theano-PyMC with a newer version of NumPy (>= 1.20.0) where `np.bool` has been deprecated.","error":"AttributeError: module 'numpy' has no attribute 'bool'"},{"fix":"Install and configure an optimized BLAS library. For conda users, installing from `conda-forge` often includes MKL or OpenBLAS automatically (`conda install -c conda-forge theano-pymc`). For pip users, ensure a properly configured scientific Python stack or refer to Theano's BLAS configuration documentation. This may involve setting environment variables like `MKL_THREADING_LAYER=GNU` or `OMP_NUM_THREADS`.","cause":"Theano is unable to find an optimized BLAS (Basic Linear Algebra Subprograms) library (like OpenBLAS or MKL) or is not configured to use it, defaulting to a less efficient NumPy-provided implementation.","error":"WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions"},{"fix":"Explicitly install the exact `theano-pymc` version required by your `PyMC3` installation. For example: `pip uninstall theano-pymc pymc3 && pip install 'theano-pymc==1.0.11' 'pymc3==3.10.0'` (adjust versions as needed). Using `conda` is often recommended for better dependency resolution: `conda install -c conda-forge theano-pymc=1.0.11 pymc3=3.10.0`.","cause":"A specific version of PyMC3 (e.g., 3.10.0) is strictly dependent on an exact version of Theano-PyMC (e.g., 1.0.11), and a different version has been installed.","error":"ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. pymc3 3.10.0 requires theano-pymc==1.0.11, but you have theano-pymc 1.1.2 which is incompatible."}]}