Skip to content

simulation.simulator

simulator

Simulation engine with parameter sweeps and convergence analysis.

Supports: - One-parameter sweeps (delta_C, lambda_1, k, etc.) - Two-parameter sweeps (grid) - Convergence analysis as order increases - Monte Carlo spinor structure sampling

Simulator

Simulator(delta_obs: float = 3.443)

Simulation engine for spinor correction parameter studies.

All parameters are fully customizable. Supports arbitrary parameter ranges and precision levels.

Source code in src/simulation/simulator.py
def __init__(self, delta_obs: float = 3.443):
    self.delta_obs = delta_obs
    self.results: dict[str, Any] = {}
    self.logs: list[str] = []
sweep_delta_C
sweep_delta_C(delta_C_range: tuple[float, float] | None = None, n_points: int = 200, lambda_D2: float = 3.338, k: int = 22, c4: float = 0.125, c6: float = 0.5) -> dict

Sweep delta_C over a range and compute Choptyuk formula at each point.

Parameters:

Name Type Description Default
delta_C_range tuple[float, float] | None

(min, max) for delta_C. Default (0.1, 1.0).

None
n_points int

Number of points in sweep.

200
lambda_D2 float

Dirac eigenvalue (fixed).

3.338
k int

Structural constant.

22
c4, c6

Higher-order coefficients.

required

Returns:

Type Description
dict

Dict with arrays of delta_C values and computed results.

Source code in src/simulation/simulator.py
def sweep_delta_C(self, delta_C_range: tuple[float, float] | None = None,
                   n_points: int = 200,
                   lambda_D2: float = 3.338,
                   k: int = 22,
                   c4: float = 0.125,
                   c6: float = 0.5) -> dict:
    """Sweep delta_C over a range and compute Choptyuk formula at each point.

    Args:
        delta_C_range: (min, max) for delta_C. Default (0.1, 1.0).
        n_points: Number of points in sweep.
        lambda_D2: Dirac eigenvalue (fixed).
        k: Structural constant.
        c4, c6: Higher-order coefficients.

    Returns:
        Dict with arrays of delta_C values and computed results.
    """
    if delta_C_range is None:
        delta_C_range = (0.1, 1.0)

    dC_arr = np.linspace(delta_C_range[0], delta_C_range[1], n_points)
    delta_bc_arr = lambda_D2 + dC_arr**2 / 2
    delta_eff_arr = dC_arr**5 / k
    delta_ch_base_arr = delta_bc_arr - delta_eff_arr
    delta_ch_full_arr = delta_ch_base_arr + c4 * dC_arr**4 + c6 * dC_arr**6
    deviation_arr = np.abs(delta_ch_full_arr - self.delta_obs) / self.delta_obs * 100

    # Find optimal delta_C
    idx_min = np.argmin(deviation_arr)
    optimal_dC = dC_arr[idx_min]
    min_dev = deviation_arr[idx_min]

    self._log(f"Delta_C sweep: {n_points} points in [{delta_C_range[0]}, {delta_C_range[1]}]")
    self._log(f"Optimal δ_C = {optimal_dC:.6f}, deviation = {min_dev:.3f}%")
    self._log(f"Reference δ_C = π/7 = {np.pi/7:.6f}")

    result = {
        "delta_C": dC_arr.tolist(),
        "delta_bc": delta_bc_arr.tolist(),
        "delta_ch_base": delta_ch_base_arr.tolist(),
        "delta_ch_full": delta_ch_full_arr.tolist(),
        "deviation_pct": deviation_arr.tolist(),
        "optimal_delta_C": float(optimal_dC),
        "min_deviation_pct": float(min_dev),
        "reference_delta_C": float(np.pi / 7),
    }
    self.results["sweep_delta_C"] = result
    return result
sweep_lambda_1
sweep_lambda_1(lam_range: tuple[float, float] = (2.0, 6.0), n_points: int = 200, delta_C: float | None = None, R: float = -2.0, k: int = 22) -> dict

Sweep lambda_1 and observe its effect on the Choptyuk formula.

Parameters:

Name Type Description Default
lam_range tuple[float, float]

(min, max) for lambda_1.

(2.0, 6.0)
n_points int

Number of points.

200
delta_C float | None

Spinor phase (default pi/7).

None
R float

Scalar curvature.

-2.0
k int

Structural constant.

22

Returns:

Type Description
dict

Dict with sweep results.

Source code in src/simulation/simulator.py
def sweep_lambda_1(self, lam_range: tuple[float, float] = (2.0, 6.0),
                    n_points: int = 200,
                    delta_C: float | None = None,
                    R: float = -2.0, k: int = 22) -> dict:
    """Sweep lambda_1 and observe its effect on the Choptyuk formula.

    Args:
        lam_range: (min, max) for lambda_1.
        n_points: Number of points.
        delta_C: Spinor phase (default pi/7).
        R: Scalar curvature.
        k: Structural constant.

    Returns:
        Dict with sweep results.
    """
    dC = delta_C if delta_C is not None else np.pi / 7
    lam_arr = np.linspace(lam_range[0], lam_range[1], n_points)
    lam_D2_arr = lam_arr + R / 4
    delta_bc_arr = lam_D2_arr + dC**2 / 2
    delta_ch_arr = delta_bc_arr - dC**5 / k
    deviation_arr = np.abs(delta_ch_arr - self.delta_obs) / self.delta_obs * 100

    idx_min = np.argmin(deviation_arr)
    optimal_lam = lam_arr[idx_min]

    self._log(f"λ₁ sweep: optimal λ₁ = {optimal_lam:.4f} (ref: 3.838)")

    result = {
        "lambda_1": lam_arr.tolist(),
        "delta_ch": delta_ch_arr.tolist(),
        "deviation_pct": deviation_arr.tolist(),
        "optimal_lambda_1": float(optimal_lam),
    }
    self.results["sweep_lambda_1"] = result
    return result
convergence_analysis
convergence_analysis(max_order: int = 10, delta_C: float | None = None, lambda_D2: float = 3.338) -> dict

Analyze convergence of the Choptyuk series at increasing orders.

The series is: Delta = lambda_D2 + sum_{n=1}^{max_order} c_n * delta_C^n where c_n are the correction coefficients.

Parameters:

Name Type Description Default
max_order int

Maximum order to compute.

10
delta_C float | None

Spinor phase (default pi/7).

None
lambda_D2 float

Dirac eigenvalue.

3.338

Returns:

Type Description
dict

Dict with convergence data.

Source code in src/simulation/simulator.py
def convergence_analysis(self, max_order: int = 10,
                          delta_C: float | None = None,
                          lambda_D2: float = 3.338) -> dict:
    """Analyze convergence of the Choptyuk series at increasing orders.

    The series is: Delta = lambda_D2 + sum_{n=1}^{max_order} c_n * delta_C^n
    where c_n are the correction coefficients.

    Args:
        max_order: Maximum order to compute.
        delta_C: Spinor phase (default pi/7).
        lambda_D2: Dirac eigenvalue.

    Returns:
        Dict with convergence data.
    """
    dC = delta_C if delta_C is not None else np.pi / 7

    # Known coefficients: c2=1/2, c4=1/8, c5=-1/22, c6=1/2
    coeffs = {2: 0.5, 4: 0.125, 5: -1/22, 6: 0.5}

    partial_sums = []
    current = lambda_D2
    for n in range(1, max_order + 1):
        if n in coeffs:
            current += coeffs[n] * dC**n
        partial_sums.append({
            "order": n,
            "value": current,
            "deviation": abs(current - self.delta_obs) / self.delta_obs * 100,
        })

    self._log(f"Convergence analysis up to order {max_order}")
    for ps in partial_sums:
        self._log(f"  Order {ps['order']}: Δ={ps['value']:.6f}, dev={ps['deviation']:.3f}%")

    result = {"partial_sums": partial_sums}
    self.results["convergence"] = result
    return result