Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from distutils.core import setup
from Cython.Build import cythonize

setup(
ext_modules = cythonize("src/process.pyx")
)
25 changes: 0 additions & 25 deletions solver_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
help="game to solve for"
)

parser.add_argument(
"--debug",
help="Enables or disables logging",
action="store_true"
)

parser.add_argument(
"-sd",
"--statsdir",
Expand All @@ -29,14 +23,6 @@

comm = MPI.COMM_WORLD

# May be later modified for debugging purposes.
# Because comm.send is read only we need to make a
# new variable.

isend = comm.isend
recv = comm.recv
abort = comm.Abort

# Load file and give it to each process.
game_module = imp.load_source('game_module', args.game_file)
src.utils.game_module = game_module
Expand All @@ -49,7 +35,6 @@
from src.game_state import GameState # NOQA
from src.job import Job # NOQA
from src.process import Process # NOQA
import src.debug # NOQA


def validate(mod):
Expand All @@ -64,22 +49,12 @@ def validate(mod):

# Make sure the game is properly defined
validate(src.utils.game_module)
# For debugging with heapy.
if args.debug:
src.debug.init_debug(comm.Get_rank())
isend = src.debug.debug_send(comm.isend)
recv = src.debug.debug_recv(comm.recv)
abort = src.debug.debug_abort(comm.Abort)

initial_position = src.utils.game_module.initial_position()

process = Process(
comm.Get_rank(),
comm.Get_size(),
comm,
isend,
recv,
abort,
stats_dir=args.statsdir
)

Expand Down
66 changes: 12 additions & 54 deletions src/cache_dict.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
import shelve

from cachetools import LRUCache
from cachetools import RRCache


class CacheDict:
Expand All @@ -13,67 +11,27 @@ class CacheDict:

__slots__ = ['_file_dict', '_cache']

def __len__(self):
return len(self._file_dict)

def _prepare_path(self, directory, rank, t="stats"):
"""
Helper function. Takes a directory and makes sure
the directory plays nice with the other functions
that require it.
"""
if directory is None:
directory = ''
else:
if directory[-1] != '/':
directory = directory + '/'
directory = directory + t + '/' + str(rank) + '/'
try:
os.makedirs(directory)
except OSError: # File exists.
pass

return directory

def __init__(self, name, directory, rank, max_size=100, t="stats"):
self._file_dict = shelve.open(
self._prepare_path(directory, rank, t=t) + name
)
self._cache = LRUCache(maxsize=max_size)
def __init__(self, name, max_size=2000):
self._file_dict = shelve.open(name)
self._cache = RRCache(maxsize=max_size)

def __getitem__(self, key):
try:
# Need the additional step in case of KeyError
if isinstance(key, int):
return self._cache[str(key)]
else:
return self._cache[key]
return self._cache[str(key)]
except KeyError:
# Need the additional step in case of KeyError
if isinstance(key, int):
item = self._file_dict[str(key)]
self._cache[str(key)] = item
return item
else:
item = self._file_dict[key]
self._cache[key] = item
return item
item = self._file_dict[str(key)]
self._cache[str(key)] = item
return item

def __setitem__(self, key, value):
if isinstance(key, int):
self._file_dict[str(key)] = value
self._cache[str(key)] = value
else:
self._file_dict[key] = value
self._cache[key] = value
self._file_dict[str(key)] = value
self._cache[str(key)] = value

def __delitem__(self, key):
if isinstance(key, int):
del self._file_dict[str(key)]
del self._cache[str(key)]
else:
del self._file_dict[str(key)]
del self._cache[str(key)]
del self._file_dict[str(key)]
del self._cache[str(key)]

def __contains__(self, item):
return item in self._file_dict
42 changes: 0 additions & 42 deletions src/debug.py

This file was deleted.

1 change: 0 additions & 1 deletion src/game_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def primitive(self):
"""
return game_module.primitive(self.pos)

@property
def to_remote_tuple(self):
"""
Converts the given GameState object to a (state, remote)
Expand Down
Loading