Skip to content

Commit 62c73ae

Browse files
committed
Get it working with python 3.11
1 parent 098b285 commit 62c73ae

File tree

10 files changed

+41
-49
lines changed

10 files changed

+41
-49
lines changed

README.md

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,14 @@ in C++ library.
4040

4141
## Installation
4242

43-
### Binary releases
4443

45-
NOTE: The Binary releases are not being maintained. Suggest building from Sources instead.
46-
47-
If you want to use `htm.core` from Python, the easiest method is to install from [PyPI](https://test.pypi.org/project/htm.core/)
48-
- Note: to install from `pip` you'll need Python 3.7 only(does not work with older or newer versions)
49-
50-
```
51-
python -m pip install -i https://test.pypi.org/simple/ htm.core
52-
```
53-
Note: to run all examples with visualizations, install including extra requirements:
54-
`pip install -i https://test.pypi.org/simple/ htm.core[examples]`
55-
56-
If you intend to use `htm.core` as a library that provides you Python \& C++ HTM,
57-
you can use our [binary releases](https://github.com/htm-community/htm.core/releases).
58-
59-
#### Prerequisites
44+
### Prerequisites
6045

6146
For running C++ apps/examples/tests from binary release: none.
6247
If you want to use python, then obviously:
6348

6449
- [Python](https://python.org/downloads/)
65-
- Standard Python 3.7+ (Recommended)
50+
- Standard Python 3.7+ (Recommend using the latest) [Tested with 3.8, 3.11.1]
6651
- Standard Python 2.7
6752
+ We recommend the latest version of 2.7 where possible, but the system version should be fine.
6853
+ Python 2 is Not Supported on Windows, use Python 3 instead.
@@ -78,6 +63,13 @@ If you want to use python, then obviously:
7863
- Other implementations of Python may not work.
7964
- Only the standard python from python.org have been tested.
8065

66+
- **C\+\+ compiler**: c\+\+11/17 compatible (ie. g++, clang\+\+).
67+
- boost library (if not a C\+\+17 or greater compiler that supports filesystem.)
68+
If the build needs boost, it will automatically download and install boost with the options it needs.
69+
- CMake 3.7+ (MSVC 2019 needs CMake 3.14+, MSVC 2022 needs CMake 3.21+).
70+
Install the latest using [https://cmake.org/download/](https://cmake.org/download/)
71+
72+
Note: Windows MSVC 2019 runs as C\+\+17 by default so boost is not needed. On linux use -std=c++17 compile option to avoid needing boost.
8173

8274
### Building from Source
8375

@@ -91,21 +83,12 @@ To fork the repo with `git`:
9183
git clone https://github.com/htm-community/htm.core
9284
```
9385

94-
#### Prerequisites
95-
96-
- same as for Binary releases, plus:
97-
- **C\+\+ compiler**: c\+\+11/17 compatible (ie. g++, clang\+\+).
98-
- boost library (if not a C\+\+17 or greater compiler that supports filesystem.)
99-
If the build needs boost, it will automatically download and install boost with the options it needs.
100-
- CMake 3.7+ (MSVC 2019 needs CMake 3.14+, MSVC 2022 needs CMake 3.21+).
101-
Install the latest using [https://cmake.org/download/](https://cmake.org/download/)
102-
103-
Note: Windows MSVC 2019 runs as C\+\+17 by default so boost is not needed. On linux use -std=c++17 compile option to avoid needing boost.
104-
10586

10687
#### Simple Python build (any platform)
10788

108-
1) Prerequisites: install the following python packages: `pip install setuptools packaging`
89+
1) Prerequisites: install the following python packages:
90+
`python -m ensurepip --upgrade`
91+
`python -m pip install setuptools packaging`
10992

11093
2) At a command prompt, `cd` to the root directory of this repository.
11194

@@ -305,10 +288,11 @@ Generate IDE solution & build.
305288
* Specify the build system folder (`$HTM_CORE/build/scripts`), i.e. where IDE solution will be created.
306289
* Click `Generate`.
307290

308-
#### For MS Visual Studio 2017 or 2019 as the IDE
291+
#### For MS Visual Studio 2017, 2019 or 2022 as the IDE
309292

310293
After downloading the repository, do the following:
311294
* NOTE: Visual Studio 2019 requires CMake version 3.14 or higher.
295+
* Visual Studio 2022 requires CMake version 3.21 or higher.
312296
* CD to the top of repository.
313297
* Double click on `startupMSVC.bat`
314298
- This will setup the build, create the solution file (build/scripts/htm.cpp.sln), and start MS Visual Studio.
@@ -404,7 +388,7 @@ Note2: It is obvious, but anyway - do not use `--user` option while using python
404388
The installation scripts will automatically download and build the dependencies it needs.
405389

406390
* [Boost](https://www.boost.org/) (Not needed by C++17 compilers that support the filesystem module)
407-
* [LibYaml](https://pyyaml.org/wiki/LibYAML) or [Yaml-cpp](https://github.com/jbeder/yaml-cpp)
391+
* [LibYaml](https://pyyaml.org/wiki/LibYAML)
408392
* [Eigen](https://eigen.tuxfamily.org/index.php?title=Main_Page)
409393
* [PyBind11](https://github.com/pybind/pybind11)
410394
* [gtest](https://github.com/google/googletest)
@@ -427,10 +411,10 @@ distribution packages as listed and rename them as indicated. Copy these to
427411
| :--------------------- | :----------------- |
428412
| libyaml.zip (*note1) | https://github.com/yaml/libyaml/archive/refs/tags/0.2.5.tar.gz |
429413
| boost.tar.gz (*note3) | https://dl.bintray.com/boostorg/release/1.72.0/source/boost_1_72_0.tar.gz |
430-
| googletest.tar.gz | https://github.com/google/googletest/archive/refs/tags/release-1.11.0.tar.gz |
414+
| googletest.tar.gz | https://github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz |
431415
| eigen.tar.bz2 | https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz |
432416
| mnist.zip (*note4) | https://github.com/wichtounet/mnist/archive/3b65c35ede53b687376c4302eeb44fdf76e0129b.zip |
433-
| pybind11.tar.gz | https://github.com/pybind/pybind11/archive/refs/tags/v2.6.2.tar.gz |
417+
| pybind11.tar.gz | https://github.com/pybind/pybind11/archive/refs/tags/v2.10.1.tar.gz |
434418
| cereal.tar.gz | https://github.com/USCiLab/cereal/archive/refs/tags/v1.3.2.tar.gz |
435419
| sqlite3.tar.gz | https://www.sqlite.org/2022/sqlite-autoconf-3380200.tar.gz |
436420
| digestpp.zip | https://github.com/kerukuro/digestpp/archive/34ff2eeae397ed744d972d86b5a20f603b029fbd.zip |

bindings/py/cpp_src/plugin/PyBindRegion.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ namespace py = pybind11;
317317
// import base64
318318
// import pickle
319319
// f = io.BytesIO()
320-
// pickle.dump(node, f, 3)
320+
// pickle.dump(node, f, HIGHEST_PROTOCOL)
321321
// b = f.getvalue()
322322
// content = str(base64.b64encode(b))
323323
// f.close()
@@ -327,7 +327,8 @@ namespace py = pybind11;
327327

328328
#if PY_MAJOR_VERSION >= 3
329329
auto pickle = py::module::import("pickle");
330-
args = py::make_tuple(node_, f, 3); // use type 3 protocol
330+
auto highest = pickle.attr("HIGHEST_PROTOCOL");
331+
args = py::make_tuple(node_, f, highest); // use type 3,4, or 5 protocol
331332
#else
332333
auto pickle = py::module::import("cPickle");
333334
args = py::make_tuple(node_, f, 2); // use type 2 protocol
@@ -338,6 +339,8 @@ namespace py = pybind11;
338339
py::bytes b = f.attr("getvalue")();
339340
args = py::make_tuple(b);
340341
std::string content = py::str(py::module::import("base64").attr("b64encode")(*args));
342+
if (content[1] == '\'') // strip off leading "b'" and trailing "'"
343+
content = content.substr(2, content.length() - 3); f.attr("close")();
341344

342345
f.attr("close")();
343346
return content;

bindings/py/tests/regions/network_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def testNetworkPickle(self):
369369
network.initialize()
370370

371371
if sys.version_info[0] >= 3:
372-
proto = 3
372+
proto = pickle.HIGHEST_PROTOCOL
373373
else:
374374
proto = 2
375375

bindings/py/tests/sparse_link_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
TEST_DATA_SPARSE = np.array([4, 7])
2626
MAX_ACTIVE = TEST_DATA_SPARSE.size
2727
OUTPUT_WIDTH = 10
28-
TEST_DATA_DENSE = np.zeros(OUTPUT_WIDTH, dtype=np.bool)
28+
TEST_DATA_DENSE = np.zeros(OUTPUT_WIDTH, dtype=np.bool_)
2929
TEST_DATA_DENSE[TEST_DATA_SPARSE] = True
3030

3131

external/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ integrated into the cmake-based build of htm.core. The code that does this are
88
- Boost.cmake - If needed, finds the boost installation 1.69.0. Boost needs to be built with -fPIC so cannot use externally installed.
99
- digestpp.cmake - Download/install digestpp @ 36fa6ca : Hash digest lib (header only)
1010
- eigen.cmake - Downloads eigen 3.4.0 (header only)
11-
- gtest.cmake - Downloads and installs googletest 1.11.0
11+
- gtest.cmake - Downloads and installs googletest 1.12.1
1212
- mnist_data.cmake - Downloads the mnist data set from repository master.
13-
- pybind11.cmake - Downloads and installs pybind11 2.6.2 (header only)
13+
- pybind11.cmake - Downloads and installs pybind11 2.10.1 (header only)
1414
- libayml.cmake - Downloads and installs libyaml 0.2.5 which is an alternative to yaml-cpp (default)
1515
- cpp-httplib.cmake- Downloads and installs cpp-httplib 0.10.4, a REST server (header only)
1616
- cerial.cmake - Downloads and installs cerial 1.3.2, a serialization package (header only)

external/gtest.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
if(EXISTS "${REPOSITORY_DIR}/build/ThirdParty/share/googletest.tar.gz")
3636
set(URL "${REPOSITORY_DIR}/build/ThirdParty/share/googletest.tar.gz")
3737
else()
38-
set(URL https://github.com/google/googletest/archive/refs/tags/release-1.11.0.tar.gz)
38+
set(URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz)
3939
endif()
4040

4141
#

external/pybind11.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
if(EXISTS "${REPOSITORY_DIR}/build/ThirdParty/share/pybind11.tar.gz")
2222
set(URL "${REPOSITORY_DIR}/build/ThirdParty/share/pybind11.tar.gz")
2323
else()
24-
set(URL https://github.com/pybind/pybind11/archive/v2.6.2.tar.gz)
25-
# set(URL "https://github.com/pybind/pybind11/archive/refs/tags/v2.9.2.tar.gz")
26-
# This caused an error regarding Base64 someplace inside pickle load. Reverting to 2.6.2
24+
set(URL https://github.com/pybind/pybind11/archive/v2.10.1.tar.gz)
2725
endif()
2826

2927
message(STATUS "obtaining PyBind11")

py/tests/advanced/algorithms/apical_tiebreak_temporal_memory/shared_tests/sequence_memory_test_base.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,9 +892,16 @@ def noisy(pattern, wFlip, n):
892892
A noisy set of active indices
893893
"""
894894

895+
"""
896+
keeney, 12/2022
897+
The random.sample() method requires the first argument to be sorted.
898+
The apical_tiebreak_temporal_memory_test_base:897 was failing with an error saying
899+
it was not a sequence. So I added a sorted(). I would have thought that a set
900+
would already be sorted. I do not know if this affects the algorithm logic.
901+
"""
895902
noised = set(pattern)
896903

897-
noised.difference_update(random.sample(noised, wFlip))
904+
noised.difference_update(random.sample(sorted(noised), wFlip))
898905

899906
for _ in range(wFlip):
900907
while True:

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,9 @@ def configure(platform, build_type):
336336
os.chdir(scriptsDir)
337337

338338
# Make sure we have CMake installed
339-
cmake_ver = getCMakeVersion();
339+
cmake_ver = getCMakeVersion()
340340
if cmake_ver == False:
341-
raise Exception("CMake is not found.");
341+
raise Exception("CMake is not found.")
342342

343343
# Call CMake to setup the cache for the build.
344344
# Normally we would let CMake figure out the generator based on the platform.

src/test/unit/regions/ClassifierRegionTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ TEST(ClassifierRegionTest, asCategoryDecoder) {
143143
TEST(ClassifierRegionTest, asRealDecoder) {
144144
Network net;
145145

146-
std::shared_ptr<Region> encoder = net.addRegion("encoder", "RDSEEncoderRegion", "{size: 400, radius: 0.1, seed: 42, activeBits: 40}");
146+
std::shared_ptr<Region> encoder = net.addRegion("encoder", "RDSEEncoderRegion", "{size: 600, radius: 0.1, seed: 42, activeBits: 40}");
147147
std::shared_ptr<Region> sp = net.addRegion("sp", "SPRegion", "{columnCount: 1000, globalInhibition: true}");
148148
std::shared_ptr<Region> classifier = net.addRegion("classifier", "ClassifierRegion", "{learn: true}");
149149

@@ -173,7 +173,7 @@ TEST(ClassifierRegionTest, asRealDecoder) {
173173
const Real64 *pdf = reinterpret_cast<const Real64 *>(classifier->getOutputData("pdf").getBuffer());
174174
VERBOSE << "Encoded -0.552808, Classifier predicted " << titles[predicted] << " with a probability of " << pdf[predicted] << std::endl;
175175
EXPECT_NEAR(titles[predicted], -0.5, 0.01);
176-
EXPECT_NEAR(pdf[predicted], 0.682351, 0.003);
176+
EXPECT_NEAR(pdf[predicted], 0.711981, 0.003);
177177
}
178178

179179
{
@@ -185,7 +185,7 @@ TEST(ClassifierRegionTest, asRealDecoder) {
185185
VERBOSE << "Encoded +0.830509, Classifier predicted " << titles[predicted] << " with a probability of "
186186
<< pdf[predicted] << std::endl;
187187
EXPECT_NEAR(titles[predicted], +0.8, 0.1);
188-
EXPECT_NEAR(pdf[predicted], 0.576886, 0.003);
188+
EXPECT_NEAR(pdf[predicted], 0.741413357, 0.003);
189189
}
190190
}
191191

0 commit comments

Comments
 (0)