VEHwang's picture
Upload CoCogni4D-Bench (questions, media, scripts, render records, code) (part 6)
5afd2f7 verified
Raw History Blame Contribute Delete
4.07 kB
"""JSON-only adapter executed by the configured generator interpreter."""
import json
import argparse
import sys
import traceback
def schema():
from embodied_pipeline.gen import appearance, config
implemented = []
for flavor in config.FLAVORS:
try:
config.load({'scene': 's', 'seed': 0, 'cast': [], 'flavor': flavor})
except config.ConfigError as exc:
if 'not implemented' in str(exc):
continue
implemented.append(flavor)
moving = []
for mode in config.MOTION_MODES: # follow is in the vocabulary but config.load refuses it: offer only what generates
try:
config.load({'scene': 's', 'seed': 0, 'cast': [], 'observers': [{**config.DEFAULT_OBSERVER, 'id': 'o', 'motion_mode': mode}]})
except config.ConfigError as exc:
if 'not implemented' in str(exc):
continue
moving.append(mode)
# Known editable constraints; the generator remains the validator.
arrangements = {t: n for t, n in config.ARRANGEMENTS.items() if t not in config.RETIRED}
fields = {'stop_at': {'where': {'type': 'location'}, 'dwell_s': {'type': 'number', 'min': 0}},
'meet': {'where': {'type': 'location'}, 'dwell_s': {'type': 'number', 'min': 0}},
'covisible_event': {'event': {'type': 'enum', 'values': ['dynamic']}},
'observer_body': {'times': {'type': 'fixed', 'value': 1}}, 'covisible_region': {}}
from np.planning import GENERATOR_TYPE_LABELS
return {
'schema': 'np-gen-schema/1',
'keys': {key: sorted(value) for key, value in config.KEYS.items()},
'flavors': list(config.FLAVORS), 'implemented_flavors': implemented,
'observer_kinds': config.OBS_KINDS, 'motion_modes': list(config.MOTION_MODES),
'implemented_motion_modes': moving, 'arrangement_labels': {t: GENERATOR_TYPE_LABELS.get(t, t) for t in arrangements},
'view_modes': list(config.VIEW_MODES), 'arrangements': arrangements,
'arrangement_fields': {t: fields[t] for t in arrangements},
'recording_keys': ['length_frac', 'link_overlap_frac', 'split_frac', 'split_excl_frac', 'split_offset_max_frac', 'max_shared'],
'bodies': config.BODIES, 'profiles': config.PROFILES,
'profile_keys': list(config.PROFILE_KEYS), 'default_profile': config.DEFAULT_PROFILE,
'default_observer': config.DEFAULT_OBSERVER,
'dist_kinds': ['fixed', 'uniform', 'normal', 'lognormal', 'choice', 'mixture'],
'max_humans': appearance.MAX_HUMANS,
}
def expand(batch, capability_root=None):
from embodied_pipeline.gen import config, expand as generator_expand
configs, selection = [], {}
for raw in generator_expand.expand(batch, selection=selection, capability_root=capability_root):
try:
configs.append({'config': config.load(raw), 'errors': []})
except config.ConfigError as exc:
configs.append({'config': raw, 'errors': [str(exc)]})
return {'count': len(configs), 'configs': configs, 'structural_selection': selection}
def load(raw):
from embodied_pipeline.gen import config
try:
return {'config': config.load(raw), 'errors': []}
except config.ConfigError as exc:
return {'config': raw, 'errors': [str(exc)]}
if __name__ == '__main__':
try:
parser = argparse.ArgumentParser()
parser.add_argument('mode', choices=['schema', 'expand', 'load'])
parser.add_argument('--capability-root')
args = parser.parse_args()
mode = args.mode
if mode == 'schema':
result = schema()
elif mode == 'expand':
result = expand(json.load(sys.stdin), capability_root=args.capability_root)
elif mode == 'load':
result = load(json.load(sys.stdin))
else:
raise ValueError('unknown bridge mode: ' + mode)
print(json.dumps(result, ensure_ascii=False, allow_nan=False))
except Exception:
traceback.print_exc(file=sys.stderr)
sys.exit(2)