Skip to content

Commit

Permalink
Fix deprecations, switch to NARpyn
Browse files Browse the repository at this point in the history
  • Loading branch information
ntoxeg committed Jul 11, 2023
1 parent e99a4e7 commit 96ccf42
Show file tree
Hide file tree
Showing 20 changed files with 115 additions and 298 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ This repository hosts both a library that facilitates interfacing OpenNARS for A
a bunch of experiments using Griddly.

## Installation
You need to have OpenNARS-For-Applications installed somewhere. It is expected that you will export a `NARS_HOME` environment
variable to specify where it is built.

The recommended way to install dependencies is with Poetry: `poetry install`. `poetry shell` will open a shell with the virtual environment activated.

Additionally, dependencies are listed in the `env.yml` file, that can be used to create a Conda environment (might be outdated).
`lock.yml` is a lock-file that you can use to make a reproducible environment, Conda might fail to create it though.

[Griddly](https://github.com/Bam4d/Griddly) requires to install Vulkan SDK, refer to its README.

Install in editable mode to your environment: `pip install -e .`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import griddly # noqa
import gym
import neptune.new as neptune
import neptune
from griddly import gd
from narpyn.ona.nar import *

from narca.agent import Runner
from narca.drunk_dwarf import DrunkDwarfAgent
from narca.nar import *
from narca.utils import *

# setup a logger for nars output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import griddly # noqa
import gym
import neptune.new as neptune
import neptune
from griddly import gd
from narpyn.ona.nar import *

from narca.agent import Runner
from narca.drunk_dwarf import DrunkDwarfAgent
from narca.nar import *
from narca.utils import *

# setup a logger for nars output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import griddly # noqa
import gym
import neptune.new as neptune
import neptune
from griddly import gd
from narpyn.ona.nar import *

from narca.agent import Runner
from narca.drunk_dwarf import DrunkDwarfAgent
from narca.nar import *
from narca.utils import *

# setup a logger for nars output
Expand Down
2 changes: 1 addition & 1 deletion experiments/drunk_dwarf/demonstrate/drunk_dwarf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import griddly # noqa
import gym
from griddly import gd
from narpyn.ona.nar import *

from narca.agent import Runner
from narca.drunk_dwarf import DrunkDwarfAgent
from narca.nar import *
from narca.utils import *

# setup a logger for nars output
Expand Down
4 changes: 2 additions & 2 deletions experiments/drunk_dwarf/extended_curriculum/drunk_dwarf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import griddly # noqa
import gym
import neptune.new as neptune
import neptune
from griddly import GymWrapperFactory, gd
from narpyn.ona.nar import *

from narca.agent import Runner
from narca.drunk_dwarf import DrunkDwarfAgent
from narca.nar import *
from narca.utils import *

# setup a logger for nars output
Expand Down
8 changes: 4 additions & 4 deletions experiments/drunk_dwarf/main/drunk_dwarf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

import gym
import hyperstate
import neptune.new as neptune
import neptune
from griddly import gd
from narpyn.ona.nar import *

from narca.agent import Runner
from narca.drunk_dwarf import DrunkDwarfAgent
from narca.nar import *
from narca.utils import *

# setup a logger for nars output
Expand Down Expand Up @@ -54,7 +54,7 @@ def key_check(_, info) -> bool:
logger.info("Run configuration: %s", config)

neprun = (
neptune.init(
neptune.init_run(
project=os.environ["NEPTUNE_PROJECT"],
tags=[ENV_NAME, MAIN_TAG, f"difficulty:{config.difficulty_level}"],
)
Expand Down Expand Up @@ -128,7 +128,7 @@ def key_check(_, info) -> bool:
callbacks = []
if neprun is not None:
neprun["parameters"] = {
"goals": [g.symbol for g in goals],
"goals": str([g.symbol for g in goals]),
"think_ticks": config.agent.think_ticks,
"view_radius": config.agent.view_radius,
"num_episodes": config.num_episodes,
Expand Down
4 changes: 2 additions & 2 deletions experiments/drunk_dwarf/main/random_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

import griddly # noqa
import gym
import neptune.new as neptune
import neptune
from griddly import gd
from narpyn.ona.nar import *

from narca.drunk_dwarf import DrunkDwarfRandom
from narca.nar import *
from narca.utils import *

# setup a logger for nars output
Expand Down
2 changes: 1 addition & 1 deletion experiments/zelda/demonstrate/nars_zelda.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import gym
import pexpect
from griddly import gd
from narpyn.ona.nar import *

from narca.nar import *
from narca.utils import *
from narca.zelda import Runner, ZeldaAgent, ZeldaLevelGenerator

Expand Down
4 changes: 2 additions & 2 deletions experiments/zelda/main/nars_zelda.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import griddly # noqa
import gym
import neptune.new as neptune
import neptune
from griddly import gd
from narpyn.ona.nar import *

from narca.agent import Runner
from narca.nar import *
from narca.utils import *
from narca.zelda import ZeldaAgent

Expand Down
2 changes: 1 addition & 1 deletion experiments/zelda/procgen/nars_zelda.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import gym
import pexpect
from griddly import gd
from narpyn.ona.nar import *

from narca.nar import *
from narca.utils import *
from narca.zelda import Runner, ZeldaAgent, ZeldaLevelGenerator

Expand Down
4 changes: 2 additions & 2 deletions narca/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import numpy as np
from griddly import gd
from griddly.util.rllib.environment.level_generator import LevelGenerator
from narpyn.ona.nar import get_raw_output, send_input, setup_nars
from narpyn.ona.narsese import Goal, nal_now
from tensorboardX import SummaryWriter

from .nar import get_raw_output, send_input, setup_nars
from .narsese import Goal, nal_now
from .utils import NARS_PATH


Expand Down
27 changes: 15 additions & 12 deletions narca/drunk_dwarf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import gym
import numpy as np
from narpyn.ona.nar import *

from .agent import Agent, NarsAgent
from .astar import pathfind
from .nar import *
from .utils import *


Expand Down Expand Up @@ -227,19 +227,19 @@ def obj_label(obj_type: str, obloc: tuple[int, int]) -> Optional[str]:
]
)

obj_concurrent_belief = (
f"({obj_labels[0]} &| {obj_labels[1]})"
if len(obj_labels) > 1
else obj_labels[0]
)
if len(obj_labels) > 2:
for i in range(2, len(obj_labels)):
obj_concurrent_belief = f"({obj_concurrent_belief} &| {obj_labels[i]})"
# obj_concurrent_belief = (
# f"({obj_labels[0]} &| {obj_labels[1]})"
# if len(obj_labels) > 1
# else obj_labels[0]
# )
# if len(obj_labels) > 2:
# for i in range(2, len(obj_labels)):
# obj_concurrent_belief = f"({obj_concurrent_belief} &| {obj_labels[i]})"

# nal_now("<" + " &| ".join(obj_labels) + ">")
# ic(obj_concurrent_belief)
self._send_beliefs([nal_now(obj_concurrent_belief)])
num_sent_beliefs += 1
# self._send_beliefs([nal_now(obj_concurrent_belief)])
# num_sent_beliefs += 1

# try:
# avatar = next(
Expand Down Expand Up @@ -301,10 +301,13 @@ def obj_label(obj_type: str, obloc: tuple[int, int]) -> Optional[str]:

# num_sent_beliefs += len(pos_beliefs) + len(diff_beliefs)
# self._send_beliefs(pos_beliefs + diff_beliefs)
blfs = [nal_now(obj) for obj in obj_labels]
self._send_beliefs(blfs)
num_sent_beliefs = len(blfs)
# ic("Sent pos beliefs:", pos_beliefs)
# ic("Sent diff beliefs:", diff_beliefs)
ic("Total beliefs sent:", num_sent_beliefs)
# sleep(1)
sleep(1)


class DrunkDwarfRandom(Agent):
Expand Down
119 changes: 0 additions & 119 deletions narca/nar.py

This file was deleted.

Loading

0 comments on commit 96ccf42

Please sign in to comment.