ouroboros / source /scripts /check_showcase_refinements.py
REXWind's picture
Publish the Ouroboros scientific showcase to CladeTeam
03677d0 verified
Raw History Blame Contribute Delete
7.85 kB
"""Check dataset scope, pair-wise parameter sharing, dense output and Atlas coverage."""
import json,os
from pathlib import Path
from playwright.sync_api import sync_playwright,expect
OUT=Path('artifacts/refinements-20261110'); OUT.mkdir(parents=True,exist_ok=True)
BASE=os.environ.get('PREVIEW_URL','http://127.0.0.1:7860')
errors=[];failed=[]
def scroll(page,selector):
page.locator(selector).evaluate("e=>window.scrollTo({top:e.getBoundingClientRect().top+scrollY-100,behavior:'instant'})")
page.wait_for_timeout(450)
def at(page,value):
page.locator('.story-scroll').evaluate("(e,p)=>{const s=e.querySelector('.story-stage');window.scrollTo({top:scrollY+e.getBoundingClientRect().top-82+(e.offsetHeight-s.offsetHeight)*p,behavior:'instant'})}",value)
page.wait_for_timeout(950)
def motion_click(page, label):
# Pointer coordinates avoid Playwright scrolling a sticky header into view.
button=page.get_by_role('button',name=label,exact=True)
box=button.bounding_box();before=page.evaluate('scrollY')
page.mouse.click(box['x']+box['width']/2,box['y']+box['height']/2)
page.wait_for_timeout(80)
assert abs(page.evaluate('scrollY')-before)<2
def no_overlap(page):
svg=page.locator('.dual-scene-svg').bounding_box();nav=page.locator('.story-chapters').bounding_box()
assert svg['y']+svg['height'] <= nav['y']+.1
assert page.evaluate('document.documentElement.scrollWidth<=innerWidth')
with sync_playwright() as p:
browser=p.chromium.launch(executable_path=os.environ.get('CHROMIUM_PATH'),args=['--no-sandbox','--use-gl=angle','--use-angle=swiftshader','--enable-unsafe-swiftshader'])
page=browser.new_page(viewport={'width':1440,'height':1000})
page.on('pageerror',lambda e:errors.append(str(e)))
page.on('response',lambda r:failed.append(r.url) if r.status>=400 else None)
page.goto(BASE,wait_until='networkidle');page.evaluate('document.fonts.ready')
for name,value,modality in [('sharing-text',.924,'text'),('sharing-protein',.967,'protein'),('sharing-both',1,None)]:
at(page,value);no_overlap(page)
if modality:
assert float(page.locator(f'[data-sharing-modality="{modality}"]').get_attribute('data-emphasis'))>.9
for kind in ['encoder','decoder']:
assert float(page.locator(f'[data-module="{modality}-{kind}"] [data-shared-attention]').get_attribute('data-shared-attention'))>.9
other='protein' if modality=='text' else 'text'
assert float(page.locator(f'[data-module="{other}-encoder"] [data-shared-attention]').get_attribute('data-shared-attention'))<.1
page.screenshot(path=str(OUT/f'desktop-{name}.png'))
for label,mode in [('Text weights','text'),('Protein weights','protein')]:
page.get_by_role('button',name=label,exact=True).click();page.wait_for_timeout(300)
expect(page.get_by_role('button',name=label,exact=True)).to_have_attribute('aria-pressed','true')
assert float(page.locator(f'[data-sharing-modality="{mode}"]').get_attribute('data-emphasis'))>.9
at(page,.924);frame=page.locator('.dual-scene-svg').inner_html();at(page,.967);at(page,.924)
assert frame==page.locator('.dual-scene-svg').inner_html()
at(page,.475)
example=json.loads(Path('public/data/core-example.json').read_text())
assert page.locator('[data-output="protein"] [data-arrived="true"]').count()==72
assert page.locator('[data-output="protein"] [data-letter]').evaluate_all('els=>els.map(e=>e.dataset.letter).join("")')==example['generatedProtein'][:72]
rect=page.locator('[data-output="protein"] [data-letter] rect').first
assert rect.get_attribute('width')=='26' and rect.get_attribute('height')=='28'
page.screenshot(path=str(OUT/'desktop-residues.png'))
scroll(page,'#evidence');expect(page.locator('.benchmark-dataset')).to_contain_text('Swiss-Prot time-cutoff')
assert page.locator('#benchmark-set').count()==0
for task in ['Text → Protein','Protein → Text']:
page.locator('#evidence').get_by_role('button',name=task,exact=True).click()
for button in page.locator('#evidence .metric-tabs button').all():
button.click();text=page.locator('#evidence').inner_text()
assert not any(x in text for x in ['Hard','Normal','100 pairs','hard-set'])
for row in page.locator('.bar-row').all(): assert any(x in row.get_attribute('aria-label') for x in ['500 examples','476 examples'])
page.locator('#evidence').get_by_role('button',name='Text → Protein',exact=True).click()
scroll(page,'#evidence');page.screenshot(path=str(OUT/'desktop-benchmark.png'))
data=page.request.get(BASE+'/data/evidence.json').json()
assert len(data['metrics'])==63 and {r['split'] for r in data['metrics']}=={'swissprot_time_cutoff'}
scroll(page,'#atlas');page.wait_for_timeout(1000)
expect(page.locator('#atlas .coverage-stat')).to_contain_text('0.295')
page.screenshot(path=str(OUT/'desktop-atlas-coverage.png'))
scroll(page,'.atlas-preview-layout');m=page.locator('#atlas .atlas-map')
expect(m).to_have_attribute('data-layer','reference');page.screenshot(path=str(OUT/'desktop-atlas-reference.png'))
m.get_by_role('button',name='Ouroboros descriptions',exact=True).click()
canvas=m.locator('canvas')
page.wait_for_timeout(180);before=float(canvas.get_attribute('data-annotation-progress'))
assert 0<before<1
motion_click(page,'Pause page animations');page.wait_for_timeout(100)
frozen=canvas.get_attribute('data-annotation-progress');page.wait_for_timeout(300)
assert canvas.get_attribute('data-annotation-progress')==frozen
motion_click(page,'Resume page animations');expect(canvas).to_have_attribute('data-annotation-progress','1.0000')
assert canvas.get_attribute('data-annotation-progress')=='1.0000'
page.screenshot(path=str(OUT/'desktop-atlas-descriptions.png'))
m.get_by_role('button',name='Sequence communities',exact=True).click();expect(m).to_have_attribute('data-layer','communities')
# Complete the explicit layer change immediately when page motion is off.
motion_click(page,'Pause page animations')
m.get_by_role('button',name='Ouroboros descriptions',exact=True).click();page.wait_for_timeout(150)
assert canvas.get_attribute('data-annotation-progress')=='1.0000'
motion_click(page,'Resume page animations')
for width,height in [(1280,720),(390,844),(320,844)]:
page.set_viewport_size({'width':width,'height':height})
if width>1100:
at(page,.967);no_overlap(page);page.screenshot(path=str(OUT/'laptop-sharing.png'))
else:
scroll(page,'#dual-step-3');page.screenshot(path=str(OUT/f'mobile-{width}-residues.png'))
assert len(page.locator('.reading-residue-output>span').all())==72
scroll(page,'#dual-step-6');page.screenshot(path=str(OUT/f'mobile-{width}-sharing.png'))
for selector,name in [('#atlas','atlas-coverage'),('.atlas-preview-layout','atlas-map'),('#evidence','benchmark')]:
scroll(page,selector)
assert page.evaluate('document.documentElement.scrollWidth<=innerWidth'), (width,selector)
if width==390: page.screenshot(path=str(OUT/f'mobile-{name}.png'))
page.emulate_media(reduced_motion='reduce');scroll(page,'.atlas-preview-layout')
m.get_by_role('button',name='Swiss-Prot overlap',exact=True).click();m.get_by_role('button',name='Ouroboros descriptions',exact=True).click()
assert canvas.get_attribute('data-annotation-progress')=='1.0000'
assert not errors,errors
assert not failed,failed
browser.close()
report={'checks':['Only 500-pair Swiss-Prot time-cutoff data across all metrics and downloads','Text and protein self-attention pairs highlight independently, rewind deterministically and support direct selection','72 exact residues in 26x28 tiles','Full-corpus 0.295% reference overlap and 51.17M beyond reference','Atlas description reveal, pause/resume, direct selection while paused and reduced motion','Desktop, 1280x720 laptop, 390px and 320px containment'],'page_errors':errors,'http_errors':failed}
(OUT/'refinements-report.json').write_text(json.dumps(report,indent=2)+'\n')
print(json.dumps(report,indent=2))