From d4157264f59f9797f8d68f2087df49d69ce6f8e0 Mon Sep 17 00:00:00 2001 From: Elton Cardoso do Nascimento <43186596+EltonCN@users.noreply.github.com> Date: Fri, 6 Sep 2024 17:25:44 -0300 Subject: [PATCH] MemoryStorageCodelet --- dev/memory_storage.ipynb | 167 ++++---- dev/memory_storage_codelet.ipynb | 715 +++++++++++++++++++++++++++++++ 2 files changed, 802 insertions(+), 80 deletions(-) create mode 100644 dev/memory_storage_codelet.ipynb diff --git a/dev/memory_storage.ipynb b/dev/memory_storage.ipynb index 97486ca..06854c0 100644 --- a/dev/memory_storage.ipynb +++ b/dev/memory_storage.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -13,7 +13,16 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 23, + "metadata": {}, + "outputs": [], + "source": [ + "mind_name = \"default_mind\"" + ] + }, + { + "cell_type": "code", + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -23,7 +32,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -32,7 +41,7 @@ "True" ] }, - "execution_count": 3, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -50,7 +59,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -59,18 +68,18 @@ "1" ] }, - "execution_count": 4, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "client.lpush(\"nodes\", \"node1\")" + "client.lpush(f\"{mind_name}:nodes\", \"node1\")" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ @@ -100,16 +109,16 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "def update_memory(memory_name, memory_object:cst.MemoryObject, client:redis.Redis):\n", - " timestamp = float(client.hget(f\"memories:{memory_name}\", \"timestamp\"))\n", + " timestamp = float(client.hget(f\"{mind_name}:memories:{memory_name}\", \"timestamp\"))\n", " \n", " if memory_object.timestamp < timestamp:\n", " print(\"Retrieve update\")\n", - " memory_dict = client.hgetall(f\"memories:{memory_name}\")\n", + " memory_dict = client.hgetall(f\"{mind_name}:memories:{memory_name}\")\n", "\n", " memory_object.set_evaluation(float(memory_dict[\"evaluation\"]))\n", " memory_object.set_name(memory_dict[\"name\"])\n", @@ -126,39 +135,31 @@ " memory_dict = MemoryEncoder.to_dict(memory_object)\n", " memory_dict[\"I\"] = json.dumps(memory_dict[\"I\"])\n", "\n", - " client.hset(f\"memories:{memory_name}\", mapping=memory_dict)\n", - " client.publish(f\"memories:{memory_name}:update\", \"\")" + " client.hset(f\"{mind_name}:memories:{memory_name}\", mapping=memory_dict)\n", + " client.publish(f\"{mind_name}:memories:{memory_name}:update\", \"\")" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 29, "metadata": {}, "outputs": [], "source": [ "def create_memory(node, memory_name, client:redis.Redis, pubsub:redis.client.PubSub) -> cst.MemoryObject:\n", - " nodes = client.lrange(\"nodes\", 0, -1)\n", - "\n", - " memory_exist = False\n", - " memory_node = \"\"\n", + " memory = cst.MemoryObject()\n", "\n", - " for n in nodes:\n", - " if n == node:\n", - " continue\n", - " \n", - " if memory_name in client.lrange(f\"{n}:memories\", 0, -1):\n", - " memory_exist = True\n", - " memory_node = n\n", + " if client.exists(f\"{mind_name}:memories:{memory_name}\"):\n", + " memory_dict = client.hgetall(f\"{mind_name}:memories:{memory_name}\")\n", "\n", - " break\n", + " if memory_dict[\"owner\"] != \"\":\n", + " #Solicita memória\n", + " pass\n", "\n", - " memory = cst.MemoryObject()\n", "\n", - " if memory_exist:\n", " #Copia memória\n", " print(\"Copia\")\n", "\n", - " memory_dict = client.hgetall(f\"memories:{memory_name}\")\n", + " memory_dict = client.hgetall(f\"{mind_name}:memories:{memory_name}\")\n", "\n", " memory.set_evaluation(float(memory_dict[\"evaluation\"]))\n", " memory.set_name(memory_dict[\"name\"])\n", @@ -170,7 +171,6 @@ " memory.set_info(info)\n", "\n", " memory.timestamp = float(memory_dict[\"timestamp\"])\n", - " \n", " else:\n", " #Indica que memória existe\n", " print(\"Cria\")\n", @@ -178,18 +178,19 @@ "\n", " memory_dict = MemoryEncoder.to_dict(memory)\n", " memory_dict[\"I\"] = json.dumps(memory_dict[\"I\"])\n", + " memory_dict[\"owner\"] = \"\" #node\n", "\n", - " client.hset(f\"memories:{memory_name}\", mapping=memory_dict)\n", + " client.hset(f\"{mind_name}:memories:{memory_name}\", mapping=memory_dict)\n", "\n", " subscribe_func = lambda message : update_memory(memory_name, memory, client)\n", - " pubsub.subscribe(**{f\"memories:{memory_name}:update\":subscribe_func})\n", + " pubsub.subscribe(**{f\"{mind_name}:memories:{memory_name}:update\":subscribe_func})\n", "\n", " return memory" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 30, "metadata": {}, "outputs": [ { @@ -206,7 +207,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -215,7 +216,7 @@ "MemoryObject [idmemoryobject=0.0, timestamp=0.0, evaluation=0.0, I=None, name=]" ] }, - "execution_count": 9, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } @@ -233,17 +234,17 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ - "client2 = redis.Redis()\n", + "client2 = redis.Redis(decode_responses=True)\n", "pubsub2 = client2.pubsub()" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 33, "metadata": {}, "outputs": [ { @@ -252,33 +253,33 @@ "2" ] }, - "execution_count": 11, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "client2.lpush(\"nodes\", \"node2\")" + "client2.lpush(f\"{mind_name}:nodes\", \"node2\")" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[b'node2', b'node1']" + "['node2', 'node1']" ] }, - "execution_count": 12, + "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "nodes = client2.lrange(\"nodes\", 0, -1)\n", + "nodes = client2.lrange(f\"{mind_name}:nodes\", 0, -1)\n", "nodes" ] }, @@ -291,14 +292,39 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'timestamp': '0.0',\n", + " 'evaluation': '0.0',\n", + " 'I': 'null',\n", + " 'name': '',\n", + " 'id': '0.0',\n", + " 'owner': ''}" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "client.hgetall(f\"{mind_name}:memories:memory1\")" + ] + }, + { + "cell_type": "code", + "execution_count": 36, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Cria\n" + "Copia\n" ] }, { @@ -307,7 +333,7 @@ "MemoryObject [idmemoryobject=0.0, timestamp=0.0, evaluation=0.0, I=None, name=]" ] }, - "execution_count": 13, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } @@ -320,7 +346,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 37, "metadata": {}, "outputs": [ { @@ -336,7 +362,7 @@ "MemoryObject [idmemoryobject=0.0, timestamp=0.0, evaluation=0.0, I=None, name=]" ] }, - "execution_count": 14, + "execution_count": 37, "metadata": {}, "output_type": "execute_result" } @@ -349,7 +375,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 38, "metadata": {}, "outputs": [ { @@ -367,17 +393,17 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 39, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'type': 'subscribe', 'pattern': None, 'channel': 'memories:memory1:update', 'data': 1}\n", + "{'type': 'subscribe', 'pattern': None, 'channel': 'default_mind:memories:memory1:update', 'data': 1}\n", "Retrieve update\n", - "{'type': 'subscribe', 'pattern': None, 'channel': b'memories:memory1:update', 'data': 1}\n", - "{'type': 'subscribe', 'pattern': None, 'channel': b'memories:memory2:update', 'data': 2}\n" + "{'type': 'subscribe', 'pattern': None, 'channel': 'default_mind:memories:memory1:update', 'data': 1}\n", + "{'type': 'subscribe', 'pattern': None, 'channel': 'default_mind:memories:memory2:update', 'data': 2}\n" ] } ], @@ -391,51 +417,32 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 40, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'timestamp': '1725053432.9742534',\n", + "{'timestamp': '1725638895.8791993',\n", " 'evaluation': '0.0',\n", " 'I': '\"INFO\"',\n", " 'name': '',\n", - " 'id': '0.0'}" + " 'id': '0.0',\n", + " 'owner': ''}" ] }, - "execution_count": 17, + "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "client.hgetall(\"memories:memory1\")" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "MemoryObject [idmemoryobject=0.0, timestamp=1725053432.9742534, evaluation=0.0, I=INFO, name=]" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "memory1" + "client.hgetall(f\"{mind_name}:memories:memory1\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 42, "metadata": {}, "outputs": [], "source": [] diff --git a/dev/memory_storage_codelet.ipynb b/dev/memory_storage_codelet.ipynb new file mode 100644 index 0000000..581e762 --- /dev/null +++ b/dev/memory_storage_codelet.ipynb @@ -0,0 +1,715 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "import weakref\n", + "import json\n", + "import asyncio\n", + "import threading\n", + "from concurrent.futures import ThreadPoolExecutor\n", + "from typing import Optional, cast, List\n", + "\n", + "import redis\n", + "\n", + "\n", + "import cst_python as cst\n", + "from cst_python.core.entities import Memory, Mind" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "client = redis.Redis(decode_responses=True)\n", + "client.flushall()" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "class MemoryEncoder(json.JSONEncoder):\n", + " def default(self, memory:cst.core.entities.Memory):\n", + " return MemoryEncoder.to_dict(memory)\n", + " \n", + " @staticmethod\n", + " def to_dict(memory:cst.core.entities.Memory):\n", + " data = {\n", + " \"timestamp\": memory.get_timestamp(),\n", + " \"evaluation\": memory.get_evaluation(),\n", + " \"I\": memory.get_info(),\n", + " \"name\": memory.get_name(),\n", + " \"id\": memory.get_id()\n", + " }\n", + "\n", + " return data" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "class MemoryStorageCodelet:\n", + " def __init__(self, mind:Mind, node_name:Optional[str]=None, mind_name:Optional[str]=None, request_timeout:float=500e-3) -> None:\n", + " self._mind = mind\n", + " self._request_timeout = request_timeout\n", + " \n", + " if mind_name is None:\n", + " mind_name = \"default_mind\"\n", + " self._mind_name = cast(str, mind_name)\n", + " \n", + " self._memories : weakref.WeakValueDictionary[str, Memory] = weakref.WeakValueDictionary()\n", + " \n", + " self._client = redis.Redis(decode_responses=True)\n", + " self._pubsub = self._client.pubsub()\n", + " self._pubsub_thread : redis.client.PubSubWorkerThread = self._pubsub.run_in_thread()\n", + "\n", + " if node_name is None:\n", + " node_number = self._client.scard(f\"{mind_name}:nodes\")\n", + "\n", + " node_name = f\"node{node_number}\"\n", + " while self._client.sismember(f\"{mind_name}:nodes\", node_name):\n", + " node_number += 1\n", + " node_name = f\"node{node_number}\"\n", + "\n", + " self._node_name = cast(str, node_name)\n", + "\n", + " self._client.sadd(f\"{mind_name}:nodes\", node_name)\n", + "\n", + " transfer_service_addr = f\"{self._mind_name}:nodes:{node_name}:transfer_memory\"\n", + " self._pubsub.subscribe(**{transfer_service_addr:self.transfer_memory})\n", + "\n", + " transfer_done_addr = f\"{self._mind_name}:nodes:{node_name}:transfer_done\"\n", + " self._pubsub.subscribe(**{transfer_done_addr:self.notify_transfer})\n", + "\n", + " self._last_update : dict[str, float] = {}\n", + " self._waiting_retrieve : set[str] = set()\n", + " \n", + " self._retrieve_executor = ThreadPoolExecutor(3)\n", + "\n", + " self._waiting_request_events : dict[str, threading.Event] = {}\n", + "\n", + " self._request = None\n", + "\n", + " def proc(self) -> None:\n", + " \n", + " #Check new memories\n", + "\n", + " mind_memories = {}\n", + " for memory in self._mind.raw_memory.all_memories:\n", + " if memory.get_name() == \"\": #No name -> No MS\n", + " continue\n", + "\n", + " mind_memories[memory.get_name()] = memory\n", + "\n", + " mind_memories_names = set(mind_memories.keys())\n", + " memories_names = set(self._memories.keys())\n", + "\n", + " #Check only not here (memories_names not in mind should be garbage collected)\n", + " difference = mind_memories_names - memories_names\n", + " for memory_name in difference:\n", + " memory : Memory = mind_memories[memory_name]\n", + " self._memories[memory_name] = memory\n", + "\n", + " if self._client.exists(f\"{self._mind_name}:memories:{memory_name}\"):\n", + " self._retrieve_executor.submit(self.retrieve_memory, memory)\n", + " \n", + " else: #Send impostor with owner\n", + " memory_impostor = {\"name\":memory.get_name(),\n", + " \"evalution\" : 0.0,\n", + " \"I\": \"\",\n", + " \"id\" : \"0.0\",\n", + " \"owner\": self._node_name}\n", + " \n", + " self._client.hset(f\"{self._mind_name}:memories:{memory_name}\", mapping=memory_impostor)\n", + "\n", + " subscribe_func = lambda message : self.update_memory(memory_name)\n", + " self._pubsub.subscribe(**{f\"{self._mind_name}:memories:{memory_name}:update\":subscribe_func})\n", + "\n", + " #Update memories\n", + " to_update = self._last_update.keys()\n", + " for memory_name in to_update:\n", + " if memory_name not in self._memories:\n", + " del self._last_update[memory_name]\n", + " continue\n", + "\n", + " memory = self._memories[memory_name]\n", + " if memory.get_timestamp() > self._last_update[memory_name]:\n", + " self.update_memory(memory_name)\n", + "\n", + " def transfer_memory(self, message) -> None:\n", + " request = json.loads(message[\"data\"])\n", + " \n", + " memory_name = request[\"memory_name\"]\n", + " requesting_node = request[\"node\"]\n", + "\n", + " print(self._node_name, \"Tranfering\", memory_name)\n", + "\n", + " if memory_name in self._memories:\n", + " memory = self._memories[memory_name]\n", + " else:\n", + " memory = cst.MemoryObject()\n", + " memory.set_name(memory_name)\n", + " \n", + " self.send_memory(memory)\n", + "\n", + " response_addr = f\"{self._mind_name}:nodes:{requesting_node}:transfer_done\"\n", + " self._client.publish(response_addr, memory_name)\n", + "\n", + "\n", + " def send_memory(self, memory:Memory) -> None:\n", + " memory_name = memory.get_name()\n", + " print(self._node_name, \"Send memory\", memory_name)\n", + " \n", + " memory_dict = MemoryEncoder.to_dict(memory)\n", + " memory_dict[\"I\"] = json.dumps(memory_dict[\"I\"])\n", + " memory_dict[\"owner\"] = \"\"\n", + "\n", + "\n", + " self._client.hset(f\"{self._mind_name}:memories:{memory_name}\", mapping=memory_dict)\n", + " self._client.publish(f\"{self._mind_name}:memories:{memory_name}:update\", \"\")\n", + "\n", + " self._last_update[memory_name] = memory.get_timestamp()\n", + " \n", + " def update_memory(self, memory_name:str) -> None:\n", + " print(self._node_name, \"Updating memory\", memory_name)\n", + "\n", + " timestamp = float(self._client.hget(f\"{self._mind_name}:memories:{memory_name}\", \"timestamp\"))\n", + " memory = self._memories[memory_name]\n", + " memory_timestamp = memory.get_timestamp()\n", + " \n", + " if memory_timestamp < timestamp:\n", + " self._retrieve_executor.submit(self.retrieve_memory, memory)\n", + "\n", + " elif memory_timestamp> timestamp:\n", + " self.send_memory(memory)\n", + "\n", + " self._last_update[memory_name] = memory.get_timestamp()\n", + "\n", + " def retrieve_memory(self, memory:Memory) -> None:\n", + " memory_name = memory.get_name()\n", + "\n", + " print(self._node_name, \"Retrieve\", memory_name)\n", + "\n", + " if memory_name in self._waiting_retrieve:\n", + " return\n", + " self._waiting_retrieve.add(memory_name)\n", + "\n", + " memory_dict = self._client.hgetall(f\"{self._mind_name}:memories:{memory_name}\")\n", + "\n", + " if memory_dict[\"owner\"] != \"\":\n", + " event = threading.Event()\n", + " self._waiting_request_events[memory_name] = event\n", + " self.request_memory(memory_name, memory_dict[\"owner\"])\n", + "\n", + " if not event.wait(timeout=self._request_timeout):\n", + " print(self._node_name, \"Request failed\", memory_name)\n", + " #Request failed\n", + " self.send_memory(memory)\n", + " return \n", + " \n", + " memory_dict = self._client.hgetall(f\"{self._mind_name}:memories:{memory_name}\")\n", + "\n", + " memory.set_evaluation(float(memory_dict[\"evaluation\"]))\n", + " memory.set_id(float(memory_dict[\"id\"]))\n", + "\n", + " info_json = memory_dict[\"I\"]\n", + " info = json.loads(info_json)\n", + "\n", + " print(self._node_name, \"INFO\", info, info_json)\n", + "\n", + " memory.set_info(info)\n", + "\n", + " self._last_update[memory_name] = memory.get_timestamp()\n", + "\n", + " self._waiting_retrieve.remove(memory_name)\n", + "\n", + " def request_memory(self, memory_name:str, owner_name:str):\n", + " print(self._node_name, \"Requesting\", memory_name)\n", + "\n", + " request_addr = f\"{self._mind_name}:nodes:{owner_name}:transfer_memory\"\n", + " \n", + " request_dict = {\"memory_name\":memory_name, \"node\":self._node_name}\n", + " request = json.dumps(request_dict)\n", + " self._client.publish(request_addr, request)\n", + "\n", + " def notify_transfer(self, message:str) -> None:\n", + " memory_name = message[\"data\"]\n", + " if memory_name in self._waiting_request_events:\n", + " event = self._waiting_request_events[memory_name]\n", + " event.set()\n", + " del self._waiting_request_events[memory_name]\n", + "\n", + " def __del__(self) -> None:\n", + " self._pubsub_thread.stop()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "mind = cst.Mind()\n", + "memory1 = mind.create_memory_object(\"Memory1\", \"\")" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "ms_codelet = MemoryStorageCodelet(mind, \"node0\")" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "ms_codelet.proc()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'node0'}" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "client.smembers(\"default_mind:nodes\")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'name': 'Memory1', 'evalution': '0.0', 'I': '', 'id': '0.0', 'owner': 'node0'}" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "client.hgetall(\"default_mind:memories:Memory1\")" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "mind2 = cst.Mind()\n", + "mind2_memory1 = mind2.create_memory_object(\"Memory1\", \"\")\n", + "mind2_ms_codelet = MemoryStorageCodelet(mind2)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "MemoryObject [idmemoryobject=0, timestamp=1725654264.298408, evaluation=0.0, I=, name=Memory1]" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mind2_memory1" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'node1'" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mind2_ms_codelet._node_name" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'node0', 'node1'}" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "client.smembers(\"default_mind:nodes\")" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "node1 Retrieve Memory1\n", + "node1 Requesting Memory1\n", + "node0 Tranfering Memory1\n", + "node0 Send memory Memory1\n" + ] + } + ], + "source": [ + "mind2_ms_codelet.proc()" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "node1 Updating memory Memory1\n", + "node0 Updating memory Memory1\n", + "node1 Send memory Memory1\n", + "node0 Updating memory Memory1\n", + "node1 Updating memory Memory1\n", + "node0 Retrieve Memory1\n", + "node0 INFO \"\"\n", + "node1 INFO \"\"\n" + ] + }, + { + "data": { + "text/plain": [ + "MemoryObject [idmemoryobject=0.0, timestamp=1725654264.7690487, evaluation=0.0, I=, name=Memory1]" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mind2_memory1" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'name': 'Memory1',\n", + " 'evalution': '0.0',\n", + " 'I': '\"\"',\n", + " 'id': '0',\n", + " 'owner': '',\n", + " 'timestamp': '1725654264.298408',\n", + " 'evaluation': '0.0'}" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "client.hgetall(\"default_mind:memories:Memory1\")" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-1" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "memory1.set_info(\"INFO\")" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "node0 Updating memory Memory1\n", + "node0 Send memory Memory1\n", + "node1 Updating memory Memory1\n", + "node0 Updating memory Memory1\n", + "node1 Retrieve Memory1\n" + ] + } + ], + "source": [ + "ms_codelet.proc()" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "node1 INFO INFO \"INFO\"\n" + ] + }, + { + "data": { + "text/plain": [ + "{'name': 'Memory1',\n", + " 'evalution': '0.0',\n", + " 'I': '\"INFO\"',\n", + " 'id': '0.0',\n", + " 'owner': '',\n", + " 'timestamp': '1725654264.794752',\n", + " 'evaluation': '0.0'}" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "client.hgetall(\"default_mind:memories:Memory1\")" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "MemoryObject [idmemoryobject=0.0, timestamp=1725654264.8138657, evaluation=0.0, I=INFO, name=Memory1]" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mind2_memory1" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [], + "source": [ + "mind2_ms_codelet.proc()" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'name': 'Memory1',\n", + " 'evalution': '0.0',\n", + " 'I': '\"INFO\"',\n", + " 'id': '0.0',\n", + " 'owner': '',\n", + " 'timestamp': '1725654264.794752',\n", + " 'evaluation': '0.0'}" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "client.hgetall(\"default_mind:memories:Memory1\")" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "node1 Updating memory Memory1\n", + "node1 Send memory Memory1\n", + "node0 Updating memory Memory1\n", + "node1 Updating memory Memory1\n", + "node0 Retrieve Memory1\n", + "node0 INFO INFO2 \"INFO2\"\n" + ] + } + ], + "source": [ + "mind2_memory1.set_info(\"INFO2\")\n", + "mind2_ms_codelet.proc()" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'name': 'Memory1',\n", + " 'evalution': '0.0',\n", + " 'I': '\"INFO2\"',\n", + " 'id': '0.0',\n", + " 'owner': '',\n", + " 'timestamp': '1725654302.9360394',\n", + " 'evaluation': '0.0'}" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "client.hgetall(\"default_mind:memories:Memory1\")" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "MemoryObject [idmemoryobject=0.0, timestamp=1725654302.943039, evaluation=0.0, I=INFO2, name=Memory1]" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "memory1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.9" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}