From 19f2e3211cd6798105996233bc220871564976f8 Mon Sep 17 00:00:00 2001 From: cogmission Date: Sun, 1 May 2016 20:06:57 -0500 Subject: [PATCH 1/6] Added additional check for running thread before calling halt in preSerialize() --- build.gradle | 9 +++++---- pom.xml | 2 +- src/main/java/org/numenta/nupic/network/Network.java | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 64d8d0fe..8ab6c045 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ apply plugin: 'eclipse' apply plugin: 'signing' group = 'org.numenta' -version = '0.6.7-SNAPSHOT' +version = '0.6.7' archivesBaseName = 'htm.java' sourceCompatibility = 1.8 @@ -12,7 +12,7 @@ targetCompatibility = 1.8 jar { manifest { - attributes 'Implementation-Title': 'htm.java', 'Implementation-Version': '0.6.7-SNAPSHOT' + attributes 'Implementation-Title': 'htm.java', 'Implementation-Version': '0.6.7' } } @@ -28,10 +28,10 @@ test { outputs.upToDateWhen { false } } -/* UNCOMMENT TO SEE STANDARD_OUT & STANDARD_ERR DURING BUILD +/* UNCOMMENT TO SEE STANDARD_OUT & STANDARD_ERR DURING BUILD */ test { testLogging.showStandardStreams = true -}*/ +} dependencies { compile group: 'joda-time', name: 'joda-time', version: '2.5' @@ -126,6 +126,7 @@ uploadArchives { javadoc.failOnError = false if(!project.hasProperty('ossrhUsername')) { + println "returning from has Property false" return } diff --git a/pom.xml b/pom.xml index 7342c1fd..ca267187 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.numenta htm.java - 0.6.7-SNAPSHOT + 0.6.7 htm.java The Java version of Numenta's HTM technology diff --git a/src/main/java/org/numenta/nupic/network/Network.java b/src/main/java/org/numenta/nupic/network/Network.java index a61c692d..9c7c0933 100644 --- a/src/main/java/org/numenta/nupic/network/Network.java +++ b/src/main/java/org/numenta/nupic/network/Network.java @@ -270,7 +270,7 @@ public static PALayer createPALayer(String name, Parameters p) { @SuppressWarnings("unchecked") @Override public Network preSerialize() { - if(shouldDoHalt) { + if(shouldDoHalt && isThreadRunning) { halt(); } regions.stream().forEach(r -> r.preSerialize()); From 5da0a90ca6ffba179e763d04a70b812983b737a9 Mon Sep 17 00:00:00 2001 From: cogmission Date: Sun, 1 May 2016 20:10:21 -0500 Subject: [PATCH 2/6] turn off standard out and err output --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 8ab6c045..d579d2e0 100644 --- a/build.gradle +++ b/build.gradle @@ -28,10 +28,10 @@ test { outputs.upToDateWhen { false } } -/* UNCOMMENT TO SEE STANDARD_OUT & STANDARD_ERR DURING BUILD */ +/* UNCOMMENT TO SEE STANDARD_OUT & STANDARD_ERR DURING BUILD test { testLogging.showStandardStreams = true -} +}*/ dependencies { compile group: 'joda-time', name: 'joda-time', version: '2.5' From 4e739644376b1d35e0fc3a673e7e7424351fd149 Mon Sep 17 00:00:00 2001 From: cogmission Date: Sun, 1 May 2016 20:29:37 -0500 Subject: [PATCH 3/6] Make sure close has been called on the Network prior to serialization --- src/main/java/org/numenta/nupic/network/Network.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/org/numenta/nupic/network/Network.java b/src/main/java/org/numenta/nupic/network/Network.java index 9c7c0933..c8cc4afa 100644 --- a/src/main/java/org/numenta/nupic/network/Network.java +++ b/src/main/java/org/numenta/nupic/network/Network.java @@ -272,7 +272,13 @@ public static PALayer createPALayer(String name, Parameters p) { public Network preSerialize() { if(shouldDoHalt && isThreadRunning) { halt(); + }else{ // Make sure "close()" has been called on the Network + if(regions.size() == 1) { + this.tail = regions.get(0); + } + tail.close(); } + regions.stream().forEach(r -> r.preSerialize()); return this; } From 0b3630fe48bdf5b45903c7fb0eb20ffc3797f70e Mon Sep 17 00:00:00 2001 From: cogmission Date: Sun, 1 May 2016 20:33:18 -0500 Subject: [PATCH 4/6] Change versions for new release --- build.gradle | 4 ++-- pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index d579d2e0..ecdd10f5 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ apply plugin: 'eclipse' apply plugin: 'signing' group = 'org.numenta' -version = '0.6.7' +version = '0.6.8' archivesBaseName = 'htm.java' sourceCompatibility = 1.8 @@ -12,7 +12,7 @@ targetCompatibility = 1.8 jar { manifest { - attributes 'Implementation-Title': 'htm.java', 'Implementation-Version': '0.6.7' + attributes 'Implementation-Title': 'htm.java', 'Implementation-Version': '0.6.8' } } diff --git a/pom.xml b/pom.xml index ca267187..572b7061 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.numenta htm.java - 0.6.7 + 0.6.8 htm.java The Java version of Numenta's HTM technology From 669383442914841976aeb450f413e4f5cd6cdb81 Mon Sep 17 00:00:00 2001 From: cogmission Date: Sun, 1 May 2016 20:44:03 -0500 Subject: [PATCH 5/6] Use different FSTObjectInput constructor which passes in the FSTConfiguration --- .../java/org/numenta/nupic/serialize/HTMObjectInput.java | 5 +++-- .../java/org/numenta/nupic/serialize/HTMObjectOutput.java | 5 +++-- .../java/org/numenta/nupic/serialize/SerializerCore.java | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/numenta/nupic/serialize/HTMObjectInput.java b/src/main/java/org/numenta/nupic/serialize/HTMObjectInput.java index 27c935e1..65661d32 100644 --- a/src/main/java/org/numenta/nupic/serialize/HTMObjectInput.java +++ b/src/main/java/org/numenta/nupic/serialize/HTMObjectInput.java @@ -4,11 +4,12 @@ import java.io.InputStream; import org.numenta.nupic.Persistable; +import org.nustaq.serialization.FSTConfiguration; import org.nustaq.serialization.FSTObjectInput; public class HTMObjectInput extends FSTObjectInput { - public HTMObjectInput(InputStream in) throws IOException { - super(in); + public HTMObjectInput(InputStream in, FSTConfiguration config) throws IOException { + super(in, config); } @SuppressWarnings("rawtypes") diff --git a/src/main/java/org/numenta/nupic/serialize/HTMObjectOutput.java b/src/main/java/org/numenta/nupic/serialize/HTMObjectOutput.java index 463fd78c..543d8af0 100644 --- a/src/main/java/org/numenta/nupic/serialize/HTMObjectOutput.java +++ b/src/main/java/org/numenta/nupic/serialize/HTMObjectOutput.java @@ -4,11 +4,12 @@ import java.io.OutputStream; import org.numenta.nupic.Persistable; +import org.nustaq.serialization.FSTConfiguration; import org.nustaq.serialization.FSTObjectOutput; public class HTMObjectOutput extends FSTObjectOutput { - public HTMObjectOutput(OutputStream out) { - super(out); + public HTMObjectOutput(OutputStream out, FSTConfiguration config) { + super(out, config); } @SuppressWarnings("rawtypes") diff --git a/src/main/java/org/numenta/nupic/serialize/SerializerCore.java b/src/main/java/org/numenta/nupic/serialize/SerializerCore.java index 190a36df..ec9f680c 100644 --- a/src/main/java/org/numenta/nupic/serialize/SerializerCore.java +++ b/src/main/java/org/numenta/nupic/serialize/SerializerCore.java @@ -104,7 +104,7 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE * @throws IOException */ public HTMObjectInput getObjectInput(InputStream is) throws IOException { - return new HTMObjectInput(is); + return new HTMObjectInput(is, fastSerialConfig); } /** @@ -113,7 +113,7 @@ public HTMObjectInput getObjectInput(InputStream is) throws IOException { * @return the HTMObjectOutput */ public HTMObjectOutput getObjectOutput(OutputStream os) { - return new HTMObjectOutput(os); + return new HTMObjectOutput(os, fastSerialConfig); } /** From 22ba2d76ceaf1fdd9689c51969a321a87c514e7f Mon Sep 17 00:00:00 2001 From: cogmission Date: Sun, 1 May 2016 21:40:20 -0500 Subject: [PATCH 6/6] Added HTMObjecInput and HTMObjectOutput test --- .../serialize/HTMObjectInputOutputTest.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/test/java/org/numenta/nupic/serialize/HTMObjectInputOutputTest.java diff --git a/src/test/java/org/numenta/nupic/serialize/HTMObjectInputOutputTest.java b/src/test/java/org/numenta/nupic/serialize/HTMObjectInputOutputTest.java new file mode 100644 index 00000000..9eb9cc5f --- /dev/null +++ b/src/test/java/org/numenta/nupic/serialize/HTMObjectInputOutputTest.java @@ -0,0 +1,79 @@ +package org.numenta.nupic.serialize; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.numenta.nupic.Parameters; +import org.numenta.nupic.Parameters.KEY; +import org.numenta.nupic.algorithms.Anomaly; +import org.numenta.nupic.algorithms.SpatialPooler; +import org.numenta.nupic.algorithms.TemporalMemory; +import org.numenta.nupic.network.Network; +import org.numenta.nupic.network.NetworkTestHarness; +import org.numenta.nupic.network.Persistence; +import org.numenta.nupic.network.PublisherSupplier; +import org.numenta.nupic.network.sensor.ObservableSensor; +import org.numenta.nupic.network.sensor.Sensor; +import org.numenta.nupic.network.sensor.SensorParams; +import org.numenta.nupic.network.sensor.SensorParams.Keys; +import org.numenta.nupic.util.FastRandom; + + +public class HTMObjectInputOutputTest { + + @Test + public void testRoundTrip() { + Network network = getLoadedHotGymNetwork(); + SerializerCore serializer = Persistence.get().serializer(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + HTMObjectOutput writer = serializer.getObjectOutput(baos); + try { + writer.writeObject(network, Network.class); + writer.flush(); + writer.close(); + }catch(Exception e) { + fail(); + } + + byte[] bytes = baos.toByteArray(); + + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + try { + HTMObjectInput reader = serializer.getObjectInput(bais); + Network serializedNetwork = (Network)reader.readObject(Network.class); + assertNotNull(serializedNetwork); + assertTrue(serializedNetwork.equals(network)); + }catch(Exception e) { + e.printStackTrace(); + fail(); + } + } + + private Network getLoadedHotGymNetwork() { + Parameters p = NetworkTestHarness.getParameters().copy(); + p = p.union(NetworkTestHarness.getHotGymTestEncoderParams()); + p.setParameterByKey(KEY.RANDOM, new FastRandom(42)); + + Sensor> sensor = Sensor.create( + ObservableSensor::create, SensorParams.create(Keys::obs, new Object[] {"name", + PublisherSupplier.builder() + .addHeader("timestamp, consumption") + .addHeader("datetime, float") + .addHeader("B").build() })); + + Network network = Network.create("test network", p).add(Network.createRegion("r1") + .add(Network.createLayer("1", p) + .alterParameter(KEY.AUTO_CLASSIFY, true) + .add(Anomaly.create()) + .add(new TemporalMemory()) + .add(new SpatialPooler()) + .add(sensor))); + + return network; + } +}