Skip to content

Commit

Permalink
Added human readable logging of the mersenne.ca response. [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
tdulcet committed Sep 14, 2024
1 parent bca7c11 commit 6e35d95
Showing 1 changed file with 45 additions and 28 deletions.
73 changes: 45 additions & 28 deletions primenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ def beep():
primenet_v5_bargs = OrderedDict((("px", "GIMPS"), ("v", TRANSACTION_API_VERSION)))
primenet_baseurl = "https://www.mersenne.org/"
mersenne_ca_baseurl = "https://www.mersenne.ca/"
MAX_PRIMENET_EXP = 1000000000

is_64bit = platform.machine().endswith("64")
PORT = None
Expand Down Expand Up @@ -813,7 +814,7 @@ def setup():
if program in {4, 5}:
tf1g = ask_yn(
"Is this setup for the TF1G subproject on https://mersenne.ca/tf1G? This is mutually exclusive with PrimeNet trial factoring.",
options.min_exp and options.min_exp >= 1000000000,
options.min_exp and options.min_exp >= MAX_PRIMENET_EXP,
)
gpu = None
if program != 1:
Expand Down Expand Up @@ -859,7 +860,7 @@ def setup():
config.set(SEC.PrimeNet, "memory", str(memory))
options.day_night_memory = memory * 0.9
if tf1g:
options.min_exp = 1000000000
options.min_exp = MAX_PRIMENET_EXP
config.set(SEC.PrimeNet, "GetMinExponent", str(options.min_exp))

disk = ask_float(
Expand Down Expand Up @@ -1537,7 +1538,7 @@ def parse_assignment(task):
assignment.n = int(n)
assignment.c = int(c)
assignment.cert_squarings = int(cert_squarings)
if assignment.n and assignment.n > 1000000000:
if assignment.n and assignment.n >= MAX_PRIMENET_EXP:
assignment.ra_failed = True
return assignment

Expand Down Expand Up @@ -1852,7 +1853,7 @@ def send(subject, message, attachments=None, to=None, cc=None, bcc=None, priorit
if options.email_username:
s.login(options.email_username, options.email_password)
s.sendmail(from_addr, to_addrs, msg.as_string())
except smtplib.SMTPException as e:
except (smtplib.SMTPException, IOError, OSError) as e: # socket.error
logging.exception("Failed to send e-mail: {0}".format(e), exc_info=options.debug)
return False
finally:
Expand Down Expand Up @@ -4789,7 +4790,7 @@ def unreserve_all(dirs):
changed = False
for assignment in assignments:
tf1g = False
if assignment.work_type == PRIMENET.WORK_TYPE_FACTOR and assignment.n >= 1000000000:
if assignment.work_type == PRIMENET.WORK_TYPE_FACTOR and assignment.n >= MAX_PRIMENET_EXP:
any_tf1g = tf1g = True
if tf1g or assignment_unreserve(adapter, assignment):
tasks = [
Expand Down Expand Up @@ -5073,10 +5074,10 @@ def recover_assignments(dirs):
unlock_file(workfile)


def tf1g_fetch(adapter, adir, max_assignments="", max_ghd="", retry_count=0):
def tf1g_fetch(adapter, adir, max_assignments, max_ghd="", retry_count=0):
stages = get_stages_mfaktx_ini(adapter, adir)
adapter.info(
"Getting {0}{1} TF1G assignments from mersenne.ca, stages={2}".format(
"Getting {0:n}{1} TF1G assignments from mersenne.ca, stages = {2}".format(
max_ghd or max_assignments, " GHz-days of" if max_ghd else "", stages
)
)
Expand Down Expand Up @@ -5196,7 +5197,9 @@ def get_assignments(adapter, adir, cpu_num, progress, tasks):
if config.has_option(SEC.PrimeNet, "MaxExponents"):
amax = config.getint(SEC.PrimeNet, "MaxExponents")
else:
amax = (10000 if options.min_exp and options.min_exp >= 1000000000 else 1000) if options.mfaktc or options.mfakto else 15
amax = (
(10000 if options.min_exp and options.min_exp >= MAX_PRIMENET_EXP else 1000) if options.mfaktc or options.mfakto else 15
)
days_work = timedelta(days=options.days_of_work)
new_tasks = []
while True:
Expand Down Expand Up @@ -5243,9 +5246,9 @@ def get_assignments(adapter, adir, cpu_num, progress, tasks):
)
)

if options.min_exp and options.min_exp >= 1000000000 and work_preference[cpu_num] in {2, 12}:
if options.min_exp and options.min_exp >= MAX_PRIMENET_EXP and work_preference[cpu_num] in {2, 12}:
if msec_per_iter is not None:
ghd_to_request = max(10, int(((options.days_of_work * 24 * 60 * 60) - cur_time_left) * 1000 / msec_per_iter))
ghd_to_request = max(10, ((options.days_of_work * 24 * 60 * 60) - cur_time_left) * 1000 / msec_per_iter)
assignments = tf1g_fetch(adapter, adir, num_to_get, ghd_to_request)
else:
assignments = tf1g_fetch(adapter, adir, num_to_get)
Expand Down Expand Up @@ -5299,7 +5302,7 @@ def register_assignment(adapter, cpu_num, assignment, retry_count=0):
if guid is None:
adapter.error("Cannot register assignment, the registration is not done")
return None
if assignment.k == 1.0 and assignment.b == 2 and assignment.n >= 1000000000 and assignment.c == -1:
if assignment.k == 1.0 and assignment.b == 2 and assignment.n >= MAX_PRIMENET_EXP and assignment.c == -1:
adapter.error("Cannot register assignment, exponent is larger than PrimeNet bounds")
return None
args = primenet_v5_bargs.copy()
Expand Down Expand Up @@ -5394,7 +5397,7 @@ def send_progress(adapter, cpu_num, assignment, percent, stage, time_left, now,
if guid is None:
adapter.error("Cannot send progress, the registration is not done")
return None
if assignment.n >= 1000000000:
if assignment.n >= MAX_PRIMENET_EXP:
# adapter.debug("Cannot send progress, exponent larger than PrimeNet bounds")
return None
if not assignment.uid:
Expand Down Expand Up @@ -5659,7 +5662,7 @@ def cuda_result_to_json(resultsfile, sendline):
return ar


def report_result(adapter, adir, ar, message, assignment, result_type, sendline, tasks, retry_count=0):
def report_result(adapter, adir, ar, message, assignment, result_type, tasks, retry_count=0):
"""Submit one result line using v5 API, will be attributed to the computer identified by guid."""
"""Return False if the submission should be retried"""
guid = get_guid(config)
Expand All @@ -5669,7 +5672,6 @@ def report_result(adapter, adir, ar, message, assignment, result_type, sendline,
# JSON is required because assignment_id is necessary in that case
# and it is not present in old output format.
# adapter.debug("Submitting using v5 API")
adapter.debug("Sending result: {0!r}".format(sendline))

args = primenet_v5_bargs.copy()
args["t"] = "ar" # assignment result
Expand Down Expand Up @@ -5790,13 +5792,13 @@ def report_result(adapter, adir, ar, message, assignment, result_type, sendline,
adapter.info("Retry count exceeded.")
return False
time.sleep(1 << retry_count)
return report_result(adapter, adir, ar, message, assignment, result_type, sendline, tasks, retry_count + 1)
return report_result(adapter, adir, ar, message, assignment, result_type, tasks, retry_count + 1)


def submit_mersenne_ca_results(adapter, lines, retry_count=0):
"""Submit results for exponents over 1,000,000,000 using https://www.mersenne.ca/submit-results.php"""
length = len(lines)
adapter.info("Submitting {0:n} results using mersenne.ca".format(length))
adapter.info("Submitting {0:n} results to mersenne.ca".format(length))
retry = False
try:
r = session.post(
Expand All @@ -5812,8 +5814,24 @@ def submit_mersenne_ca_results(adapter, lines, retry_count=0):
logging.exception(e, exc_info=options.debug)
retry = True
else:
adapter.info("mersenne.ca results:")
adapter.info(str(result["results"]))
adapter.info("mersenne.ca response:")
adapter.info(result["user_message"])
results = result["results"]
if results["unknown"]:
adapter.error("Unknown {0:n} result{1}.".format(results["unknown"], "s" if results["unknown"] != 1 else ""))
if results["rejected"]:
adapter.error("Rejected {0:n} result{1}.".format(results["rejected"], "s" if results["rejected"] != 1 else ""))
accepted = sum(results["accepted"].values())
adapter.info("Accepted {0:n} result{1}.".format(accepted, "s" if accepted != 1 else ""))
factors = results["factors"]
adapter.info(
"Total credit is {0:n} GHz-days{1}.".format(
sum(results["ghd"].values()),
", Found {0:n} new factor{1}".format(factors["new"], "s" if factors["new"] != 1 else "")
if factors["new"]
else "",
)
)
if retry:
if retry_count >= 3:
logging.info("Retry count exceeded.")
Expand Down Expand Up @@ -6073,17 +6091,16 @@ def parse_result(adapter, resultsfile, sendline):
)

if not no_report:
adapter.debug("Sending result: {0!r}".format(sendline))
adapter.info("Sending result to server: {0}".format(buf))

if result_type in {PRIMENET.AR_TF_FACTOR, PRIMENET.AR_P1_FACTOR}:
num = (
(1 << assignment.n) - 1
if result_type == PRIMENET.AR_TF_FACTOR
else int(assignment.k) * assignment.b**assignment.n + assignment.c
)
for factor in map(int, ar["factors"]):
adapter.info("The factor {0} has {1:n} decimal digits and {2:.6n} bits".format(factor, len(str(factor)), log2(factor)))
if num % factor:
if result_type == PRIMENET.AR_TF_FACTOR:
if pow(2, n, factor) - 1:
adapter.warning("Bad factor for M{0} found: {1}".format(assignment.n, factor))
elif (int(assignment.k) * pow(assignment.b, assignment.n, factor) + assignment.c) % factor:
adapter.warning("Bad factor for {0} found: {1}".format(exponent_to_str(assignment), factor))

return ar, message, assignment, result_type, no_report
Expand Down Expand Up @@ -6130,9 +6147,9 @@ def submit_work(adapter, adir, cpu_num, tasks):
ar, message, assignment, result_type, no_report = result
if no_report:
sent.append(sendline)
elif assignment.k == 1.0 and assignment.b == 2 and assignment.n >= 1000000000 and assignment.c == -1:
elif assignment.k == 1.0 and assignment.b == 2 and assignment.n >= MAX_PRIMENET_EXP and assignment.c == -1:
mersenne_ca_result_send.append((message, sendline))
elif report_result(adapter, adir, ar, message, assignment, result_type, sendline, tasks):
elif report_result(adapter, adir, ar, message, assignment, result_type, tasks):
sent.append(sendline)
else:
failed.append(sendline)
Expand Down Expand Up @@ -6623,7 +6640,7 @@ def is_pyinstaller():
options.days_of_work = 1.0 if options.mfaktc or options.mfakto else 3.0
config.set(SEC.PrimeNet, "DaysOfWork", str(options.days_of_work))
if not config.has_option(SEC.PrimeNet, "MaxExponents"):
amax = (10000 if options.min_exp and options.min_exp >= 1000000000 else 1000) if options.mfaktc or options.mfakto else 15
amax = (10000 if options.min_exp and options.min_exp >= MAX_PRIMENET_EXP else 1000) if options.mfaktc or options.mfakto else 15
config.set(SEC.PrimeNet, "MaxExponents", str(amax))

# check options after merging so that if local.ini file is changed by hand,
Expand Down Expand Up @@ -6753,7 +6770,7 @@ def is_pyinstaller():
)
)

if options.min_exp and options.max_exp and options.min_exp < 1000000000 <= options.max_exp:
if options.min_exp and options.max_exp and options.min_exp < MAX_PRIMENET_EXP <= options.max_exp:
parser.error(
"Minimum exponent ({0}) and maximum exponent ({1}) must both be less than or greater than 1,000,000,000 (for TF1G)".format(
options.min_exp, options.max_exp
Expand Down

0 comments on commit 6e35d95

Please sign in to comment.