def loadModule(self, name, filename): if lua is None: return None lua.globals().package.loaded[name] = None CurrentDir = os.getcwd() os.chdir('quirks') try: return lua.require(name) except Error as e: print(e) return None finally: os.chdir(CurrentDir)
def loadModule(self, name, filename): if lua is None: return None lua.globals().package.loaded[name] = None CurrentDir = os.getcwd() os.chdir('quirks') try: return lua.require(name) except Error as e: logging.error(e) return None finally: os.chdir(CurrentDir)
print "----- import lua -----" import lua print "----- lg = lua.globals() -----" lg = lua.globals() print "lg:", lg print "lg._G:", lg._G print "lg['_G']:", lg['_G'] print "----- lg.foo = \"bar\" -----" lg.foo = 'bar' print "----- lg.tmp = [] -----" lg.tmp = [] print "----- print lg.tmp -----" print lg.tmp print "----- lua.execute(\"xxx = {1,2,3,foo={4,5}}\") -----" lua.execute("xxx = {1,2,3,foo={4,5}}") print "----- print lg.xxx[1] -----" print lg.xxx[1] print "----- print lg.xxx[2] -----" print lg.xxx[2] print "----- print lg.xxx[3] -----" print lg.xxx[3] print "----- print lg.xxx['foo'][1] -----" print lg.xxx['foo'][1] print "lua.require =", lua.require try: lua.require("foo") except: print "lua.require('foo') raised an exception"
import lua from vizdoom import * from random import choice from time import sleep from time import time import itertools as it import cv2 import numpy as np import argparse import sys from opencv.cv import * from opencv.highgui import * torch = lua.require('torch') lua.require('trepl') lua.require('cunn') # We run the network on GPU dqn = lua.eval("dofile('dqn/NeuralQLearner.lua')") tt = lua.eval("dofile('dqn/TransitionTable.lua')") #lua.execute("dofile('dqn/Scale.lua')") # for the preproc spectator_action_mapping = { 1 : [0,0,0,0,0,0,0,0,0] , 2 : [1,0,0,0,0,0,0,0,0] , 3 : [0,0,0,0,1,0,0,0,0] , 4 : [0,0,0,0,0,1,0,0,0] , 5 : [0,0,0,0,0,0,1,0,0] , 6 : [0,0,0,0,0,0,0,1,0] , 7 : [0,0,0,0,0,0,0,0,1] , 8 : [0,0,0,0,0,1,0,1,0] ,
def style(rule): colour = lua.eval("%s.Colour" % rule) boldQ = lua.eval("%s.Bold" % rule) bold = r"\bfseries" if boldQ else "" return color(colour) + bold if __name__ == "__main__": print consts.common_style for theme in os.listdir(consts.THEMES_DIR): lua.require(theme) name = consts.theme_name(theme) styles = { "name": name, "backgroundcolor": style("Canvas"), "basicstyle": style("Default"), "identifierstyle": style("Keywords[2]"), "commentstyle": style("BlockComment"), "stringstyle": style("String"), "keywordstyle": style("Keywords[1]"), "procnamestyle": style("Keywords[4]"), } print consts.listings_style % styles
import numpy as np import random import time import math from tqdm import tqdm import sys, DLFCN sys.setdlopenflags(DLFCN.RTLD_NOW | DLFCN.RTLD_GLOBAL) import lua lua.require('xlua') Brain = lua.require("deepql_model/deepqlearn") from game256 import * ####### LUA & PYTHON for learning Game 2048 with Deep Reinforcement Learning ####### __author__ = 'Wonjun' # params # num_of_train = 100000 num_actions = 4 num_states = 192 Brain.init(num_states, num_actions) Brain.load("inf_model_256.net") #print "temp_window ", Brain.temporal_window # Manipulating params of Nets # Brain.start_learn_threshold = 2000 Brain.learning_steps_total = 100000 Brain.learning_steps_burnin = 2000 Brain.gamma = 0.95 actions = ['H','P','K','M'] #Brain.age = 1
import gym import lua import numpy as np torch = lua.require('torch') lua.require('trepl') lua.require('cunn') # We run the network on GPU dqn = lua.eval("dofile('dqn/NeuralQLearner.lua')") tt = lua.eval("dofile('dqn/TransitionTable.lua')") lua.execute("dofile('dqn/Scale.lua')") # for the preproc env = gym.make('Breakout-v0') possible_actions = lua.toTable({ 1: 0, 2: 2, 3: 3, 4: 1 }) agent = torch.load("out/net-10000.t7") agent.bestq = 0 observation = env.reset() action_index = 4 done = False t=1 while True: t += 1 env.render() observation, reward, done, info = env.step(possible_actions[action_index])
# This is a simple interface to the prosody XMPP server and presently takes care of simple use cases like # creation, deletion of accounts. It should be used in further development to change the server if required! # Note that this script should be run with privellages that can allow prosody databases to be accessed. # If you are not sure enough, use sudo/root privellages( is that a stiable idea ? ) # Import the Lunatic Python, Lua-Python, interpolability module import lua # Import the Lua side of API lua.require('prosody_api') # Import types module for assertion reasoning import types class XMPPApi: def isUser(self, uname, host): # Check if we have got valid strings assert ( type(uname) == types.StringType ) and ( type(host) == types.StringType ) # Evaluate the function from the prosody API pro_isUser = '******'+uname+'","'+host+'")' return lua.eval(pro_isUser) def createUser(self, uname, passwd, host):
def loadModule(self, name, filename): if lua is None: return None fullname = os.path.join('quirks', name) lua.globals().package.loaded[fullname] = None return lua.require(fullname)
from random import choice from time import sleep from time import time import itertools as it #changes made import lua import numpy as np torch = lua.require('torch') lua.require('trepl') dqn = lua.eval("dofile('dqn/NeuralQLearner.lua')") tt = lua.eval("dofile('dqn/TransitionTable.lua')") # Create DoomGame instance. It will run the game and communicate with you. game = DoomGame() screen_width = 320 screen_height = 240 color_palette = 24 # Now it's time for configuration! # load_config could be used to load configuration instead of doing it here with code. # If load_config is used in-code configuration will work. Note that the most recent changes will add to previous ones.