Skip to content

Commit

Permalink
git pull removed fork
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Fievet committed Sep 9, 2024
2 parents 8e539dd + f9e3ab3 commit 0ff6b83
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 19 deletions.
4 changes: 2 additions & 2 deletions LIReC/db/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ class DBConnection:
db_name: str

def __init__(self):
self.host = 'database-1.c1keieal025m.us-east-2.rds.amazonaws.com'
self.host = 'rmdb.cluster-czg4ecmu66lx.us-east-2.rds.amazonaws.com'
self.port = 5432
self.user = 'spectator_public'
self.passwd = 'helloworld123'
self.db_name = 'lirec-main'
self.db_name = 'lirec'

def __str__(self):
return f'postgresql://{self.user}:{self.passwd}@{self.host}:{self.port}/{self.db_name}'
Expand Down
8 changes: 5 additions & 3 deletions LIReC/db/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
from os import system
from LIReC.db.access import connection, db
from LIReC.db.models import NamedConstant, Constant
from LIReC.lib.calculator import Constants
from LIReC.lib.calculator import Constants, Universal

if __name__ == '__main__':
oldname = connection.db_name
connection.db_name = 'postgres'
system(f'psql {connection} < LIReC/db/create.sql')
connection.db_name = oldname

precision = 4000
precision = 16000
print(f'Using {precision} digits of precision')
Constants.set_precision(precision)
for const in Constants.__dict__.keys():
if const[0] == '_' or const == 'set_precision':
continue
print(f'Adding named constant {const}')
db.session.add(Universal.calc_named(const, True, True))
if 'CAUTION' in Constants.__dict__[const].__get__(0).__doc__: Constants.set_precision(precision // 4)
else: Constants.set_precision(precision)
db.session.add(Universal.calc_named(const, None, True, True))

from mpmath import zeta

Expand Down
1 change: 1 addition & 0 deletions LIReC/db/create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ CREATE ROLE spectator WITH
NOCREATEROLE
NOREPLICATION;

GRANT ALL ON SCHEMA public TO spectator;
GRANT SELECT ON constant TO spectator;
GRANT SELECT ON constant_in_relation TO spectator;
GRANT SELECT, REFERENCES ON named_constant TO spectator;
Expand Down
4 changes: 3 additions & 1 deletion LIReC/lib/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from math import prod
import mpmath as mp
from mpmath import mpf
from re import match
from sympy import Poly, Symbol, compose
from traceback import format_exc
from typing import List
from urllib.request import urlopen
from LIReC.db.models import *
Expand Down Expand Up @@ -430,7 +432,7 @@ def Omega() -> mpf:
return mp.lambertw(1)

@staticmethod
def Zeta3() -> mpf:
def zeta3() -> mpf:
'''
apery constant, appears often in physics.
OEIS link: https://oeis.org/A002117
Expand Down
9 changes: 5 additions & 4 deletions LIReC/lib/logger.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import logging
import logging.handlers
import os
LOG_FORMAT = '%(asctime)s - %(filename)s - %(levelname)s - %(message)s'

def configure_logger(name, log_queue):
import os
if not log_queue:
return

if not os.path.exists('logs'):
os.mkdir('logs')

import logging.handlers
from multiprocessing import get_logger
root = logging.getLogger()

fileHandler = logging.handlers.RotatingFileHandler(f'logs/{name}.log', 'a', 1024*1024, 50)
Expand All @@ -19,7 +21,6 @@ def configure_logger(name, log_queue):
def print_logger(queue):
# https://docs.python.org/3/howto/logging-cookbook.html#logging-to-a-single-file-from-multiple-processes
# borrowed from ^^^ and modified to my liking
import logging
root = logging.getLogger()
h = logging.StreamHandler()
h.setFormatter(logging.Formatter(LOG_FORMAT))
Expand Down
23 changes: 16 additions & 7 deletions LIReC/lib/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,20 @@ class WorkerPool:
job_queue: Queue
result_queues: Dict[str, Queue]

def __init__(self: WorkerPool) -> None:
print('Starting __init__ WorkerPool ...')
def start(self: WorkerPool, modules: Dict[str, Any]): # -> module_id, timings
print("Starting __init__ WorkerPool ... pool.py", file=sys.stderr)

if len(modules) == 1 and not modules[0][1].get('run_async', False):
module_path, module_config = modules[0]
i = 0
module_id = f'{i}@{module_path}'
return WorkerPool.run_job(None, None, None, module_id, module_config, None)

self.manager = Manager()
self.job_queue = self.manager.Queue()
self.log_queue = self.manager.Queue()
self.result_queues = {}

def start(self: WorkerPool, modules: Dict[str, Any]): # -> module_id, timings
print('Starting WorkerPool ...')
Process(target=print_logger, args=(self.log_queue,)).start()
print("Process started")
pipes = []
Expand Down Expand Up @@ -142,11 +145,17 @@ def run_job(job_queue, log_queue, result_queue, module_id, module_config, in_pip
timings.append(time() - start_time)
iteration += 1

job_queue.put(Message.get_done_message())
in_pipe.send((module_id, timings))
if in_pipe:
job_queue.put(Message.get_done_message())
in_pipe.send((module_id, timings))
else:
return (module_id, timings)
except:
logging.info(f'Error in job {module_id}: {format_exc()}')
in_pipe.send((module_id, []))
if in_pipe:
in_pipe.send((module_id, []))
else:
return (module_id, [])

@staticmethod
def run_sub_job(module_id, parameters, log_queue, result_queue):
Expand Down
4 changes: 2 additions & 2 deletions LIReC/lib/pslq_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _latexify(name: str) -> str:
return name

if name[0] == 'e':
exp = Constants.latexify(name[1:])
exp = _latexify(name[1:])
if len(exp) > 1:
exp = f'{{{exp}}}'
return f'e^{exp}'
Expand All @@ -60,7 +60,7 @@ def _latexify(name: str) -> str:

root = match(r'root(\d+)of(\w+)', name)
if root and root[0] == name:
return fr'\sqrt[{root[1]}]{{{Constants.latexify(root[2])}}}'
return fr'\sqrt[{root[1]}]{{{_latexify(root[2])}}}'

groups = match(r'([A-Za-z]*)(_?)([A-Za-z]*)(\w*)', name)
if groups[0] != name:
Expand Down

0 comments on commit 0ff6b83

Please sign in to comment.