Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/openaccel-lab/blob/main/oal/ref.py # openaccel-lab aien-dev/openaccel-lab Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `openaccel-lab / oal / ref.py` 40 lines ยท 1506 bytes Raw Blame History 1 # SPDX-License-Identifier: Apache-2.0 2 """Independent reference: workloads//reference.py defines reference(p, x) -> {output: value or 3 (value, scale)}, computed in float64 numpy from the exact input values. The reference is the oracle, 4 not an entrant; it never appears on the board as a backend. A control may borrow the reference of 5 the workload it breaks with "reference_from". 6 """ 7 import importlib.util 8 import os 9 10 import numpy as np 11 12 from . import manifest 13 14 15 def load(m): 16 src_name = m.get("reference_from", m["name"]) 17 d = manifest.workload_dir(src_name) 18 path = os.path.join(d, "reference.py") 19 spec = importlib.util.spec_from_file_location("oal_ref_" + src_name, path) 20 mod = importlib.util.module_from_spec(spec) 21 spec.loader.exec_module(mod) 22 return mod.reference 23 24 25 def compute(m, params, inputs): 26 fn = load(m) 27 x = {k: np.asarray(v) for k, v in inputs.items()} 28 out = fn(dict(params), x) 29 refs = {} 30 for spec in m["outputs"]: 31 v = out[spec["name"]] 32 if isinstance(v, tuple): 33 refs[spec["name"]] = (np.asarray(v[0], dtype=np.float64), np.asarray(v[1], dtype=np.float64)) 34 else: 35 refs[spec["name"]] = (np.asarray(v, dtype=np.float64), None) 36 want = tuple(manifest.shape(spec, params)) 37 if refs[spec["name"]][0].shape != want: 38 raise ValueError("%s reference %s has shape %s, manifest says %s" % ( 39 m["name"], spec["name"], refs[spec["name"]][0].shape, want)) 40 return refs