feat: find interesting locations for deep zoom, with lot of changes during the zoom

This commit is contained in:
2026-09-30 10:24:20 +02:00
parent 370894e62f
commit c59fe800b1
6 changed files with 540 additions and 4 deletions
+1
View File
@@ -0,0 +1 @@
out/
+83 -2
View File
@@ -1,7 +1,7 @@
# Deep-zoom locations
Beautiful deep Mandelbrot locations, all computed with `find_deep.py` and checked with a
`--headless` render. Every one is an exact minibrot nucleus (Newton's method at
Beautiful deep Mandelbrot locations, all computed with `find_deep.py` or `search.py` and
checked with a `--headless` render. Every one is an exact minibrot nucleus (Newton's method at
`2·depth + 60` digits), not a coordinate copied from somewhere, so the digits are right all
the way down.
@@ -153,8 +153,89 @@ A single twelve-armed star, very symmetric. The antenna minibrots have short per
--view=-0.1011037579721041867570689093600472352495811991784283939876186880159732846332867701937330961715882746718394428627914481009391257007785408536971203165750666758077852384490279260184029373211737264310068845597273991782305778295187471341711226626762421910644338164121042775094463557363347706110614218633830535086184,0.9562940079523540929071943411882448455804659198042339938863014041593801060467576090157496959748683171680339080646917869452781885502668216669916185990922330667568398963038228431738928191227884090004548615469303071899797403388188723954061899156655653387543351937028936674153437083087070219108726088551230849901498,2.5e-300
```
## Morphing zooms (no endless spiral)
A minibrot from `find_deep.py` sits at distance r from a Misiurewicz point and has size r², so
the first half of its zoom (in log scale) is the same spiral turning over and over. These are
built by `search.py` instead: a chain of minibrots, each picked inside the previous one's
embedded Julia set, off its centre. Every time the zoom passes one, the picture folds (z → z²
locally), so each stage shows the previous shape doubled instead of a repeat. The Misiurewicz
point is only used for the first few decades.
Each location has two end points. Zoom to the **last embedded Julia set** to keep changing
shape all the way down. The **minibrot** is about a third deeper, but that last stretch is
rings closing in on it, which looks the same for every minibrot.
The colour contrast washes out at these depths in headless renders (the default colour scale is
tuned for shallower views). Try `--palette` or the interactive app.
### Seahorse valley, 9 stages, minibrot at 1.95e-367 (period 13701)
Seed 2, the top scorer. Each stage doubles the pattern. Around 1e-150 it is an eight-armed star of seahorse-tail spirals, and by 1e-250 each arm has become a spiral arm of its own. The last Julia set is pale cyan S-spirals interlocked with small snowflakes.
```sh
# last embedded Julia set
--view=-0.7753452295156405956088382319063405041200389687755508065690758933972356154674766194756672970107824576987716506820473626377289966850477815993212514936989107755288403190421564405962299577965531281406098430140843315809148941148835642905077493477538626689716455579196401297663769682360083746728010029499252318437245060419975563373728583873423397522687593946164217423611237456686155,0.1364239581870775619072911253207719792041200901039288844939565392217863173195981034417860802937281884987101484785589683756503781834313063872897864695678156825572773750286514435594400277526505362588686964101890046172400600115486054295219300235694108056070084590715209580088595029634293379003635002553779969859087272620892813545216852862560609109477666596320676409189943462906183,1.7e-275
# minibrot
--view=-0.7753452295156405956088382319063405041200389687755508065690758933972356154674766194756672970107824576987716506820473626377289966850477815993212514936989107755288403190421564405962299577965531281406098430140843315809148941148835642905077493477538626689716455579196401297663769682360083746728010029499252318437245060419975563373728583873423397522687593946164217423611237456686155,0.1364239581870775619072911253207719792041200901039288844939565392217863173195981034417860802937281884987101484785589683756503781834313063872897864695678156825572773750286514435594400277526505362588686964101890046172400600115486054295219300235694108056070084590715209580088595029634293379003635002553779969859087272620892813545216852862560609109477666596320676409189943462906183,5.8e-367
```
### Seahorse valley, 9 stages, minibrot at 2.23e-332 (period 20771)
Seed 24. Ends on a deep-blue field with a ladder of two spiky rosettes up the middle and seahorse spirals hanging off both sides.
```sh
# last embedded Julia set
--view=-0.77581899776364093541231633878667591854940234460393623634560469682524602327917430132831992200028242018281986527945300983871854511115659304292671652789338745276924830204381603012151271794534404802657864351394053047466207495399034821695775654392586465718993627074907162608014351492003087712186151836540562594796512607687563345530430631968989769,0.13639016044733587310899816976451186522511735544614557616370747772490427471765768547942874390030670422507300887964841711805169647706659494431705444259263501596739281803768172126446068576798485059599688488281382970932839834055072153017771954773333653697740526075860787508424313537171575674813478338329140463605230166008829195653885760869703998,4.2e-249
# minibrot
--view=-0.77581899776364093541231633878667591854940234460393623634560469682524602327917430132831992200028242018281986527945300983871854511115659304292671652789338745276924830204381603012151271794534404802657864351394053047466207495399034821695775654392586465718993627074907162608014351492003087712186151836540562594796512607687563345530430631968989769,0.13639016044733587310899816976451186522511735544614557616370747772490427471765768547942874390030670422507300887964841711805169647706659494431705444259263501596739281803768172126446068576798485059599688488281382970932839834055072153017771954773333653697740526075860787508424313537171575674813478338329140463605230166008829195653885760869703998,6.7e-332
```
### Elephant valley, 10 stages, minibrot at 9.9e-376 (period 26330)
Seed 10. The busiest one. Around 1e-100 it is dense blue lace over dark red; around 1e-200 there are big pinwheel fans with curled trunk tips, the prettiest frame of the set. Toward the end it becomes a dark field of small starbursts.
```sh
# last embedded Julia set
--view=0.2919725609273281486648237582115998883600209040251439086749905948711563568174299074829283558691127379979884016672342155749823780016183197461740530259273568326709292748874665616014636798873898973811666320162356520760904526444122077135661892284506788063980999152039879384033195224044981383998272534314607724906042434605344003420578380980595202662299201627356955139354311024040150045335132,0.01609653145423751028823367722046071738201813858290104726012040624213292560317148577164650820980015376333402589301809392204612823423640558757865322964450320793537771158249026499009376062869974452053829363185721040089473699420550959606623588474079103727001609122830051578927796106929658205975868875493047686224923681237537000490733609889219929444859368575967702125530262379423175371468097,5.5e-282
# minibrot
--view=0.2919725609273281486648237582115998883600209040251439086749905948711563568174299074829283558691127379979884016672342155749823780016183197461740530259273568326709292748874665616014636798873898973811666320162356520760904526444122077135661892284506788063980999152039879384033195224044981383998272534314607724906042434605344003420578380980595202662299201627356955139354311024040150045335132,0.01609653145423751028823367722046071738201813858290104726012040624213292560317148577164650820980015376333402589301809392204612823423640558757865322964450320793537771158249026499009376062869974452053829363185721040089473699420550959606623588474079103727001609122830051578927796106929658205975868875493047686224923681237537000490733609889219929444859368575967702125530262379423175371468097,3.0e-375
```
### Elephant valley, 10 stages, minibrot at 2.58e-393 (period 31938)
Seed 6. Ends on a cream field covered in tiny orange starbursts, like frost on a window.
```sh
# last embedded Julia set
--view=0.291920245587041963891588502847402316252926795406554403678013521015333816452464592295071998432671814509111459555663776008730796899291641422047823143066182408211544669386206661368710007384581820315259562196579747306521924025557974076213683940172635312577637426632710121469687554303515614245960216389023574299414942997525087881669471153995469440602254536765333823609728596136514603489157828188139494926264,0.0160764363740117355209701377378165904185186672655973900712949768468968706838603774970184637138036946417491390244864230673560872881279816470698447551999091888703048347169598010650942657073167719830723550405395270691529274225324525523911917416786211773060643555546204329361883408672335674317068855354237389458235628771660652358504910575175071131870389768222336460879256178272208513228731902472063018497750,1.7e-295
# minibrot
--view=0.291920245587041963891588502847402316252926795406554403678013521015333816452464592295071998432671814509111459555663776008730796899291641422047823143066182408211544669386206661368710007384581820315259562196579747306521924025557974076213683940172635312577637426632710121469687554303515614245960216389023574299414942997525087881669471153995469440602254536765333823609728596136514603489157828188139494926264,0.0160764363740117355209701377378165904185186672655973900712949768468968706838603774970184637138036946417491390244864230673560872881279816470698447551999091888703048347169598010650942657073167719830723550405395270691529274225324525523911917416786211773060643555546204329361883408672335674317068855354237389458235628771660652358504910575175071131870389768222336460879256178272208513228731902472063018497750,7.7e-393
```
## Finding more
Zooms that keep changing shape (Julia morphing, see above), ranked by rendering them:
```sh
./search.py seahorse # 24 chains down to ~1e-300..1e-450, prints the best 5
./search.py elephant --depth 200 --candidates 40 --seed 100
./morph.py seahorse --seed 7 --all-stages # one chain, with every stage's views
./score.py --view=RE,IM,HALF_HEIGHT --debug # score any zoom (e.g. the entries above)
```
`search.py` builds chains on every core (a few seconds each), then renders 32 thumbnails
along each zoom on the GPU (10-60 s each, most of the run time). The score is detail
(gradient strength) times one minus the fraction of frames that repeat the ones before them.
That fraction comes from a rotation- and scale-invariant (Fourier-Mellin) frame descriptor,
and it's about 0.6 for the spiral zooms above versus ~0 for morphing chains. Contact sheets
(8 frames along the zoom) go to `out/`. The thumbnails have no AA, so deep frames look
noisier there than they really are: render the view before judging. Needs mpmath, numpy,
Pillow and `cargo build --release`. Antenna chains work too, but they're mostly empty
background with thin dendrites, so they score low.
Minibrots next to a Misiurewicz point (the spiral locations above):
```sh
./find_deep.py --list # known regions
./find_deep.py seahorse 250 # minibrot of size ~1e-500 near the seahorse point
+3 -1
View File
@@ -11,7 +11,9 @@ minibrot of size ~r^2, found by:
3. the standard size estimate (Heiland-Allen) for its scale.
Zooming at the nucleus shows spirals, then an embedded Julia set (around
size^0.75), then the minibrot (half-height ~3x size).
size^0.75), then the minibrot (half-height ~3x size). The spirals take
the first half of the zoom: for zooms that keep changing shape, use
morph.py / search.py instead.
Usage:
find_deep.py REGION DEPTH [OFFSET_RE,OFFSET_IM]
+200
View File
@@ -0,0 +1,200 @@
#!/usr/bin/env python3
"""Chain minibrots by Julia morphing, so a deep zoom keeps changing shape.
find_deep.py puts a minibrot of size r^2 at distance r from a Misiurewicz
point, so the first half of the zoom (in log scale) is the same spiral over
and over. Here the Misiurewicz point is only used shallowly (stage 0), and
each later minibrot is picked inside the previous one's embedded Julia set,
off its centre. Zooming past a minibrot's neighbourhood folds the picture
(locally z -> z^2), so every stage shows the previous shape doubled instead
of a repeat.
Usage:
morph.py REGION [--stages N] [--depth D] [--d0 D0] [--seed S]
REGION is a name from find_deep.REGIONS or "re,im,k,p". Prints each stage's
period, size and the views to look at. search.py tries many seeds and ranks
the resulting zooms by rendering them.
Needs mpmath.
"""
import argparse
import math
import random
import sys
from dataclasses import dataclass
from mpmath import exp, log10, mp, mpc, mpf, sqrt
from find_deep import REGIONS, misiurewicz, nucleus, period_in_ball, size
# The shader treats an exhausted reference as escaped, and the reference is
# requested with 1.5x headroom (app.rs), so periods past this can't render.
MAX_ITERATIONS = 1 << 24
@dataclass
class Stage:
nucleus: mpc
period: int
size: mpf
reach: mpf # distance from the previous stage's centre (stage 0: the disk radius)
rho: float = 0.0 # where the target was picked, in units of the previous julia scale
theta: float = 0.0
@property
def julia(self):
"""Half-height of the embedded Julia set: geometric midpoint of reach and size."""
return sqrt(self.size * self.reach)
@property
def depth(self):
return float(-log10(self.size))
def set_precision(depth):
mp.dps = int(2 * depth) + 60
def anchor_point(region):
if region in REGIONS:
(re, im), k, p = REGIONS[region]
else:
re, im, k, p = region.split(",")
k, p = int(k), int(p)
return mpc(re, im), k, p
def find_minibrot(center, radius, min_period):
"""Nucleus of the lowest-period minibrot whose atom covers the disk, or None.
Rejects periods <= min_period (an ancestor, not something new next to
the target) and Newton landing far from the disk (another nucleus of the
same period).
"""
p = period_in_ball(center, radius)
if p is None or p <= min_period:
return None
n = nucleus(center, p)
if abs(n - center) > 4 * radius:
return None
s = size(n, p)
if not s > 0:
return None
return n, p, s
def stage0(region, d0, rng):
"""Minibrot near the Misiurewicz point at distance 10^-d0: a short spiral."""
c, k, p = anchor_point(region)
set_precision(2 * d0)
m = misiurewicz(c, k, p)
r = mpf(10) ** (-d0)
for _ in range(20):
theta = rng.uniform(0, 2 * math.pi)
off = r * exp(1j * mpf(theta))
found = find_minibrot(m + off, r, 0)
# Size ~r^2; far below means Newton didn't converge (as in find_deep.py).
if found and r * r * 1e-10 < found[2] < r * r * 1e6:
n, per, s = found
return Stage(n, per, s, abs(n - m), 0.0, theta)
return None
def next_stage(prev, rng, max_depth, beta=0.05, tries=12):
"""A minibrot inside prev's embedded Julia set, off its centre."""
for _ in range(tries):
rho = rng.uniform(0.05, 0.6)
theta = rng.uniform(0, 2 * math.pi)
# Enough digits to place the target and find the period; the nucleus
# is polished at the new depth's precision below, which is the costly
# part (a few Newton steps instead of all of them).
mp.dps = int(-log10(prev.julia)) + 60
d = rho * prev.julia
t = prev.nucleus + d * exp(1j * mpf(theta))
found = find_minibrot(t, beta * d, prev.period)
if not found:
continue
n, p, s = found
# Newton didn't converge (implausibly small), no real progress, or
# past the target depth (renders get slow and views huge).
if s < prev.size ** 2.5 or s > prev.size ** 1.2 or -log10(s) > max_depth:
continue
set_precision(float(-log10(s)))
n = nucleus(n, p) # polish at the precision this depth needs
s2 = size(n, p)
if not s / 10 < s2 < s * 10: # the polish wandered off to another nucleus
continue
return Stage(n, p, s2, abs(n - prev.nucleus), rho, theta)
return None
def build_chain(region, stages, depth, d0, seed, max_period=200_000):
"""Stage list, deepest last, ending between depth and 1.5x depth if it can.
Stops early at max_period or a dead end (no stage within reach).
"""
rng = random.Random(seed)
s = stage0(region, d0, rng)
if s is None:
return []
chain = [s]
while len(chain) < stages and chain[-1].depth < depth:
s = next_stage(chain[-1], rng, 1.5 * depth)
if s is None or s.period > min(max_period, MAX_ITERATIONS // 2):
break
chain.append(s)
return chain
def view_args(stage, half_height):
set_precision(stage.depth)
digits = int(stage.depth) + 10
re = mp.nstr(stage.nucleus.real, digits, strip_zeros=False)
im = mp.nstr(stage.nucleus.imag, digits, strip_zeros=False)
return f"--view={re},{im},{mp.nstr(half_height, 2)}"
def minibrot_view(stage):
return view_args(stage, 3 * stage.size)
def julia_view(stage):
return view_args(stage, stage.julia)
def describe(chain):
lines = []
for i, s in enumerate(chain):
lines.append(f"# stage {i}: period={s.period} size={mp.nstr(s.size, 3)} "
f"julia={mp.nstr(s.julia, 3)} rho={s.rho:.2f} theta={s.theta:.2f}")
return lines
def main(argv):
ap = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
ap.add_argument("region")
ap.add_argument("--stages", type=int, default=6)
ap.add_argument("--depth", type=float, default=300, help="stop past size 10^-DEPTH")
ap.add_argument("--d0", type=float, default=4, help="stage 0 distance 10^-D0 from the anchor")
ap.add_argument("--seed", type=int, default=1)
ap.add_argument("--max-period", type=int, default=200_000)
ap.add_argument("--all-stages", action="store_true", help="print every stage's views")
a = ap.parse_args(argv)
chain = build_chain(a.region, a.stages, a.depth, a.d0, a.seed, a.max_period)
if not chain:
print("no minibrot found near the anchor, try another seed", file=sys.stderr)
return 1
for line in describe(chain):
print(line)
for i, s in enumerate(chain if a.all_stages else chain[-1:]):
i = i if a.all_stages else len(chain) - 1
print(f"# stage {i} embedded Julia set:\n{julia_view(s)}")
print(f"# stage {i} minibrot:\n{minibrot_view(s)}")
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
+160
View File
@@ -0,0 +1,160 @@
#!/usr/bin/env python3
"""Score a deep zoom by rendering thumbnails along it.
One `--headless` animation call streams the whole zoom (full set down to
the target, evenly spaced in log-depth) as raw RGBA thumbnails. Per frame:
- detail: mean gradient magnitude at half resolution, so flat bands and
empty voids score low and aliasing noise doesn't score high;
- a Fourier-Mellin descriptor (|FFT| resampled to log-polar, then |FFT| of
that), invariant to translation, rotation and scale. A Misiurewicz spiral
looks the same at every turn, so its frames all get the same descriptor.
A frame's novelty is its mean descriptor distance to the 3 frames before
it. boring = fraction of frames with novelty below BORING (at the default
32 frames, spiral zooms sit around 0.17, morphing chains around 0.28). score = mean detail x
(1 - boring) x (1 - empty fraction).
Usage:
score.py --view=RE,IM,HALF_HEIGHT [--frames 32] [--debug] [--sheet out.png]
Needs numpy and a release build (cargo build --release).
"""
import argparse
import os
import subprocess
import sys
from dataclasses import dataclass
import numpy as np
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
BINARY = os.path.join(ROOT, "target", "release", "mandelbrot")
START_VIEW = "-0.75,0,1.5"
BORING = 0.21 # novelty below which a frame repeats the ones before it
LAGS = (1, 2, 3)
EMPTY = 0.02 # detail below which a frame counts as empty
def render_path(view, frames=32, width=192, height=108, start=START_VIEW):
"""Frames from the full set down to `view` (RE,IM,HALF_HEIGHT), shape (n, h, w, 3)."""
view = view.removeprefix("--view=")
cmd = [BINARY, "--headless", f"--view={start}", f"--to-view={view}",
"--frames", str(frames), "--linear", "--width", str(width),
"--height", str(height), "--export-path", "-"]
out = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
check=True).stdout
rgba = np.frombuffer(out, np.uint8).reshape(frames, height, width, 4)
return rgba[..., :3]
def edges(frame):
"""RGB gradient magnitude: filaments and band slopes, whatever the palette phase.
The cosine palettes offset the channels' phases, so the three channel
gradients never vanish together the way one brightness gradient does.
"""
f = frame.astype(np.float32) / 255.0
gy, gx = np.gradient(f, axis=(0, 1))
return np.sqrt((gx * gx + gy * gy).sum(axis=2))
def detail(frame):
"""Edge strength after a 2x2 box average.
Thumbnails are rendered without AA, so a deep frame's sub-pixel filaments
alias into noise. The average smooths that noise away but keeps real
filaments, so a noisy frame doesn't win on detail.
"""
h, w = frame.shape[0] // 2 * 2, frame.shape[1] // 2 * 2
f = frame[:h, :w].astype(np.float32)
f = (f[0::2, 0::2] + f[1::2, 0::2] + f[0::2, 1::2] + f[1::2, 1::2]) / 4
return float(edges(f.astype(np.uint8)).mean())
def structure(e):
"""Rank-normalised edge map: which pixels are filaments, not how bright they are."""
r = np.empty(e.size, np.float32)
r[np.argsort(e, axis=None, kind="stable")] = np.linspace(0, 1, e.size)
return r.reshape(e.shape)
def _log_polar_grid(h, w, n_r=32, n_a=64):
cy, cx = h / 2, w / 2
r = np.exp(np.linspace(np.log(2), np.log(min(cy, cx) - 1), n_r))
a = np.linspace(0, np.pi, n_a, endpoint=False) # |FFT| is point-symmetric
ys = (cy + r[:, None] * np.sin(a)[None, :]).astype(int)
xs = (cx + r[:, None] * np.cos(a)[None, :]).astype(int)
return ys, xs
def descriptor(g):
"""Translation-, rotation- and scale-invariant signature of a frame."""
g = (g - g.mean()) * np.outer(np.hanning(g.shape[0]), np.hanning(g.shape[1]))
mag = np.abs(np.fft.fftshift(np.fft.fft2(g)))
ys, xs = _log_polar_grid(*g.shape)
lp = np.log1p(mag[ys, xs])
lp -= lp.mean()
# Rotation and scale are shifts along the log-polar axes: drop them.
d = np.abs(np.fft.fft2(lp))[:8, :16].ravel()
return d / (np.linalg.norm(d) + 1e-12)
@dataclass
class PathScore:
score: float
detail: float
boring: float
empty: float
per_frame: list # (detail, novelty)
def score_frames(frames):
maps = [edges(f) for f in frames]
det = np.array([detail(f) for f in frames])
desc = [descriptor(structure(e)) for e in maps]
novelty = np.array([
np.mean([np.linalg.norm(desc[i] - desc[i - lag]) for lag in LAGS])
for i in range(max(LAGS), len(frames))
])
# The last frames close in on the minibrot, which is meant to look alike.
boring = float((novelty[:-2] < BORING).mean())
empty = float((det < EMPTY).mean())
per_frame = list(zip(det.tolist(), [0.0] * max(LAGS) + novelty.tolist()))
return PathScore(float(det.mean()) * (1 - boring) * (1 - empty),
float(det.mean()), boring, empty, per_frame)
def save_sheet(frames, path, picks=(0.25, 0.5, 0.75, 1.0), columns=4):
"""A grid of the frames at the given fractions of the zoom, row by row."""
from PIL import Image # optional: only needed for sheets
idx = [min(len(frames) - 1, round(p * (len(frames) - 1))) for p in picks]
rows = [np.concatenate([frames[i] for i in idx[r:r + columns]], axis=1)
for r in range(0, len(idx), columns)]
Image.fromarray(np.ascontiguousarray(np.concatenate(rows, axis=0))).save(path)
def main(argv):
ap = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
ap.add_argument("--view", required=True, help="RE,IM,HALF_HEIGHT of the zoom target")
ap.add_argument("--frames", type=int, default=32)
ap.add_argument("--debug", action="store_true", help="print per-frame metrics")
ap.add_argument("--sheet", help="write a contact sheet PNG (needs Pillow)")
a = ap.parse_args(argv)
frames = render_path(a.view, a.frames)
s = score_frames(frames)
if a.debug:
for i, (d, nov) in enumerate(s.per_frame):
print(f"{i:3} detail={d:.3f} novelty={nov:.3f}")
print(f"score={s.score:.4f} detail={s.detail:.3f} boring={s.boring:.2f} empty={s.empty:.2f}")
if a.sheet:
save_sheet(frames, a.sheet)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
+92
View File
@@ -0,0 +1,92 @@
#!/usr/bin/env python3
"""Random search for deep zooms that keep changing shape all the way down.
Builds many Julia-morphing chains (morph.py) from different seeds on every
core, renders each zoom's thumbnails on the GPU (score.py), and prints the
best ones with their views and a contact sheet (8 frames) in out/.
Zooms are scored down to the last embedded Julia set, not the minibrot:
the last quarter of the way to any minibrot is rings closing in on it (as
self-similar as a spiral) and looks the same in every chain.
Usage:
search.py REGION [--depth 300] [--candidates 24] [--seed 1] [--jobs N]
Needs mpmath, numpy, Pillow and a release build (cargo build --release).
"""
import argparse
import os
import subprocess
import sys
from concurrent.futures import ProcessPoolExecutor, as_completed
from morph import build_chain, describe, julia_view, minibrot_view
from score import render_path, save_sheet, score_frames
OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "out")
def chain_job(region, stages, depth, d0, seed, max_period):
chain = build_chain(region, stages, depth, d0, seed, max_period)
if not chain:
return seed, None
last = chain[-1]
return seed, {
"stages": describe(chain),
"depth": last.depth,
"period": last.period,
"julia": julia_view(last),
"minibrot": minibrot_view(last),
}
def main(argv):
ap = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
ap.add_argument("region", help="find_deep.py region name, or re,im,k,p")
ap.add_argument("--stages", type=int, default=14)
ap.add_argument("--depth", type=float, default=300, help="stop past size 10^-DEPTH")
ap.add_argument("--d0", type=float, default=4, help="stage 0 distance 10^-D0 from the anchor")
ap.add_argument("--candidates", type=int, default=24)
ap.add_argument("--seed", type=int, default=1, help="first seed; candidates use seed, seed+1, ...")
ap.add_argument("--max-period", type=int, default=200_000)
ap.add_argument("--jobs", type=int, default=os.cpu_count())
ap.add_argument("--top", type=int, default=5)
a = ap.parse_args(argv)
os.makedirs(OUT, exist_ok=True)
results = []
with ProcessPoolExecutor(a.jobs) as pool:
futures = [pool.submit(chain_job, a.region, a.stages, a.depth, a.d0, s, a.max_period)
for s in range(a.seed, a.seed + a.candidates)]
# Chains finish in any order; render each as it arrives (one at a time on the GPU).
for f in as_completed(futures):
seed, r = f.result()
if r is None:
print(f"seed {seed}: no chain", file=sys.stderr)
continue
try:
frames = render_path(r["julia"])
except (OSError, subprocess.CalledProcessError) as e:
print(f"seed {seed}: render failed: {e}", file=sys.stderr)
continue
s = score_frames(frames)
sheet = os.path.join(OUT, f"{a.region.split(',')[0]}-{seed}.png")
save_sheet(frames, sheet, picks=[i / 7 for i in range(8)], columns=4)
print(f"seed {seed}: score={s.score:.4f} boring={s.boring:.2f} "
f"depth=1e-{r['depth']:.0f} period={r['period']}", file=sys.stderr)
results.append((s, seed, r, sheet))
results.sort(key=lambda x: -x[0].score)
for s, seed, r, sheet in results[:a.top]:
print(f"\n## seed {seed}: score={s.score:.4f} detail={s.detail:.3f} "
f"boring={s.boring:.2f} empty={s.empty:.2f}")
print(f"# contact sheet: {sheet}")
print("\n".join(r["stages"]))
print(f"# last embedded Julia set (end here to keep changing shape all the way):\n{r['julia']}")
print(f"# minibrot (the last quarter of the zoom is rings closing in):\n{r['minibrot']}")
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))