Skip to content

Commit 89554d6

Browse files
committed
RZ guards to reduce sim hang risk at high rho (>3000)
1 parent e3e0faa commit 89554d6

2 files changed

Lines changed: 32 additions & 16 deletions

File tree

src/Data/data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@
646646
"stratFilterCondition": "(Active || Very-Active) && rho >= 50 && rho < 400"
647647
},
648648
"RZdBHRewind" : {
649-
"stratFilterCondition": "Very-Active && rho >= 860"
649+
"stratFilterCondition": "Very-Active && rho >= 860 && rho <= 2000"
650650
}
651651
}
652652
},

src/Theories/CTs/RZ.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Currency from "../../Utils/currency";
44
import Variable from "../../Utils/variable";
55
import { ExponentialValue, StepwisePowerSumValue, LinearValue } from "../../Utils/value";
66
import { ExponentialCost, StepwiseCost, FirstFreeCost, BaseCost } from '../../Utils/cost';
7-
import { l10, binaryInsertionSearch, getBestResult, toCallables, logToExp } from "../../Utils/helpers";
7+
import { l10, binaryInsertionSearch, getBestResult, toCallables, logToExp, defaultResult } from "../../Utils/helpers";
88
import { c1Exp, lookups, resolution, zeta, ComplexValue } from "./helpers/RZ";
99
import goodzeros from "./helpers/RZgoodzeros.json" assert { type: "json" };
1010

@@ -19,6 +19,8 @@ class VariableBcost extends BaseCost {
1919
}
2020
}
2121

22+
class BlackHoleError extends Error{}
23+
2224
function mergeSortedLists(list1: number[], list2: number[]): number[] {
2325
let mergedList: number[] = [];
2426
let i = 0; // Pointer for list1
@@ -440,9 +442,12 @@ class rzSim extends theoryClass<theory> {
440442
bhProcess(zResult: ComplexValue | null = null, tmpZ: ComplexValue | null = null) {
441443
this.offGrid = true;
442444
if (this.strat != "RZdBHRewind") this.bhProcessCounter++;
445+
if (this.bhProcessCounter > 500) {
446+
throw new BlackHoleError("Black Hole algorithm did not converge.\nThis is likely due to precision issues at large t.");
447+
}
443448

444449
// This is a method to prevent the non-convergence of the algorithm
445-
const bhLockPreventionCoeff = this.bhProcessCounter < 1000 ? 1 : Math.E ** (-0.002*(this.bhProcessCounter - 1000));
450+
const bhLockPreventionCoeff = this.bhProcessCounter < 100 ? 1 : Math.E ** (-0.001*(this.bhProcessCounter - 100));
446451

447452
if (zResult === null){
448453
zResult = zeta(this.t_var, this.ticks, this.offGrid, lookups.zetaLookup);
@@ -573,20 +578,31 @@ class rzSim extends theoryClass<theory> {
573578
}
574579
async simulate(): Promise<simResult> {
575580
const BHStrats = new Set(["RZBH", "RZdBH", "RZBHLong", "RZdBHLong", "RZdBHRewind"]);
576-
while (!this.endSimulation()) {
577-
if (!global.simulating) break;
578-
// Prevent lookup table from retrieving values from wrong sim settings
579-
if (!this.ticks && (this.dt !== lookups.prevDt || this.ddt !== lookups.prevDdt)) {
580-
lookups.prevDt = this.dt;
581-
lookups.prevDdt = this.ddt;
582-
lookups.zetaLookup = [];
583-
lookups.zetaDerivLookup = [];
581+
try {
582+
while (!this.endSimulation()) {
583+
if (!global.simulating) break;
584+
// Prevent lookup table from retrieving values from wrong sim settings
585+
if (!this.ticks && (this.dt !== lookups.prevDt || this.ddt !== lookups.prevDdt)) {
586+
lookups.prevDt = this.dt;
587+
lookups.prevDdt = this.ddt;
588+
lookups.zetaLookup = [];
589+
lookups.zetaDerivLookup = [];
590+
}
591+
this.tick();
592+
this.updateSimStatus();
593+
if (this.lastPub < 600) this.updateMilestones();
594+
if (this.milestones[3] > 0 && BHStrats.has(this.strat)) this.updateBHstatus();
595+
this.buyVariables();
596+
}
597+
}
598+
catch (error) {
599+
if (error instanceof BlackHoleError) {
600+
const res = defaultResult();
601+
res.strat = error.message;
602+
console.error(error.message);
603+
return res;
584604
}
585-
this.tick();
586-
this.updateSimStatus();
587-
if (this.lastPub < 600) this.updateMilestones();
588-
if (this.milestones[3] > 0 && BHStrats.has(this.strat)) this.updateBHstatus();
589-
this.buyVariables();
605+
else throw error;
590606
}
591607
let stratExtra = "";
592608
if (this.strat.includes("BH"))

0 commit comments

Comments
 (0)