Exemple #1
0
def load_exec(path):
    with open(path, 'rb') as f:
        # TODO implement an actual binary format
        for key, value in pickle.load(f):
            key = (Constant(key[0]), key[1])
            if key[0] == Constant.SYMBOL:
                value = (Constant(value[0]), value[1])
            elif key[0] == Constant.CODE and len(value) == 2:
                value = tuple(value) + (dict(), )  # Auto-upgrade
            elif key[0] == Constant.CODE:
                value = (value[0], value[1], dict(value[2]))
            yield (key, value)
Exemple #2
0
    def check_term_valid(self, term):
        """ Check if term is syntax and semantic valid

        Term include 'const', '*', '/'

        return : 
                True, value of term if 'term' is valid
                False, None         if 'term' is not valid
        """

        term_stars = term.split("*")
        # IF term is const
        if (len(term_stars) == 1):  # term == const
            term_value = term_stars[0]
            is_constant = Constant().check_constant_valid(term_value)
            if is_constant == False:
                return False, None
            else:
                return True, term_value

        # IF term is not const
        for term_star_idx in range(len(term_stars)):
            term_star = term_stars[term_star_idx]
            term_splashes = term_star.split("/")

            for term_splash_idx in range(len(term_splashes)):
                # Check syntax
                term_splash = term_splashes[term_splash_idx]
                if (Constant().check_constant_valid(term_splash) == False):
                    return False, None
                else:
                    # Check if term_splash must be a number
                    try:
                        term_splash = float(term_splash)
                    except:
                        return False, None

                # Check semantic
                if (term_splash_idx == 0):
                    term_star_value = term_splash
                else:
                    term_star_value = term_star_value / term_splash

            # Check semantic
            if (term_star_idx == 0):
                term_value = term_star_value
            else:
                term_value = term_value * term_star_value

        return True, term_value
Exemple #3
0
def send_mail_to_user(reciever_email, confirmation_url):
    cons = Constant()
    sendgrid_object = sendgrid.SendGridAPIClient(apikey=cons.sendgrid_API_key)
    data = {
        "personalizations": [
            {
                "to": [
                    {
                        "email": reciever_email
                    }
                ],
                "subject": "Confirm account"
            }
        ],
        "from": {
            "email": "*****@*****.**",
            "name": "Svoop"
        },
        "content": [
            {
                "type": "text/html",
                "value": cons.email_template(confirmation_url)
            }
        ]
    }
    response = sendgrid_object.client.mail.send.post(request_body=data)
Exemple #4
0
    def __init__(self):
        """ Inicializa los scopes de las variables : Temporales, Globales,
		Locales y Constantes.
		"""
        self.tmp = Temporal()
        self.glob = Globs()
        self.loc = Local()
        self.const = Constant()
        self.max_memory = 20000
        self.current_used_memory = 0
    def __init__(self, memoryFile):
        self.nCycles = 0  # Used to hold number of clock cycles spent executing instructions

        self.dataMemory = DataMemory(memoryFile)
        self.instructionMemory = InstructionMemory(memoryFile)
        self.registerFile = RegisterFile()

        self.constant3 = Constant(3)
        self.constant4 = Constant(4)
        self.randomControl = RandomControl()
        self.mux = Mux()
        self.adder = Add()
        self.pc = PC(0xbfc00000)  # hard coded "boot" address

        self.elements = [
            self.constant3, self.constant4, self.randomControl, self.adder,
            self.mux
        ]

        self._connectCPUElements()
Exemple #6
0
def main():
    symbol_table = SymbolTable()

    v1 = Identifier('a', 5)
    v2 = Identifier('b', 7)
    v3 = Identifier('c', 12)
    v4 = Identifier('a', 14)
    c1 = Constant('d', 7)

    symbol_table.add(v1)
    symbol_table.add(v2)
    symbol_table.add(v3)
    symbol_table.add(c1)
    symbol_table.add(v4)

    v2.set_value(42)
    symbol_table.add(v2)

    c2 = Constant('c', 17)
    symbol_table.add(c2)

    symbol_table.print_symbol_table()
Exemple #7
0
	def __init__(self, memoryFile):
		self.nCycles = 0 # Used to hold number of clock cycles spent executing instructions

		# Fetch
		self.PCMux	  = Mux()
		self.ProgramC   = PC(long(0xbfc00200))
		self.InstMem	= InstructionMemory(memoryFile)
		self.IFadder	= Add()
		self.JMux	   = Mux()
		self.IFaddconst = Constant(4)
		self.IF_ID_Wall = Wall()
		self.fetchgroup = {}

		# Decode
		self.register   = RegisterFile()
		self.signext	= SignExtender()
		self.control	= ControlElement()
		self.jmpCalc	= JumpCalc()
		self.ID_EX_Wall = Wall()

		# Execute
		self.EXadder	= Add()
		self.shiftL	 = LeftShifter()
		self.ALogicUnit = ALU()
		self.ALUSrcMux  = Mux()
		self.RegDstMux  = Mux()
		self.ALUctrl	= AluControl()
		self.EX_MEM_Wall= Wall()

		# Memory
		self.storage	= DataMemory(memoryFile)
		self.brnch	  = Branch()
		self.MEM_WB_Wall= Wall()

		# Write Back
		self.WBmux = Mux()

		self.ProgramC
		self.elements1 = [self.InstMem, self.IFaddconst, self.IFadder, self.PCMux, self.JMux]
		self.elements2 = [self.control, self.register, self.signext, self.jmpCalc]
		self.elements3 = [self.shiftL, self.ALUSrcMux, self.RegDstMux, self.ALUctrl, self.ALogicUnit, self.EXadder]
		self.elements4 = [self.brnch, self.storage]
		self.elementsboot = [self.IFaddconst, self.IFadder, self.InstMem,
							 self.IF_ID_Wall, self.register, self.signext, self.control, self.jmpCalc,
							 self.ID_EX_Wall, self.RegDstMux, self.shiftL, self.EXadder, self.ALUSrcMux, self.ALUctrl, self.ALogicUnit,
							 self.EX_MEM_Wall, self.brnch, self.storage,
							 self.MEM_WB_Wall, self.WBmux, self.PCMux, self.JMux]
		self.walls = [self.MEM_WB_Wall, self.EX_MEM_Wall, self.ID_EX_Wall, self.IF_ID_Wall]


		self._connectCPUElements()
Exemple #8
0
def main_menu():
    global screen
    cons = Constant()
    menu_song = pygame.mixer.music.load(path.join(sound_folder, "menu.mp3"))
    pygame.mixer.music.set_volume(5)
    pygame.mixer.music.play(-1)

    title = pygame.image.load(path.join(img_dir, "main.jpg")).convert()
    title = pygame.transform.scale(title, (cons.WIDTH, cons.HEIGHT), screen)

    screen.blit(title, (0,0))
    draw_text(screen, "School Battle", 72, cons.WIDTH/2, cons.HEIGHT/2 - 80, cons.BLACK)
    pygame.display.update()

    while True:
        ev = pygame.event.poll()
        if ev.type == pygame.KEYDOWN:
            if ev.key == pygame.K_RETURN:
                break
            elif ev.key == pygame.K_q:
                pygame.quit()
                quit()
        elif ev.type == pygame.QUIT:
                pygame.quit()
                quit() 
        else:
            draw_text(screen, "Press [ENTER] To Begin", 30, cons.WIDTH/2, cons.HEIGHT/2, cons.BLACK)
            draw_text(screen, "or [Q] To Quit", 30, cons.WIDTH/2, (cons.HEIGHT/2)+40, cons.BLACK)
            draw_text(screen, "Press [SPACE] To Shoot", 30, cons.WIDTH/2, cons.HEIGHT/2 + 80, cons.BLACK)
            pygame.display.update()

    # Hide the mouse cursor.
    pygame.mouse.set_visible(False)

    screen.fill(cons.BLACK)
    screen.blit(background, background_rect)
    draw_text(screen, "GET READY!", 40, cons.WIDTH/2, cons.HEIGHT/2, cons.BLACK)
    pygame.display.update()
    pygame.event.pump()
    pygame.time.wait(1000)
    for i in range(3):
        screen.fill(cons.BLACK)
        screen.blit(background, background_rect)
        draw_text(screen, str(3 - i), 40, cons.WIDTH/2, cons.HEIGHT/2, cons.BLACK)
        pygame.display.update()
        pygame.event.pump()
        pygame.time.wait(1000)
Exemple #9
0
  def __init__(self, memoryFile):
    self.nCycles = 0 # Used to hold number of clock cycles spent executing instructions
    
    self.adder              = Add()
    self.branchAdder        = Add()
    self.alu                = Alu()
    self.aluControl         = AluControl()
    self.branchNE           = BranchNotEqual()
    self.branch             = Branch()
    self.constant           = Constant(4)
    self.control            = Control()
    self.dataMemory         = DataMemory(memoryFile)
    self.instructionMemory  = InstructionMemory(memoryFile)
    self.regMux             = Mux()
    self.aluMux             = Mux()
    self.dmMux              = Mux()
    self.branchMux          = Mux()
    self.jmpMux             = Mux()
    self.registerFile       = RegisterFile()
    self.shiftLeft2         = ShiftLeft2()
    self.signExtend         = SignExtend()
    self.jump               = Jump()
    self.leftShift2         = ShiftLeft2()
    self.leftShift2Jump     = ShiftLeft2Jump()

    self.IFID = IFID()
    self.IDEX = IDEX()
    self.EXMEM = EXMEM()
    self.MEMWB = MEMWB()

    self.pc = PC(0xbfc00200) # hard coded "boot" address
    
    self.IFIDelements = [ self.constant, self.branchMux, self.jmpMux, self.instructionMemory, self.adder ]

    self.IDEXelements = [ self.control, self.registerFile, self.signExtend, self.leftShift2Jump, self.jump ]

    self.EXMEMelements = [ self.regMux, self.aluControl, self.aluMux, self.alu, self.shiftLeft2, self.branchAdder, self.branchNE, self.branch ]
    
    self.MEMWBelements = [ self.dataMemory ]

    self.WBelements = [ self.dmMux ] 

    self.elements = [ self.IFIDelements, self.IDEXelements, self.EXMEMelements, self.WBelements]

    self.pipes = [ self.IFID, self.IDEX, self.EXMEM, self.MEMWB]
    
    self._connectCPUElements()
Exemple #10
0
    def __init__(self, memoryFile):

        self.nCycles = 0  # Used to hold number of clock cycles spent executing instructions

        self.datamemory = DataMemory(memoryFile)
        self.instructionmemory = InstructionMemory(memoryFile)
        self.registerfile = RegisterFile()

        self.constant4 = Constant(4)

        self.alu = Alu()
        self.controlunit = ControlUnit()
        self.shift2 = Shift2()
        self.shift16 = Shift16()
        self.signextend = SignExtend()
        self.alterand = Alterand()
        self.altershift = Altershift()

        self.mux_writereg = Mux()  # 6 multiplexors
        self.mux_regoutput = Mux()
        self.mux_jump = Mux()
        self.mux_branch = Mux()
        self.mux_datamem = Mux()
        self.mux_shift16 = Mux()

        self.adderpc = Add()  # 2 adders
        self.addershift = Add()
        self.pc = PC(0xbfc00000)  # hard coded "boot" address

        self.elements = [
            self.constant4, self.adderpc, self.instructionmemory,
            self.controlunit, self.altershift, self.mux_writereg,
            self.registerfile, self.shift16, self.signextend, self.shift2,
            self.addershift, self.mux_regoutput, self.alu, self.alterand,
            self.mux_branch, self.mux_jump, self.datamemory, self.mux_datamem,
            self.mux_shift16, self.registerfile
        ]

        self._connectCPUElements()
Exemple #11
0
    def static_dielectric_constant(self):
        """Calculate relative static dielectric constant (w=0)
        Ref: Mol. Phys. 50, 841-858 (1983)

        Returns
        -------
        dielec_const_vec : float[:], shape = (num_frame)
            relative dielectric constant.
        """
        const = Constant()
        tot_dip_mat = self.total_dipole()
        run_avg_dip_vec = self._running_mean(np.sum(tot_dip_mat[:,:3], axis=1))
        run_avg_sqr_dip_vec = self._running_mean(np.sum(tot_dip_mat[:,:3]**2, axis=1))

        vol_vec = self._box_mat[:,0]*self._box_mat[:,1]*self._box_mat[:,2]

        dielec_const_vec = np.zeros(self._num_frame)
        dielec_const_vec.fill(4*np.pi/3)
        dielec_const_vec *= run_avg_sqr_dip_vec - run_avg_dip_vec**2
        dielec_const_vec /= vol_vec*const.kB*300
        dielec_const_vec /= const.eps0*1e-10/(1.602*1.602*1e-38)
        dielec_const_vec += 1
        return(dielec_const_vec)
Exemple #12
0
  def __init__(self, memoryFile):
    self.nCycles = 0 # Used to hold number of clock cycles spent executing instructions
    
    self.dataMemory = DataMemory(memoryFile)
    self.instructionMemory = InstructionMemory(memoryFile)
    self.registerFile = RegisterFile()
    self.alu = ALU()
    self.mainControl = MainControl()
    self.splitter = Splitter()
    self.signExtender = SignExtender()
    self.andGate = AndGate()
    self.breaker = Breaker()

    self.constant4 = Constant(4)
    # self.randomControl = RandomControl()
    self.pcMux1 = Mux()
    self.pcMux2 = Mux()
    self.regMux = Mux()
    self.aluMux = Mux()
    self.resultMux = Mux()
    self.luiMux = Mux()

    self.adder = Add()
    self.branchAdder = Add()

    self.jumpAddress = JMPAddress()
    self.shiftBranch = LeftShiftTwo()
    self.shiftJump = LeftShiftTwo()

    self.pc = PC(hex(0xbfc00000))  # hard coded "boot" address
    
    self.elements = [self.constant4, self.adder, self.instructionMemory, self.breaker, self.splitter,
                     self.shiftJump, self.mainControl, self.regMux, self.signExtender, self.luiMux, self.registerFile,
                     self.jumpAddress, self.shiftBranch, self.branchAdder, self.aluMux, self.alu, self.dataMemory,
                     self.andGate, self.pcMux1, self.pcMux2, self.resultMux, self.registerFile, self.pc]
    
    self._connectCPUElements()
Exemple #13
0
 def __init__(self):
     self.log = Logging()
     self.constant = Constant()
     self.maps = {}  # ID(int), MAP(object)
Exemple #14
0
 def addConst(self, val):
   if val not in self.consts:
     self.consts[val] = Constant(val)
   return self.consts[val]
import math, argparse
import numpy as np
import tensorflow as tf
import tensorflow_hub as hub
import os
import nltk
nltk.download('punkt')
nltk.download('averaged_perceptron_tagger')
nltk.download('universal_tagset')
from nltk import pos_tag, word_tokenize, RegexpParser

from constant import Constant
const = Constant()
const.MODULE_URL = "https://tfhub.dev/google/universal-sentence-encoder-large/5"  #@param ["https://tfhub.dev/google/universal-sentence-encoder/2", "https://tfhub.dev/google/universal-sentence-encoder-large/3"]
# os.environ['TFHUB_CACHE_DIR'] = '/tmp/tfhub_modules'
print('start')
embed = hub.load(const.MODULE_URL)


def similarities(sentence, paraphrases):
    vectors = embed([sentence] + paraphrases)
    cosine_similarities = []
    for v2 in vectors[1:]:
        cosine_similarities.append(
            cosine_similarity(np.array(vectors[0]), np.array(v2)))

    return cosine_similarities


def similarity(sentence, paraphrase):
    vectors = embed([sentence, paraphrase])
Exemple #16
0
# -*- coding: utf-8 -*-

from __future__ import division
import pygame
import random
from os import path

from constant import Constant

## assets folder
img_dir = path.join(path.dirname(__file__), 'assets')
sound_folder = path.join(path.dirname(__file__), 'sounds')

font_name = pygame.font.match_font('arial')

cons = Constant()

def main_menu():
    global screen
    cons = Constant()
    menu_song = pygame.mixer.music.load(path.join(sound_folder, "menu.mp3"))
    pygame.mixer.music.set_volume(5)
    pygame.mixer.music.play(-1)

    title = pygame.image.load(path.join(img_dir, "main.jpg")).convert()
    title = pygame.transform.scale(title, (cons.WIDTH, cons.HEIGHT), screen)

    screen.blit(title, (0,0))
    draw_text(screen, "School Battle", 72, cons.WIDTH/2, cons.HEIGHT/2 - 80, cons.BLACK)
    pygame.display.update()
Exemple #17
0
from averager import Averager
from constant import Constant
from julia import Competative
from zeke import Zeke
from regression import Regression
from alice import Alice
from julia import Julia
from marginal import Marginal
from julia import Julinear

players = [
    Laster(),
    Zeke(),
    Julia(),
    Julinear(),
    Constant(),
    Competative(),
    Marginal()
]

TheGov = Gov(players, plant_groups)
Plotter = MultiGraphPlotter(window=100)
MoneyPlotter = PlayerStatePlotter(window=100)
# The number of times to repeat the simulation.
repeats = 50
# The number of rounds per simulation.
rounds = 24 * 365

# Rather or not we should plot.
plot = False