Files
MeltMind/tools/prepare_track_b_h2_pressure_combined.py
T

55 lines
2.2 KiB
Python

"""Freeze H2-P comparison metadata and audit only original triangle mesh members."""
from pathlib import Path
from tempfile import TemporaryDirectory
from zipfile import ZipFile
import torch
import track_b_h2_pressure_entry as entry
from track_b_gino_paper_keyword_patch import extract_patched_paper_code
from track_b_gino_shapenet_entry import read, save
from track_b_h2_pressure_worker import SurfaceData, mesh_graph
def prepare():
c = entry.reference.contract()
entry.ROOT.mkdir(exist_ok=False)
torch.set_num_threads(1)
with TemporaryDirectory(prefix='h2-p-mesh-only-') as folder:
extract_patched_paper_code(c, folder)
path = Path(folder)
data = SurfaceData(c, path)
rows = []
class MeshOnly:
def __init__(self, archive):
self.archive = archive
def read(self, member):
if not member.startswith('car-pressure-data/data/mesh_') or not member.endswith('.ply'):
raise PermissionError('Preparation may only open original meshes')
return self.archive.read(member)
with ZipFile(c['paper_data']['path']) as archive:
for case in data.train_ids + data.test_ids:
graph, faces = mesh_graph(c, path, MeshOnly(archive), data.rows[case], data.paper)
x, mass, receivers, _, _, components = graph
rows.append(dict(case=case, vertices=len(x), faces=faces,
edge_count=len(receivers), components=int(components.max()) + 1,
total_positive_area=float(mass.double().sum())))
save(entry.ROOT/'geometry-audit.json', dict(status='PASS', mesh_members_opened=len(rows),
target_members_opened=0, actual_gpu_queries=0, rows=rows))
save(entry.ROOT/'comparison-contract.json', entry.expected_comparison(c))
save(entry.ROOT/'contract.json', entry.expected_contract())
assert entry.contract()['identity'] == 'H2-P'
print(f'{len(rows)} original shape meshes audited, zero pressure members')
if __name__ == '__main__':
import os
if os.environ.get('CUDA_VISIBLE_DEVICES') != '':
raise PermissionError('Preparation is CPU only')
prepare()