Skip to content

Commit e526d32

Browse files
authored
Remove Text, SQLite and HDF5 backends (#4231)
* Removed Text, SQLite and HDF5 backends * Remove unnecessary line from .gitignnore * Black formatting on sampling.py * Restored save_trace and load_trace to global namespace * Remove another backend test
1 parent ec0ee58 commit e526d32

17 files changed

+22
-1367
lines changed

Diff for: .gitignore

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ _build
2121
# Merge tool
2222
*.orig
2323

24-
# Test artifacts
25-
mcmc.sqlite
26-
2724
# Docker development
2825
# notebooks/
2926

@@ -41,3 +38,6 @@ benchmarks/results/
4138
pytestdebug.log
4239
.dir-locals.el
4340
.pycheckers
41+
42+
# Codespaces
43+
pythonenv*

Diff for: RELEASE-NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## PyMC3 3.9.x (on deck)
44

55
### Maintenance
6+
- Removed non-NDArray (Text, SQLite, HDF5) backends and associated tests.
67
- Switch the dependency of Theano to our own fork, [Theano-PyMC](https://github.com/pymc-devs/Theano-PyMC).
78
- Mentioned the way to do any random walk with `theano.tensor.cumsum()` in `GaussianRandomWalk` docstrings (see [#4048](https://github.com/pymc-devs/pymc3/pull/4048)).
89
- Fixed numerical instability in ExGaussian's logp by preventing `logpow` from returning `-inf` (see [#4050](https://github.com/pymc-devs/pymc3/pull/4050)).

Diff for: docs/source/api/backends.rst

-16
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,6 @@ ndarray
1515
.. automodule:: pymc3.backends.ndarray
1616
:members:
1717

18-
sqlite
19-
^^^^^^
20-
21-
.. currentmodule:: pymc3.backends.sqlite
22-
23-
.. automodule:: pymc3.backends.sqlite
24-
:members:
25-
26-
text
27-
^^^^
28-
29-
.. currentmodule:: pymc3.backends.text
30-
31-
.. automodule:: pymc3.backends.text
32-
:members:
33-
3418
tracetab
3519
^^^^^^^^
3620

Diff for: pymc3/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __set_compiler_flags():
6767
from . import sampling
6868

6969
from .backends.tracetab import *
70-
from .backends import save_trace, load_trace, point_list_to_multitrace
70+
from .backends import save_trace, load_trace
7171

7272
from .plots import *
7373
from .tests import test

Diff for: pymc3/backends/__init__.py

+4-84
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Backends for traces
15+
"""Storage backends for traces
1616
17-
Available backends
18-
------------------
19-
20-
1. NumPy array (pymc3.backends.NDArray)
21-
2. Text files (pymc3.backends.Text)
22-
3. SQLite (pymc3.backends.SQLite)
23-
24-
The NDArray backend holds the entire trace in memory, whereas the Text
25-
and SQLite backends store the values while sampling.
26-
27-
Selecting a backend
28-
-------------------
29-
30-
By default, a NumPy array is used as the backend. To specify a different
31-
backend, pass a backend instance to `sample`.
32-
33-
For example, the following would save the sampling values to CSV files
34-
in the directory 'test'.
35-
36-
>>> import pymc3 as pm
37-
>>> with pm.Model():
38-
>>> db = pm.backends.Text('test')
39-
>>> trace = pm.sample(..., trace=db)
40-
41-
Note that as in the example above, one must have an active model context,
42-
or pass a `model` parameter in order to create a backend.
17+
The NDArray (pymc3.backends.NDArray) backend holds the entire trace in memory.
4318
4419
Selecting values from a backend
4520
-------------------------------
@@ -77,67 +52,12 @@
7752
>>> sliced_trace = trace[1000:]
7853
7954
The backend for the new trace is always NDArray, regardless of the
80-
type of original trace. Only the NDArray backend supports a stop
81-
value in the slice.
55+
type of original trace.
8256
8357
Loading a saved backend
8458
-----------------------
8559
86-
Saved backends can be loaded using `load` function in the module for the
87-
specific backend.
88-
89-
>>> trace = pm.backends.text.load('test')
90-
91-
Writing custom backends
92-
-----------------------
93-
94-
Backends consist of a class that handles sampling storage and value
95-
selection. Three sampling methods of backend will be called:
96-
97-
- setup: Before sampling is started, the `setup` method will be called
98-
with two arguments: the number of draws and the chain number. This is
99-
useful setting up any structure for storing the sampling values that
100-
require the above information.
101-
102-
- record: Record the sampling results for the current draw. This method
103-
will be called with a dictionary of values mapped to the variable
104-
names. This is the only sampling function that *must* do something to
105-
have a meaningful backend.
106-
107-
- close: This method is called following sampling and should perform any
108-
actions necessary for finalizing and cleaning up the backend.
109-
110-
The base storage class `backends.base.BaseTrace` provides common model
111-
setup that is used by all the PyMC backends.
112-
113-
Several selection methods must also be defined:
114-
115-
- get_values: This is the core method for selecting values from the
116-
backend. It can be called directly and is used by __getitem__ when the
117-
backend is indexed with a variable name or object.
118-
119-
- _slice: Defines how the backend returns a slice of itself. This
120-
is called if the backend is indexed with a slice range.
121-
122-
- point: Returns values for each variable at a single iteration. This is
123-
called if the backend is indexed with a single integer.
124-
125-
- __len__: This should return the number of draws.
126-
127-
When `pymc3.sample` finishes, it wraps all trace objects in a MultiTrace
128-
object that provides a consistent selection interface for all backends.
129-
If the traces are stored on disk, then a `load` function should also be
130-
defined that returns a MultiTrace object.
60+
Saved backends can be loaded using `arviz.from_netcdf`
13161
132-
For specific examples, see pymc3.backends.{ndarray,text,sqlite}.py.
13362
"""
13463
from ..backends.ndarray import NDArray, save_trace, load_trace, point_list_to_multitrace
135-
from ..backends.text import Text
136-
from ..backends.sqlite import SQLite
137-
from ..backends.hdf5 import HDF5
138-
139-
_shortcuts = {
140-
"text": {"backend": Text, "name": "mcmc"},
141-
"sqlite": {"backend": SQLite, "name": "mcmc.sqlite"},
142-
"hdf5": {"backend": HDF5, "name": "mcmc.hdf5"},
143-
}

Diff for: pymc3/backends/base.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
"""Base backend for traces
1616
17-
See the docstring for pymc3.backends for more information (including
18-
creating custom backends).
17+
See the docstring for pymc3.backends for more information
1918
"""
2019
import itertools as itl
2120
import logging

0 commit comments

Comments
 (0)