feat: checkpoint Go2 FL simulation performance v0.4.2

Include callable skill and live-GUI prerequisites, epoch sensor reads, packed snapshots, sampled bit-exact kinematics, and verified-tick rendering without changing the physical/control schedule.

Record bounded analytic S1 GUI/headless qualification, original failures and CPU evidence (1557 passed, 6 skipped). Preserve accepted_skill=false and sub-real-time limitations. Exclude native authorities, caches, large media and local delivery copies; retain sealed artifact digest.
This commit is contained in:
2026-10-16 15:46:01 +08:00
parent 9fe9d27865
commit c528dd268f
136 changed files with 15553 additions and 15 deletions
@@ -0,0 +1,101 @@
"""Finite config/source binding for the separately approved functional campaign.
Reuse installed provenance primitives, never P1/P2/RootXY grants or protocol
admission. Preparation constructs config only; no environment or physics.
"""
from pathlib import Path
FORMAT = 'skillfactory.contact-cycle-functional-binding.v2'
SCRIPT = 'scripts/evaluate_cycle_functional_flow.py'
ROLES = (
'SkillFactory.legs.contact_cycle_sim.functional_flow_v2',
'SkillFactory.legs.contact_cycle_sim.functional_flow_binding_v2',
'SkillFactory.tasks.manager_based.contact_cycle_sim.functional_flow_recording_v2',
'SkillFactory.tasks.manager_based.contact_cycle_sim.evaluation_cfg',
'SkillFactory.tasks.manager_based.contact_cycle_sim.evaluation_env',
'SkillFactory.tasks.manager_based.contact_cycle_sim.evaluation_mdp',
'SkillFactory.tasks.manager_based.contact_cycle_sim.recording',
'SkillFactory.legs.contact_cycle_sim.replay',
'audit_contact_cycle_functional', 'evaluate_cycle_sim_residual',
'functional_flow_launch_v2', 'rootxy_launch_v2', '__main__',
)
def components(root, cfg, *, extra_roles=(), main_script=SCRIPT):
from . import evaluation_binding as b
root = Path(root)
names, records = set((*ROLES, *extra_roles)), {}
for name in (*ROLES, *extra_roles):
path = b._module_file(name)
expected = (root / 'source/SkillFactory' / (name.replace('.', '/') + '.py')
if name.startswith('SkillFactory.') else
root / (main_script if name == '__main__' else 'scripts/' + name + '.py'))
if path != expected:
raise ValueError('Functional source role mismatch: ' + name)
records[name] = {'path': str(path), 'sha256': b.sha256(path.read_bytes())}
roles = set(names)
encoded = b._encode(cfg, names, set())
imports = b._imports(names, root)
return b, records, roles, encoded, imports
def propose_inventory(root, cfg, native_layouts, *, extra_roles=(), main_script=SCRIPT):
b, _, roles, _, imports = components(root, cfg, extra_roles=extra_roles, main_script=main_script)
modules = {n: b._dependency_module_identity(n)
for n in sorted(b.required_dependencies(set(imports), roles))}
roots = {n: Path(modules[n]['path']).parent for n in b.NUMERICAL_ROOTS}
artifacts = {}
def add(path, owner, vendor=False):
path = b._file(path)
if str(path) in artifacts:
raise ValueError('Duplicate native artifact')
artifacts[str(path)] = {'module': owner, 'path': str(path),
'sha256': b.sha256(path.read_bytes()),
'purpose': 'Installed numerical implementation consumed by ' + owner}
if vendor:
artifacts[str(path)]['vendor'] = 'NVIDIA'
for owner, directories in native_layouts(roots).items():
for directory in directories:
files = sorted(directory.glob('*.so*'))
if not files:
raise ValueError('Missing native layout: ' + str(directory))
for path in files:
add(path, owner)
if (roots['torch'] / 'lib/libtorch_cuda.so').is_file():
for package in b.NVIDIA_CUDA_PACKAGES:
for path in sorted((roots['torch'].parent / 'nvidia' / package / 'lib').glob('*.so*')):
add(path, 'torch', True)
return b._dependency_inventory({'scope': b.INVENTORY_SCOPE, 'modules': modules,
'artifacts': artifacts}, set(imports), roles)
def snapshot(root, cfg, inventory):
from .functional_flow_v2 import load_contract
from .replay import verify_bundle
from SkillFactory.tasks.manager_based.contact_cycle_sim.evaluation_cfg import EvaluationContactCycleEnvCfg
b, records, roles, encoded, imports = components(root, cfg)
if (type(cfg) is not EvaluationContactCycleEnvCfg or cfg.scene.num_envs != 1
or type(cfg.seed) is not int or cfg.seed != 93501 or cfg.sim.device != 'cuda:0'
or cfg.sim.dt != .002 or cfg.decimation != 5 or b._normalization_updates(cfg)):
raise ValueError('Functional actual config/normalization mismatch')
path = Path(root) / 'configs/contact_cycle/functional_flow_v2.json'
contract = load_contract(path)
_, frozen = verify_bundle(root)
return {'format': FORMAT, 'root': str(root), 'effective_config': encoded,
'sources': records, 'imports': imports, 'contract': contract,
'contract_sha256': b.sha256(path.read_bytes()),
'dependency_inventory': b._dependency_inventory(inventory, set(imports), roles),
'runtime_layout_pins': dict(b.RUNTIME_LAYOUT_PINS),
'required_runtime_roles': dict(b.REQUIRED_RUNTIME), 'frozen_policy': frozen,
'scope': b.PROVENANCE_SCOPE, 'limitations': b.PROVENANCE_LIMITATIONS,
'execution_authorized': False, 'optimizer_steps': 0, 'accepted_skill': False}
def verify(expected, root, cfg, inventory):
from . import evaluation_binding as b
actual = snapshot(root, cfg, inventory)
if b.canonical_json(actual) != b.canonical_json(expected):
raise b.BindingMismatchError(b.canonical_json(expected), b.canonical_json(actual))
return actual
@@ -0,0 +1,80 @@
"""Independent function-first protocol; no Kit, optimizer, or execution grant.
Reuse the P1 integer clocks/A-B-A-B command math, NOT P1 precision margins.
The existing no-autoreset EvaluationContactCycleEnv accepts this descriptor.
Its original phase rules and all safety floors remain unchanged initially.
"""
import json
from pathlib import Path
from .evaluation_protocol import Protocol, Trial, _freeze
FORMAT = 'skillfactory.contact-cycle-functional-flow.v2'
CONTROLLERS = ('analytic_reference', 'learned_policy')
def load_contract(path):
def unique(pairs):
result = {}
for key, value in pairs:
if key in result:
raise ValueError('Duplicate contract key: ' + key)
result[key] = value
return result
return validate_contract(json.loads(Path(path).read_text(), object_pairs_hook=unique))
def validate_contract(cfg):
# Do not silently accept a new task, phase schedule, fixture or tuned gate.
from .evaluation_protocol import _FUNCTIONAL_GATES
expected = {
'format': FORMAT,
'status': 'prospective_functional_development_not_independent_acceptance',
'execution_authorized': False,
'optimizer_steps': 0,
'num_envs': 1,
'seed': 93501,
'physics_dt_s': 0.002,
'control_ticks': 5,
'phase_durations_s': [3.0, 1.0, 0.6, 1.4, 0.8, 2.2],
'cycles_allowed': [1, 3],
'swing_displacement_m': [0.025, 0.020, 0.0],
'anchor_sequence': ['A', 'B', 'A', 'B'],
'functional_gates': _FUNCTIONAL_GATES,
'diagnostics_only': ['root_xy_error', 'root_xy_drift', 'stance_slip',
'landing_accuracy_beyond_functional_gate'],
'runtime': 'EvaluationContactCycleEnv_no_autoreset_original_phase_safety',
'phase_rule_changes': [],
'fixture_changes': [],
}
from .evaluation_protocol import _match
_match(cfg, expected, 'functional_flow_v2')
return cfg
class FunctionalFlowProtocol(Protocol):
"""A distinct protocol, never admitted through the old P1/P2 authorization.
Construction only prepares metadata. A fresh functional runner/binding and
explicit new budget are still required; old evaluators reject this format.
"""
def __init__(self, cfg, *, cycles, controller_kind):
validate_contract(cfg)
if type(cycles) is not int or cycles not in cfg['cycles_allowed']:
raise ValueError('Require one cycle or three continuous cycles')
if controller_kind not in CONTROLLERS:
raise ValueError('Explicit controller kind required')
if cfg['format'] != FORMAT or cfg['execution_authorized'] is not False:
raise ValueError('Not a prospective functional contract')
document = {
'format': FORMAT, 'stage': 'FUNCTIONAL_V2', 'events': [],
'thresholds': {'functional': cfg['functional_gates']},
'execution_authorized': False, 'optimizer_steps': 0,
}
pair = f'FUNCTIONAL_V2/{cycles}-cycle/{cfg["seed"]}'
trial = Trial(0, f'{pair}/{controller_kind}', pair, 'nominal', cfg['seed'],
controller_kind, 0, tuple(cfg['swing_displacement_m']), (),
tuple(cfg['anchor_sequence'][:cycles + 1]))
object.__setattr__(self, 'document', _freeze(document))
object.__setattr__(self, 'trials', (trial,))
@@ -0,0 +1,50 @@
"""New finite binding for the followup; neither old binding nor plan is a grant."""
from pathlib import Path
from . import functional_flow_binding_v2 as base
FORMAT = 'skillfactory.functional-followup-binding.v3'
EXTRA_ROLES = ('SkillFactory.legs.contact_cycle_sim.functional_followup_v3',
'SkillFactory.legs.contact_cycle_sim.functional_followup_binding_v3',
'functional_followup_launch_v3', 'functional_gpu_watch_v3')
def propose_inventory(root, cfg, native_layouts):
return base.propose_inventory(root, cfg, native_layouts, extra_roles=EXTRA_ROLES)
def snapshot(root, cfg, inventory):
from .functional_followup_v3 import load_plan, PLAN_PATH
from .functional_flow_v2 import load_contract
from .replay import verify_bundle
from SkillFactory.tasks.manager_based.contact_cycle_sim.evaluation_cfg import EvaluationContactCycleEnvCfg
b, records, roles, encoded, imports = base.components(root, cfg, extra_roles=EXTRA_ROLES)
if (type(cfg) is not EvaluationContactCycleEnvCfg or cfg.scene.num_envs != 1
or type(cfg.seed) is not int or cfg.seed != 93501 or cfg.sim.device != 'cuda:0'
or cfg.sim.dt != .002 or cfg.decimation != 5 or b._normalization_updates(cfg)):
raise ValueError('Followup actual config/normalization mismatch')
root = Path(root)
plan_path = root / PLAN_PATH
plan = load_plan(plan_path)
contract_path = root / plan['base_contract']
if b.sha256(contract_path.read_bytes()) != plan['base_contract_sha256']:
raise ValueError('Base contract identity drift')
contract = load_contract(contract_path)
_, frozen = verify_bundle(root)
return {'format': FORMAT, 'root': str(root), 'effective_config': encoded,
'sources': records, 'imports': imports, 'contract': contract,
'contract_sha256': plan['base_contract_sha256'], 'plan': plan,
'plan_sha256': b.sha256(plan_path.read_bytes()),
'dependency_inventory': b._dependency_inventory(inventory, set(imports), roles),
'runtime_layout_pins': dict(b.RUNTIME_LAYOUT_PINS),
'required_runtime_roles': dict(b.REQUIRED_RUNTIME), 'frozen_policy': frozen,
'scope': b.PROVENANCE_SCOPE, 'limitations': b.PROVENANCE_LIMITATIONS,
'execution_authorized': False, 'optimizer_steps': 0, 'accepted_skill': False}
def verify(expected, root, cfg, inventory):
from . import evaluation_binding as b
actual = snapshot(root, cfg, inventory)
if b.canonical_json(actual) != b.canonical_json(expected):
raise b.BindingMismatchError(b.canonical_json(expected), b.canonical_json(actual))
return actual
@@ -0,0 +1,97 @@
"""Frozen small interpolation matrix; pure metadata, never a run authorization."""
import json
import math
from pathlib import Path
from .evaluation_protocol import Protocol, Trial, _freeze, _match
from .functional_flow_v2 import CONTROLLERS, validate_contract
FORMAT = 'skillfactory.functional-followup.v3'
PLAN_PATH = 'configs/contact_cycle/functional_followup_v3.json'
BASE_SHA256 = '16c064228b30f36bbd420b7c2290602bacae6601cac2cec5deb16440f7600625'
def expected_plan():
return {
'format': FORMAT, 'status': 'prospective_finite_functional_development',
'execution_authorized': False, 'accepted_skill': False, 'optimizer_steps': 0,
'base_contract': 'configs/contact_cycle/functional_flow_v2.json',
'base_contract_sha256': BASE_SHA256, 'seed': 93501, 'cycles_per_run': 3,
'anchor_sequence': ['A', 'B', 'A', 'B'],
'direction_xy_ratios': {'x_bias': [25, 10], 'baseline_direction': [25, 20], 'y_bias': [15, 20]},
'amplitudes_m': [0.016, 0.024],
'direction_order': ['x_bias', 'baseline_direction', 'y_bias'],
'controller_order': ['analytic_reference', 'learned_policy'],
'nominal_requalification_first': 'learned_policy_only_0.025_0.020',
'matrix_scope': 'inside_previous_component_command_envelope_not_previously_validated_every_direction',
'pairing': 'reference_initial_record_then_exact_u256_check_before_first_rollout_step',
'pairing_scope': 'recorded_tensors_RNG_IK_commands_not_complete_native_solver_state',
'failure_policy': 'first_any_failure_stop_no_retry_remaining_not_run',
'perturbations': [], 'noise': False, 'morphology_changes': [],
'functional_or_safety_changes': [], 'fixture_changes': [],
'limits': {
'max_prepare_launches': 1, 'max_physical_launches': 13,
'max_rollout_calls': 175500, 'max_physics_calls': 178750,
'max_initialization_calls_per_launch': 250,
'max_prepare_seconds': 300, 'max_physical_seconds': 480, 'cleanup_seconds': 120,
'max_campaign_seconds': 6540, 'max_owned_bytes': 2147483648,
'num_envs': 1, 'optimizer_steps': 0, 'retry_or_resume': False,
},
}
def validate_plan(plan):
_match(plan, expected_plan(), 'functional_followup_v3')
return plan
def load_plan(path):
def unique(pairs):
result = {}
for k, v in pairs:
if k in result:
raise ValueError('Duplicate plan key: ' + k)
result[k] = v
return result
return validate_plan(json.loads(Path(path).read_text(), object_pairs_hook=unique))
def commands(plan):
validate_plan(plan)
result = {'validated_nominal': (0.025, 0.020, 0.0)}
for direction in plan['direction_order']:
x, y = plan['direction_xy_ratios'][direction]
norm = math.hypot(x, y)
for amplitude in plan['amplitudes_m']:
name = f'{direction}-{round(amplitude * 1000)}mm'
result[name] = (amplitude * x / norm, amplitude * y / norm, 0.0)
return result
def slots(plan):
table = commands(plan)
result = [{'slot': 'prepare', 'cycles': 0, 'controller_kind': None, 'command_id': None, 'pair_group': None},
{'slot': 'u256-nominal-3', 'cycles': 3, 'controller_kind': 'learned_policy',
'command_id': 'validated_nominal', 'pair_group': None}]
for name in list(table)[1:]:
for kind in plan['controller_order']:
suffix = 'reference' if kind == 'analytic_reference' else 'u256'
result.append({'slot': name + '-' + suffix, 'cycles': 3, 'controller_kind': kind,
'command_id': name, 'pair_group': name})
return result
class FollowupProtocol(Protocol):
def __init__(self, base, plan, command_id, controller_kind):
validate_contract(base)
validate_plan(plan)
if controller_kind not in CONTROLLERS or command_id not in commands(plan):
raise ValueError('Unknown frozen controller or command')
pair = f'FUNCTIONAL_FOLLOWUP_V3/{command_id}/{plan["seed"]}'
document = {'format': FORMAT, 'stage': 'FUNCTIONAL_FOLLOWUP_V3', 'events': [],
'thresholds': {'functional': base['functional_gates']},
'execution_authorized': False, 'optimizer_steps': 0}
trial = Trial(0, pair + '/' + controller_kind, pair, command_id, plan['seed'], controller_kind,
0, commands(plan)[command_id], (), tuple(plan['anchor_sequence']))
object.__setattr__(self, 'document', _freeze(document))
object.__setattr__(self, 'trials', (trial,))
@@ -0,0 +1,73 @@
"""v4 actual-config/source binding; immutable functional gates, never a grant."""
from pathlib import Path
from . import functional_flow_binding_v2 as base
FORMAT = 'skillfactory.go2-fl-skill-binding.v4'
MAIN_SCRIPT = 'scripts/go2_fl_skill.py'
EXTRA_ROLES = ('SkillFactory.legs.contact_cycle_sim.skill_v4',
'SkillFactory.legs.contact_cycle_sim.skill_mailbox_v4',
'SkillFactory.legs.contact_cycle_sim.skill_binding_v4',
'SkillFactory.tasks.manager_based.contact_cycle_sim.skill_recording_v4',
'SkillFactory.tasks.manager_based.contact_cycle_sim.skill_gui_v041',
'SkillFactory.tasks.manager_based.contact_cycle_sim.performance_v042',
'SkillFactory.tasks.manager_based.contact_cycle_sim.sensor_epoch_v042',
'SkillFactory.tasks.manager_based.contact_cycle_sim.packed_recording_v042',
'SkillFactory.tasks.manager_based.contact_cycle_sim.readonly_scope_v042',
'SkillFactory.tasks.manager_based.contact_cycle_sim.batched_kinematics_v042',
'SkillFactory.tasks.manager_based.contact_cycle_sim.live_cadence_v042',
'skill_launch_v4', 'evaluate_cycle_functional_flow',
'SkillFactory.legs.contact_cycle_sim.functional_followup_v3',
'SkillFactory.legs.contact_cycle_sim.functional_followup_binding_v3',
'functional_followup_launch_v3', 'functional_gpu_watch_v3')
def propose_inventory(root, cfg, native_layouts):
return base.propose_inventory(root, cfg, native_layouts, extra_roles=EXTRA_ROLES, main_script=MAIN_SCRIPT)
def snapshot(root, cfg, inventory):
from .functional_followup_v3 import load_plan, PLAN_PATH
from .functional_flow_v2 import load_contract
from .replay import verify_bundle
from SkillFactory.tasks.manager_based.contact_cycle_sim.evaluation_cfg import EvaluationContactCycleEnvCfg
b, records, roles, encoded, imports = base.components(root, cfg, extra_roles=EXTRA_ROLES, main_script=MAIN_SCRIPT)
if (type(cfg) is not EvaluationContactCycleEnvCfg or cfg.scene.num_envs != 1
or type(cfg.seed) is not int or cfg.seed != 93501 or cfg.sim.device != 'cuda:0'
or cfg.sim.dt != .002 or cfg.decimation != 5 or b._normalization_updates(cfg)):
raise ValueError('Skill v4 actual config/normalization mismatch')
root = Path(root)
plan_path = root / PLAN_PATH
plan = load_plan(plan_path)
contract_path = root / plan['base_contract']
if b.sha256(contract_path.read_bytes()) != plan['base_contract_sha256']:
raise ValueError('Base contract identity drift')
contract = load_contract(contract_path)
_, frozen = verify_bundle(root)
from SkillFactory.tasks.manager_based.contact_cycle_sim.performance_v042 import options, CONFIG
performance = options(root)
from SkillFactory.tasks.manager_based.contact_cycle_sim import performance_v042 as perf
if performance['mode'] in ('combined', 'combined_display') and perf.RUNTIME_MATH_QUALIFICATION is None:
raise ValueError('Combined mode requires exact runtime math qualification record')
return {'performance_options': performance,
'runtime_math_qualification': perf.RUNTIME_MATH_QUALIFICATION,
'performance_config_sha256': b.sha256((root / CONFIG).read_bytes()),
'performance_plan_sha256': b.sha256((root / 'performance_v042/plan.md').read_bytes()),
'format': FORMAT, 'root': str(root), 'effective_config': encoded,
'sources': records, 'imports': imports, 'contract': contract,
'contract_sha256': plan['base_contract_sha256'], 'plan': plan,
'plan_sha256': b.sha256(plan_path.read_bytes()),
'v4_plan_sha256': b.sha256((root / 'docs/contact_cycle_sim_skill_v4_plan.md').read_bytes()),
'dependency_inventory': b._dependency_inventory(inventory, set(imports), roles),
'runtime_layout_pins': dict(b.RUNTIME_LAYOUT_PINS),
'required_runtime_roles': dict(b.REQUIRED_RUNTIME), 'frozen_policy': frozen,
'scope': b.PROVENANCE_SCOPE, 'limitations': b.PROVENANCE_LIMITATIONS,
'execution_authorized': False, 'optimizer_steps': 0, 'accepted_skill': False}
def verify(expected, root, cfg, inventory):
from . import evaluation_binding as b
actual = snapshot(root, cfg, inventory)
if b.canonical_json(actual) != b.canonical_json(expected):
raise b.BindingMismatchError(b.canonical_json(expected), b.canonical_json(actual))
return actual
@@ -0,0 +1,87 @@
"""Bounded atomic single-outstanding-request mailbox; no Kit imports."""
import json
import os
from pathlib import Path
import uuid
MAX_BYTES = 16384
def read_json(path):
path = Path(path)
if path.is_symlink() or path.stat().st_size > MAX_BYTES:
raise ValueError('Unsafe/oversized mailbox file')
return json.loads(path.read_text())
def publish(path, value):
path = Path(path)
raw = json.dumps(value, allow_nan=False, separators=(',', ':')).encode()
if len(raw) > MAX_BYTES or path.is_symlink():
raise ValueError('Unsafe/oversized mailbox publication')
temporary = path.with_name(path.name + '.' + uuid.uuid4().hex + '.pending')
with temporary.open('xb') as stream:
stream.write(raw)
stream.flush()
os.fsync(stream.fileno())
os.replace(temporary, path)
def send(directory, operation, command=None):
from .skill_v4 import validate_command
if operation not in ('queue', 'stop') or (operation == 'stop' and command is not None):
raise ValueError('Invalid operation')
if operation == 'queue':
validate_command(command) # invalid input causes zero filesystem mutation
directory = Path(directory)
status = read_json(directory / 'status.json')
if status.get('state') not in ('starting', 'running'):
raise RuntimeError('Skill is not live')
if status.get('receipts_count', 0) >= 64:
raise RuntimeError('Receipt capacity exhausted')
lock = directory / 'request.lock'
fd = os.open(lock, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o600)
os.close(fd)
request = {'id': uuid.uuid4().hex, 'operation': operation}
if command is not None:
request['command'] = command
try:
publish(directory / 'request.json', request)
except BaseException:
lock.unlink()
raise
return request['id']
def consume(directory, session, tick):
directory = Path(directory)
path = directory / 'request.json'
if not path.exists():
return None
if len(session.receipts) >= 64:
raise RuntimeError('budget_live_receipts_cap')
request = None
before = (session.active, list(session.pending), session.stop_requested, dict(session.pair_commands))
try:
if path.stat().st_size > 1024:
raise ValueError('Oversized command request')
request = read_json(path)
if (type(request) is not dict or type(request.get('id')) is not str
or len(request['id']) != 32):
raise ValueError('Invalid request identity')
operation = request.get('operation')
if operation == 'queue' and set(request) == {'id', 'operation', 'command'}:
session.queue(request['command'])
elif operation == 'stop' and set(request) == {'id', 'operation'}:
session.request_stop()
else:
raise ValueError('Invalid request fields/operation')
receipt = {'request': request, 'received_tick': tick, 'accepted': True}
except (ValueError, TypeError, KeyError) as error:
assert before == (session.active, session.pending, session.stop_requested, session.pair_commands)
receipt = {'request': request, 'received_tick': tick, 'accepted': False, 'error': str(error)}
session.receipts.append(receipt)
publish(directory / 'receipt.json', receipt)
path.unlink()
(directory / 'request.lock').unlink(missing_ok=True)
return receipt
@@ -0,0 +1,88 @@
"""Finite Go2 FL world-XY skill metadata/session. No Kit or tensor imports.
Only command metadata changes at admitted A endpoints. Trajectory math remains
Protocol.command; the B of an outbound/return pair is never changed mid-pair.
"""
from dataclasses import replace
from .evaluation_protocol import Protocol, Trial, _freeze, CYCLE_TICKS
from .functional_flow_v2 import validate_contract
from .functional_followup_v3 import commands, expected_plan
FORMAT = 'skillfactory.go2-fl-skill.v4'
COMMANDS = commands(expected_plan())
SEQUENCES = {
'nominal20': ('validated_nominal',),
'S1': ('x_bias-16mm', 'baseline_direction-24mm', 'y_bias-16mm'),
'S2': ('y_bias-24mm', 'x_bias-24mm', 'baseline_direction-16mm'),
'S3': ('baseline_direction-24mm', 'y_bias-24mm', 'x_bias-16mm'),
}
CONTROLLERS = {'analytic': 'analytic_reference', 'u256': 'learned_policy'}
def validate_command(command):
if type(command) is not str or command not in COMMANDS:
raise ValueError('Require nominal or one of the six fixed direction/amplitude command IDs')
return command
def validate_request(command, cycles, controller):
validate_command(command)
if type(cycles) is not int or not 1 <= cycles <= 20:
raise ValueError('cycles must be an integer in 1..20')
if type(controller) is not str or controller not in CONTROLLERS:
raise ValueError('controller must be analytic or u256')
class SkillSession:
"""Single runtime writer; at most ten pending pairs and 64 live receipts."""
def __init__(self, command, cycles, controller, queued=()):
validate_request(command, cycles, controller)
queued = tuple(validate_command(c) for c in queued)
if len(queued) > 10:
raise ValueError('Queue capacity is ten commands')
self.cycles, self.controller = cycles, controller
self.active, self.pending = command, list(queued)
self.pair_commands = {0: command}
self.stop_requested = False
self.receipts = []
def queue(self, command):
validate_command(command) # before any mutation, including receipt/queue
if len(self.pending) >= 10:
raise ValueError('Queue full')
self.pending.append(command)
def request_stop(self):
self.stop_requested = True
def admit_endpoint(self, completed_cycles):
if type(completed_cycles) is not int or not 1 <= completed_cycles <= self.cycles:
raise ValueError('Invalid endpoint')
if completed_cycles % 2 == 0 and completed_cycles < self.cycles:
if self.pending:
self.active = self.pending.pop(0)
self.pair_commands[completed_cycles // 2] = self.active
class SkillProtocol(Protocol):
def __init__(self, base, session):
validate_contract(base)
trial = Trial(0, 'SKILL_V4/' + session.controller, 'SKILL_V4', session.active, 93501,
CONTROLLERS[session.controller], 0, COMMANDS[session.active], (),
tuple('A' if i % 2 == 0 else 'B' for i in range(session.cycles + 1)))
object.__setattr__(self, 'document', _freeze({
'format': FORMAT, 'stage': 'SKILL_V4', 'events': [],
'thresholds': {'functional': base['functional_gates']},
'execution_authorized': False, 'optimizer_steps': 0}))
object.__setattr__(self, 'trials', (trial,))
object.__setattr__(self, 'session', session)
def command(self, trial_index, clock, **kwargs):
self.trial(trial_index)
command = self.session.pair_commands[clock.cycle_index // 2]
# Use the existing exact command implementation with a per-pair descriptor.
descriptor = object.__new__(Protocol)
object.__setattr__(descriptor, 'document', self.document)
object.__setattr__(descriptor, 'trials', (replace(self.trials[0], swing_displacement_m=COMMANDS[command]),))
return Protocol.command(descriptor, trial_index, clock, **kwargs)
@@ -0,0 +1,53 @@
"""Batch the SAME six finite-difference FK evaluations, no IK parameter change.
Qualification uses pure tensor math in PREP, not an environment or physics.
An inexact sampled CUDA comparison is explicitly rejected for this optional
optimization; original Jacobian remains selected and the decision is recorded.
"""
from types import SimpleNamespace, MethodType
import torch
from SkillFactory.legs.contact_cycle_sim.reference import ReferenceController
def jacobian(controller, q):
eps = controller.cfg['jacobian_epsilon_rad']
delta = torch.eye(3, device=q.device, dtype=q.dtype) * eps
probes = torch.cat((q[:, None, :] + delta[None], q[:, None, :] - delta[None]), dim=1)
foot = controller.foot(probes.reshape(-1, 3)).reshape(len(q), 6, 3)
return ((foot[:, :3] - foot[:, 3:]) / (2 * eps)).transpose(-1, -2).contiguous()
def same_bits(left, right):
if (left.dtype != torch.float32 or right.dtype != torch.float32
or left.shape != right.shape or left.device != right.device):
return False
return torch.equal(left.contiguous().view(torch.int32), right.contiguous().view(torch.int32))
def qualify(bundle, cfg, nominal, device):
s = SimpleNamespace(bundle=bundle, nominal=nominal,
env=SimpleNamespace(device=device, num_envs=1))
controller = ReferenceController(s, cfg)
offsets = torch.linspace(-.5, .5, 33, device=device)
equal = True
maximum = 0.
# B=1 is the actual execution shape; B>1 here is math only, no extra envs.
for offset in offsets:
q = nominal.reshape(1, 3) + offset
old = ReferenceController.jacobian(controller, q)
new = jacobian(controller, q)
finite = bool(torch.isfinite(old).all() and torch.isfinite(new).all())
if not finite:
raise ValueError('nonfinite_jacobian_math_qualification')
equal = equal and same_bits(old, new)
maximum = max(maximum, float((old - new).abs().max()))
return {'qualification': 'sampled same-device same-dtype original-vs-batched math; not all-input proof',
'samples': len(offsets), 'all_bitwise_equal': equal, 'max_abs': maximum,
'applied': equal, 'reason': 'exact_samples' if equal else 'not_exact_keep_original',
'epsilon_rad': cfg['jacobian_epsilon_rad'], 'ik_parameters_changed': False}
def install(env, qualification):
if qualification['applied']:
env._cycle_state.controller.jacobian = MethodType(jacobian, env._cycle_state.controller)
return dict(qualification)
@@ -223,7 +223,7 @@ class SeamDecision:
@dataclass(frozen=True)
class StopResult:
reason: str # failure or protocol_complete, never a gate-pass assertion
reason: str # failure, protocol_complete or requested_stop; never a gate-pass assertion
trial_index: int
clock: Clock
causes: tuple[str, ...]
@@ -272,9 +272,12 @@ class EvaluationContactCycleEnv(ManagerBasedRLEnv):
Its returned causes join ALL runtime causes. Missing/raising callbacks stop.
Intermediate endpoint seam callback must return explicit SeamDecision(True).
No callback means no admission. Final endpoint has no next reference/reset.
Optional boundary stop runs after endpoint evidence/safety, before admission
or another reference refresh; absent by default for historical evaluators.
"""
def __init__(self, cfg, *, protocol: Protocol, trial_index: int, runtime_hooks: RuntimeHooks,
evidence_callback: EvidenceCallback, seam_callback: SeamCallback | None = None, **kwargs):
evidence_callback: EvidenceCallback, seam_callback: SeamCallback | None = None,
boundary_stop_callback: Callable[[], bool] | None = None, **kwargs):
if not runtime_hooks.active or runtime_hooks.mode != 'construction':
raise RuntimeError('Install RuntimeHooks before environment construction')
if not callable(evidence_callback):
@@ -285,6 +288,7 @@ class EvaluationContactCycleEnv(ManagerBasedRLEnv):
self.evaluation_protocol, self.evaluation_trial_index = protocol, trial_index
self.runtime_hooks = runtime_hooks
self.evidence_callback, self.seam_callback = evidence_callback, seam_callback
self.boundary_stop_callback = boundary_stop_callback
self.stop_result = None
self._started = self._initial_reset = self._finalized = False
self._consumed_rows = set()
@@ -336,7 +340,7 @@ class EvaluationContactCycleEnv(ManagerBasedRLEnv):
except Exception as exc:
return (f'recording_callback:{type(exc).__name__}:{exc}',)
def _stop(self, causes=()):
def _stop(self, causes=(), *, reason=None):
causes = tuple(dict.fromkeys((*causes, *(
('illegal_reset_or_pose_write',) if self.runtime_hooks.violations else ()))))
if self.stop_result is not None:
@@ -351,7 +355,7 @@ class EvaluationContactCycleEnv(ManagerBasedRLEnv):
g = int(s.substeps[0]) if s.trial.index == trial_index else 0
clock = (s.protocol.evidence_clock(trial_index, g) if g else
s.protocol.next_command_clock(trial_index, 0))
self.stop_result = StopResult('failure' if causes else 'protocol_complete', trial_index, clock,
self.stop_result = StopResult('failure' if causes else (reason or 'protocol_complete'), trial_index, clock,
causes, _fatal(causes), g, g // CONTROL_TICKS, g % CONTROL_TICKS,
g // CYCLE_TICKS, h.attempted_steps, h.completed_steps,
h.initialization_steps, h.rollout_steps, h.reset_calls, h.pose_write_calls,
@@ -468,6 +472,9 @@ class EvaluationContactCycleEnv(ManagerBasedRLEnv):
self.common_step_counter += 1
reward = self.reward_manager.compute(dt=self.step_dt)
g = int(s.substeps[0])
if (g % CYCLE_TICKS == 0 and self.boundary_stop_callback is not None
and self.boundary_stop_callback()):
return StepResult(None, reward, CONTROL_TICKS, self._stop(reason='requested_stop'))
if g == s.trial.total_ticks:
return StepResult(None, reward, CONTROL_TICKS, self._stop())
admitted = False
@@ -0,0 +1,229 @@
"""Compact synchronous 500Hz capture, unchanged physical/reference action math.
No scene.update monkeypatch, no autoreset, no sampled/thinned evidence. Only two
seams need full carried-state/RNG fingerprints; do not copy RNG per physics tick.
"""
import hashlib
import json
import random
from dataclasses import asdict
import numpy as np
import torch
from audit_contact_cycle_functional import evaluate as evaluate_cycle
from SkillFactory.legs.contact_cycle_sim.evaluation_protocol import CYCLE_TICKS
from .recording import SimCycleRecorder
COUNTERS = ('attempted_steps', 'completed_steps', 'initialization_steps', 'rollout_steps',
'reset_calls', 'pose_write_calls', 'composer_buffer_replacements')
def counters(hooks):
return {k: getattr(hooks, k) for k in COUNTERS}
def tensor_identity(value):
value = value.detach().cpu().contiguous()
return {'dtype': str(value.dtype), 'shape': list(value.shape),
'sha256': hashlib.sha256(value.numpy().tobytes()).hexdigest()}
def carry_snapshot(s):
"""Read-only identity of enumerated carried state; not a full PhysX cache claim."""
env = s.env
values = {
'root': torch.cat(s.root(), -1), 'q': s.q(), 'qdot': s.robot.data.joint_vel.torch,
'torque': s.robot.data.applied_torque.torch,
'substeps': s.substeps, 'time': s.time, 'origin': s.origin, 'base_origin': s.base_origin,
'sensed': s.sensed, 'executed': s.executed, 'residual_request': s.residual_request,
'effective_residual': s.effective_residual_rad, 'reference_used': s.reference_used,
'sensor_delay': s.sensor_delay.data, 'action_delay': s.action_delay.data,
'action': env.action_manager.action, 'previous_action': env.action_manager.prev_action,
'processed_target': env.action_manager.get_term('joint_position').processed_actions,
'external': s.external, 'guide': s.guide, 'auxiliary': s.auxiliary,
'impact': s.impact, 'load_off': s.load_off, 'edge_on': s.edge_on, 'edge_off': s.edge_off,
'torch_cpu_rng': torch.get_rng_state(),
}
if s.q().is_cuda:
values['torch_cuda_rng'] = torch.cuda.get_rng_state(s.q().device)
for name, attrs in {
'latch': ('contact', 'timer'),
'separation': ('separated', 'armed', 'premature', 'timer', 'onset_phase', 'edge_phase'),
'acquisition': ('acquired', 'failed', 'timer'),
'schedule': ('fired', 'start', 'envelope', 'integral', 'completed'),
}.items():
for attr in attrs:
values[name + '.' + attr] = getattr(getattr(s, name), attr)
result = {name: tensor_identity(value) for name, value in values.items()}
py_rng = json.dumps(random.getstate(), separators=(',', ':')).encode()
np_rng = np.random.get_state()
result['python_rng'] = hashlib.sha256(py_rng).hexdigest()
result['numpy_rng'] = {'algorithm': np_rng[0], 'state': tensor_identity(torch.from_numpy(np_rng[1])),
'pos': int(np_rng[2]), 'has_gauss': int(np_rng[3]), 'cached_gaussian': float(np_rng[4])}
# Nominal actuator config is stateless PD. Backend qualification binds this.
return result
class FunctionalFlowRecorder:
def __init__(self, cfg, protocol, guard):
self.cfg, self.protocol, self.guard = cfg, protocol, guard
self.capture = None
self.initial = None
self.initial_counters = None
self.events, self.cycles, self.seams = [], [], []
self.pending_seam = None
self.faults = []
self.support_load = None
def attach(self, env):
self.capture = SimCycleRecorder(env) # never enter its old scene-update wrapper
def before_control(self, observation, action, mean, std):
self.guard()
self.capture.before_control(observation, action, mean, std)
@property
def frames(self):
return [] if self.capture is None else self.capture.frames
def trace(self, start=0):
frames = self.frames[start:]
return {} if not frames else {k: torch.stack([f[k] for f in frames]) for k in frames[0]}
def _window_checks(self, event):
"""Stop at the last included phase sample, not after an extra control."""
local = event.clock.local_tick
if local not in (1499, 1999, 2999):
return ()
f = self.cfg['functional_gates']
start = event.clock.cycle_index * CYCLE_TICKS
frames = self.frames[start:]
if local == 1499:
win = frames[-250:]
normal = torch.stack([x['normal'][0, 2] for x in win])
weight = torch.stack([x['weight'][0] for x in win])
self.support_load = float((normal / weight).mean())
ok = (float((normal > f['contact_force_on_N']).float().mean()) >= f['support_reload_contact_fraction_min']
and self.support_load >= f['support_reload_load_fraction_min'])
return () if ok else ('functional_support',)
if local == 1999:
win = frames[-50:]
load = float(torch.stack([x['normal'][0, 2] / x['weight'][0] for x in win]).mean())
ok = self.support_load is not None and load / max(self.support_load, 1e-6) <= f['unload_remaining_support_fraction_max']
return () if ok else ('functional_unload',)
swing = frames[2299:2999]
air = [bool(x['gap'][0] >= f['swing_gap_m_min'] and x['normal'][0, 2] <= f['contact_force_on_N']) for x in swing]
best = run = 0
for hit in air:
run = run + 1 if hit else 0
best = max(best, run)
pre, post = frames[2298], frames[2998]
requested = post['target'][0, :2] - pre['target'][0, :2]
actual = post['foot'][0, :2] - pre['foot'][0, :2]
progress = actual * requested.sign() / requested.abs().clamp_min(1e-6)
causes = []
if sum(air) / len(air) < f['swing_air_fraction_min'] or best * .002 < f['swing_contiguous_air_s_min']:
causes.append('functional_real_flight')
if not bool((requested.abs() > .001).all() and (progress >= f['swing_xy_progress_fraction_min']).all()):
causes.append('functional_xy_swing')
return tuple(causes)
def __call__(self, event, s):
self.guard()
if self.capture is None:
raise RuntimeError('Recorder not attached before initial reset')
if event.kind == 'initial':
self.initial = self.capture.snapshot()
self.initial_counters = counters(s.env.runtime_hooks)
self.events.append({'event': asdict(event), 'counters': self.initial_counters})
return ()
if event.kind == 'next_reference':
self.events.append({'event': asdict(event), 'q_ik': s.controller.q_ik.detach().cpu().tolist(),
'counters': counters(s.env.runtime_hooks)})
if self.pending_seam is not None:
seam = self.pending_seam
after = carry_snapshot(s)
same = after == seam['carry_before']
refresh = int(s.controller.refreshes[0])
seam.update(carry_after=after, same_carried_state=same,
refresh_after=refresh, single_refresh=refresh == seam['refresh_before'] + 1,
next_command=asdict(event.command), next_clock=asdict(event.clock))
self.seams.append(seam)
self.pending_seam = None
if not same or not seam['single_refresh']:
return ('recording_seam_carry_or_refresh_changed',)
return ()
if event.kind != 'tick' or event.clock.global_tick != len(self.frames) + 1:
return ('recording_clock_gap',)
frame = self.capture.snapshot()
h = s.env.runtime_hooks
for k, v in counters(h).items():
frame['runtime_' + k] = torch.tensor([v], dtype=torch.int64)
frame['global_tick'] = torch.tensor([event.clock.global_tick])
frame['cycle_index'] = torch.tensor([event.clock.cycle_index])
frame['local_tick'] = torch.tensor([event.clock.local_tick])
frame['reference_used_origin_tick'] = torch.tensor([event.reference_used_clock.global_tick])
frame['controller_refreshes'] = s.controller.refreshes.detach().cpu().clone()
# Append first, including the offending sample. Do not drop evidence to pass.
self.frames.append(frame)
causes = list(event.causes)
if not all(bool(torch.isfinite(v).all()) for v in frame.values()):
causes.append('nonfinite_recorded_state')
if h.reset_calls != self.initial_counters['reset_calls'] or h.pose_write_calls != self.initial_counters['pose_write_calls']:
causes.append('illegal_reset_or_pose_write')
if bool((frame['requested_action'].abs() > 1).any() or (frame['effective_residual_rad'].abs() > .050001).any()):
causes.append('hardware_residual_bound')
scale = s.env.cfg.support_parameters['action_scale_rad']
actual = frame['processed_target'] - s.nominal.detach().cpu() - scale * frame['reference_used_normalized']
if not torch.allclose(actual, frame['effective_residual_rad'], atol=1e-6, rtol=0):
causes.append('recording_effective_residual_mismatch')
if s.trial.controller_kind == 'analytic_reference':
if bool(frame['requested_action'].any() or frame['effective_residual_rad'].abs().gt(1e-6).any()):
causes.append('identity_reference_nonzero_residual')
elif not torch.allclose(frame['requested_action'], frame['actor_mean'].tanh(), atol=1e-6, rtol=0):
causes.append('identity_nondeterministic_action')
causes.extend(self._window_checks(event))
if event.clock.local_tick == CYCLE_TICKS:
local = self.trace(event.clock.cycle_index * CYCLE_TICKS)
# Global ticks were checked above. Preserve phases; derive local clock
# from integer ticks to avoid float32 subtraction at exact boundaries.
local['time'] = (torch.arange(1, CYCLE_TICKS + 1) * .002)[:, None]
legacy = {'format': 'skillfactory.contact-cycle-simulation-functional.v1',
'physics_dt_s': .002, 'phase_durations_s': self.cfg['phase_durations_s'],
'nominal_scenario_id': 0, 'gates': self.cfg['functional_gates']}
row = evaluate_cycle(local, legacy, s.trial.controller_kind)
self.cycles.append({'cycle_index': event.clock.cycle_index, 'audit': row})
if not row['sim_functional_passed']:
causes.extend('functional_' + k for k, passed in row['gates'].items() if not passed)
if causes:
self.faults.append({'event': asdict(event), 'causes': list(dict.fromkeys(causes))})
return tuple(dict.fromkeys(causes))
def seam_callback(self, event, s):
from .evaluation_env import SeamDecision
if not self.cycles or not self.cycles[-1]['audit']['sim_functional_passed'] or self.pending_seam is not None:
return SeamDecision(False, ('functional_seam_not_admitted',))
self.pending_seam = {'endpoint_event': asdict(event), 'carry_before': carry_snapshot(s),
'refresh_before': int(s.controller.refreshes[0]),
'q_ik_before': s.controller.q_ik.detach().cpu().tolist()}
return SeamDecision(True)
def continuity(self, stop, hooks, cycles):
final = counters(hooks)
checks = {
'complete_protocol': stop is not None and stop.reason == 'protocol_complete' and not stop.causes,
'all_samples': len(self.frames) == cycles * CYCLE_TICKS == hooks.rollout_steps,
'no_reset_increment': self.initial_counters is not None and final['reset_calls'] == self.initial_counters['reset_calls'],
'no_pose_write_increment': self.initial_counters is not None and final['pose_write_calls'] == self.initial_counters['pose_write_calls'],
'no_hook_violations': not hooks.violations,
'all_cycle_gates': len(self.cycles) == cycles and all(r['audit']['sim_functional_passed'] for r in self.cycles),
'all_seams': len(self.seams) == cycles - 1 and all(x['same_carried_state'] and x['single_refresh'] for x in self.seams),
'no_pending_seam': self.pending_seam is None,
'no_recording_faults': not self.faults,
}
return {'runtime_continuity_verified': all(checks.values()), 'checks': checks,
'initial_counters': self.initial_counters, 'final_counters': final,
'scope': 'Enumerated state and guarded simulator API; native PhysX caches not observed.'}
@@ -0,0 +1,82 @@
"""Presentation-only: render each NEW verified physical sample, no frame cap.
The frozen environment's configured interval20 renders remain untouched.
On those ticks no extra render occurs. Else paint only AFTER original safety
and synchronous full-rate evidence succeed, BEFORE any next physical step.
No interpolation, repeated-state moving frames, sleeps, timestep/control changes
or physical calls. This may trade simulation throughput for UI responsiveness;
measure simulation/wall separately from genuine render submissions.
"""
from .packed_recording_v042 import ScopedPackedSkillRecorder
class VerifiedTickPainter:
def __init__(self, env, gui):
if env.cfg.sim.render_interval != 20:
raise RuntimeError('presentation_requires_original_render_interval20')
self.env, self.gui = env, gui
kits = [v for v in env.sim.visualizers if v.cfg.visualizer_type == 'kit']
if len(kits) != 1:
raise RuntimeError('presentation_requires_one_concrete_Kit_visualizer')
self.kit = kits[0]
self.additional_renders = 0
self.last_tick = 0
self.require_live()
def require_live(self):
# The SDK swallows viz.step exceptions and removes the failed viz,
# while render_generation still increases. Never count that as a paint.
if (not any(v is self.kit for v in self.env.sim.visualizers)
or self.kit.is_closed or not self.kit.is_running()
or self.kit.is_rendering_paused() or self.kit.is_training_paused()):
raise RuntimeError('presentation_expected_Kit_visualizer_lost_closed_or_paused')
def __call__(self, event, state):
tick = event.clock.global_tick
if tick != self.last_tick + 1:
raise RuntimeError('presentation_requires_a_new_verified_physical_tick')
self.last_tick = tick
if (self.gui.closed or not self.gui.app.is_running()) and tick < state.trial.total_ticks:
return ('gui_window_closed_before_completion',)
self.require_live()
self.gui.update(self.env)
if tick % 20:
self.env.sim.render()
self.require_live() # includes SDK-swallowed step/close failures
self.additional_renders += 1
# Preserve final-tick completion semantics, but a close during an
# earlier newly pumped frame must fail BEFORE any next physical step.
if (self.gui.closed or not self.gui.app.is_running()) and tick < state.trial.total_ticks:
return ('gui_window_closed_before_completion',)
return ()
def report(self):
return {'policy': 'one current-state render per verified physical tick; no frame cap',
'additional_renders': self.additional_renders, 'last_verified_tick': self.last_tick,
'original_render_interval': 20, 'interpolation': False,
'adds_physics': False, 'presentation_vs_throughput_tradeoff': True}
class DisplaySkillRecorder(ScopedPackedSkillRecorder):
painter = None
def __call__(self, event, state):
causes = super().__call__(event, state)
# Offending sample/all causes are already preserved by original code.
# Never paint after physical/evidence failure or before a full sample.
if (self.painter is not None and event.kind == 'tick' and not causes
and not event.causes and not state.env.runtime_hooks.violations):
return self.painter(event, state)
return causes
def require_recorder_live(recorder):
painter = getattr(recorder, 'painter', None)
if painter is not None:
painter.require_live()
def attach(recorder, env, gui):
recorder.painter = VerifiedTickPainter(env, gui)
gui.message.text = '0.4.2 candidate | LIVE verified states | no interpolation / no training'
return recorder.painter
@@ -0,0 +1,102 @@
"""Exact-dtype synchronous packed snapshot transfer; not sampled evidence.
The physical expressions below match the original CycleRecorder/SimCycleRecorder.
Only host transfer packaging changes. All GPU copies complete before callback
return and the original per-tick safety/window/endpoint checks still run.
"""
from collections import defaultdict
import torch
from SkillFactory.tasks.manager_based.contact_cycle.mdp import effort, failed, failure_flags
from .mdp import residual_cost, root_position_cost, root_velocity_cost
from .recording import SimCycleRecorder
from .skill_recording_v4 import SkillRecorder
from .readonly_scope_v042 import readonly_scope
def copy_snapshot(values, *, group_cpu=False):
"""Keep exact keys/dtypes/shapes and independent CPU storage for every field.
group_cpu exercises the grouping algorithm with CPU tensors in unit tests;
production groups only device tensors. No cast, delayed copy or pinned-ring
overwrite is permitted. Noncontiguous/empty fields retain their values.
"""
output, groups = {}, defaultdict(list)
for name, value in values.items():
if not isinstance(value, torch.Tensor):
raise TypeError('Snapshot fields must be tensors')
if value.device.type == 'cpu' and not group_cpu:
output[name] = value.detach().clone()
else:
groups[(value.device, value.dtype)].append((name, value.detach()))
for members in groups.values():
flat = torch.cat([v.reshape(-1) for _, v in members])
host = flat.cpu() # blocking: never hand unchecked/incomplete data back
offset = 0
for name, value in members:
size = value.numel()
output[name] = host[offset:offset + size].reshape(value.shape).clone()
offset += size
if offset != host.numel():
raise RuntimeError('Packed snapshot layout mismatch')
return {name: output[name] for name in values}
class PackedSimCycleRecorder(SimCycleRecorder):
def snapshot(self):
s = self.state
phase, progress, target, force, _ = s.reference()
ratio = torch.maximum((s.robot.data.applied_torque.torch[:, s.joints]/s.effort).abs().amax(-1),
(s.robot.data.joint_vel.torch[:, s.joints]/self.speed).abs().amax(-1))
values = {"phase": phase, "progress": progress, "time": s.time, "scenario": s.scenarios,
"weight": s.weight, "normal": s.contact(), "friction": s.friction(), "foot": s.foot_center(),
"target": target, "gap": s.foot_center()[:, 2] - s.bundle["foot"]["radius"],
"desired_force": force,
"joint_excess": torch.maximum(self.lower - s.q(), s.q() - self.upper).clamp(min=0).amax(-1),
"limit_ratio": ratio, "slip_speed": s.slip_velocity(),
"height_error": (s.root()[0][:, 2] - s.port_reference()[0][:, 2]).abs(),
"external": s.external, "guide": s.guide, "auxiliary": s.auxiliary,
"would_fail": failed(self.env), "failure_flags": failure_flags(self.env), "tilt": s.tilt(),
"root_state": torch.cat(s.root(), -1),
"signed_height_error": s.root()[0][:, 2] - s.port_reference()[0][:, 2],
"joint_pos": s.q(), "joint_vel": s.robot.data.joint_vel.torch[:, s.joints],
"applied_torque": s.robot.data.applied_torque.torch[:, s.joints],
"processed_target": self.env.action_manager.get_term("joint_position").processed_actions,
"effective_action": s.executed, "policy_snapshot": s.policy(),
"actor_input": self.actor_input, "actor_mean": self.actor_mean, "actor_std": self.actor_std,
"requested_action": self.requested_action, "actor_metadata_available": self.actor_available,
"control_action_available": self.action_available,
"task_reward_unweighted": s.objective()[0], "effort_cost_unweighted": effort(self.env),
"contact_acquired": s.acquisition.acquired, "acquisition_failed": s.acquisition.failed,
"acquisition_timer": s.acquisition.timer, "contact_armed": s.separation.armed,
"separation_timer": s.separation.timer,
"load_off": s.load_off, "liftoff": s.edge_off, "liftoff_phase": s.separation.edge_phase,
"separated": s.separation.separated, "premature_separation": s.separation.premature,
"event_fired": s.schedule.fired, "event_completed": s.schedule.completed,
"event_integral": s.schedule.integral}
extra = {'residual_request_normalized': s.residual_request,
'reference_used_normalized': s.reference_used,
'reference_next_normalized': s.controller.action,
'effective_residual_rad': s.effective_residual_rad,
'reference_ik_rad': s.controller.q_ik,
'root_position_cost_unweighted': root_position_cost(self.env),
'root_velocity_cost_unweighted': root_velocity_cost(self.env),
'residual_cost_unweighted': residual_cost(self.env)}
values.update(extra)
return copy_snapshot(values)
class PackedSkillRecorder(SkillRecorder):
def attach(self, env):
self.capture = PackedSimCycleRecorder(env)
class ScopedPackedSimCycleRecorder(PackedSimCycleRecorder):
def snapshot(self):
with readonly_scope(self.state):
return super().snapshot()
class ScopedPackedSkillRecorder(PackedSkillRecorder):
def attach(self, env):
self.capture = ScopedPackedSimCycleRecorder(env)
@@ -0,0 +1,95 @@
"""Bound application observer. No physics/control changes, no fake FPS."""
import cProfile
import importlib.metadata
import json
import pstats
import time
from pathlib import Path
CONFIG = 'configs/contact_cycle/performance_v042.json'
RUNTIME_MATH_QUALIFICATION = None
def options(root):
value = json.loads((Path(root) / CONFIG).read_text())
if (set(value) != {'mode', 'profile'} or value['mode'] not in ('baseline', 'sensor_epoch', 'packed', 'combined', 'combined_display')
or type(value['profile']) is not bool):
raise ValueError('Invalid authenticated performance configuration')
return value
def runtime_metadata(app):
import torch
import omni.kit.app
kit_app = omni.kit.app.get_app() # SimulationApp is the lifecycle wrapper, not IApp.
result = {'application': 'Isaac Lab / Isaac Sim', 'version': kit_app.get_app_version(),
'path': '/home/cen/isaacsim-6.0.1', 'kit_build': kit_app.get_build_version()
if hasattr(kit_app, 'get_build_version') else None}
result.update(cuda_available=torch.cuda.is_initialized(), cuda_device=torch.cuda.get_device_name(0))
for name in ('isaacsim', 'torch', 'numpy'):
try: result[name] = importlib.metadata.version(name)
except importlib.metadata.PackageNotFoundError: result[name] = None
return result
def recorder_class(root):
from .skill_recording_v4 import SkillRecorder
from .packed_recording_v042 import PackedSkillRecorder, ScopedPackedSkillRecorder
from .live_cadence_v042 import DisplaySkillRecorder
return {'baseline': SkillRecorder, 'sensor_epoch': SkillRecorder,
'packed': PackedSkillRecorder, 'combined': ScopedPackedSkillRecorder,
'combined_display': DisplaySkillRecorder}[options(root)['mode']]
def install_readonly_path(root, env):
from . import sensor_epoch_v042, readonly_scope_v042, batched_kinematics_v042
mode = options(root)['mode']
result = sensor_epoch_v042.install(env) if mode in ('sensor_epoch', 'combined', 'combined_display') else {'implementation': 'original', 'sensors': []}
if mode in ('combined', 'combined_display'):
result.update(readonly_scope_v042.install_safety(env))
if RUNTIME_MATH_QUALIFICATION is None:
raise RuntimeError('Missing bound runtime Jacobian qualification')
result['jacobian'] = batched_kinematics_v042.install(env, RUNTIME_MATH_QUALIFICATION)
return result
class LoopProfile:
def __init__(self, root, env):
self.settings = options(root)
self.profile = cProfile.Profile() if self.settings['profile'] else None
self.env = env
self.began = None
def start(self):
self.render_before = self.env.sim.render_generation
self.began_wall = time.time()
self.began = time.perf_counter()
if self.profile is not None:
self.profile.enable()
def finish(self, controls, physics_samples):
if self.profile is not None:
self.profile.disable()
duration = time.perf_counter() - self.began
renders = self.env.sim.render_generation - self.render_before
rows = []
if self.profile is not None:
for (filename, line, function), (primitive, calls, own, cumulative, _) in pstats.Stats(self.profile).stats.items():
rows.append({'file': filename, 'line': line, 'function': function,
'primitive_calls': primitive, 'calls': calls,
'self_seconds': own, 'cumulative_seconds': cumulative})
rows.sort(key=lambda x: x['cumulative_seconds'], reverse=True)
from .sensor_epoch_v042 import report
return {'mode': self.settings['mode'], 'cprofile_enabled': self.profile is not None,
'active_loop_started_wall': self.began_wall, 'active_loop_ended_wall': time.time(),
'capture_implementation': type(self.env.evidence_callback.capture).__module__ + '.' + type(self.env.evidence_callback.capture).__qualname__,
'sensor_epochs': report(self.env),
'jacobian_qualification': RUNTIME_MATH_QUALIFICATION,
'presentation': self.env.evidence_callback.painter.report() if getattr(self.env.evidence_callback, 'painter', None) is not None else None,
'active_loop_wall_seconds': duration, 'physics_samples': physics_samples,
'control_calls': controls, 'render_generations': renders,
'physics_ticks_per_wall_second': physics_samples / duration,
'simulation_seconds_per_wall_second': .002 * physics_samples / duration,
'actual_render_generations_per_wall_second': renders / duration,
'scope': 'Actual env.step loop incl gates/recording/UI. Startup and final viewing excluded. cProfile adds overhead. Render generations are submissions, not display-present GPU timings.',
'functions_by_cumulative': rows}
@@ -0,0 +1,71 @@
"""Invocation-local memoization of proven read-only state accessors.
Not a global-tick cache: lifetime is ONE safety/snapshot invocation. No control,
physics, reset, latch, history, reference refresh or app pumping occurs inside.
Original arithmetic is still called; only duplicate reads in that invocation
reuse the result. Never cache policy/objective/RNG or mutating methods.
"""
from contextlib import contextmanager
from functools import wraps
NAMES = ('root', 'q', 'foot_center', 'contact', 'friction', 'mount_wrench',
'mount_world', 'tilt', 'errors', 'protocol_command', 'reference', 'port_reference')
_ABSENT = object()
def marker(s):
hooks = getattr(s.env, 'runtime_hooks', None)
return (id(getattr(s, 'command_clock', None)), id(getattr(s, 'reference_clock', None)),
id(getattr(s, 'anchors', None)),
*(getattr(hooks, n, None) for n in ('completed_steps', 'reset_calls', 'pose_write_calls')))
@contextmanager
def readonly_scope(s):
before = marker(s)
saved = {}
try:
for name in NAMES:
original = getattr(s, name, None)
if not callable(original):
continue
saved[name] = vars(s).get(name, _ABSENT)
def memoized(original=original):
value = _ABSENT
@wraps(original)
def read(*args, **kwargs):
nonlocal value
if args or kwargs:
return original(*args, **kwargs)
if value is _ABSENT:
value = original() # do not cache exceptions
return value
return read
setattr(s, name, memoized())
yield
if marker(s) != before:
raise RuntimeError('readonly_scope_changed_clock_physics_reset_or_anchor')
finally:
for name, value in saved.items():
if value is _ABSENT:
delattr(s, name)
else:
setattr(s, name, value)
def install_safety(env):
s = env._cycle_state
original = s.safety_causes
@wraps(original)
def scoped():
with readonly_scope(s):
return original()
s.safety_causes = scoped
# LoadedState retains a constructor reference to the mount sensor. Route
# that existing read through the same qualified epoch proxy, not a new sensor.
routed = []
for name, wrapper in env._performance_sensor_epochs.items():
if getattr(s, 'sensor', None) is wrapper._source:
s.sensor = wrapper
routed.append(name)
return {'safety_read_scope': True, 'constructor_sensor_references_routed': routed}
@@ -0,0 +1,72 @@
"""Avoid re-fetching an unchanged sensor inside one explicit sensor epoch.
No SDK patches, solver/config changes, skipped update or delayed safety sample.
Each sensor.update/reset invalidates before delegation, including zero-dt updates
and exceptions. First data access in that epoch runs the original SDK getter.
Later access returns that SAME live data object. Never cache by global tick.
"""
_MISSING = object()
class EpochSensor:
def __init__(self, source):
self._source = source
self._value = _MISSING
self.data_requests = 0
self.data_fetches = 0
self.invalidations = 0
def __getattr__(self, name):
return getattr(self._source, name)
def invalidate(self):
self._value = _MISSING
self.invalidations += 1
@property
def data(self):
self.data_requests += 1
if self._value is _MISSING:
value = self._source.data # exceptions do not admit a cache entry
self._value = value
self.data_fetches += 1
return self._value
def update(self, *args, **kwargs):
self.invalidate()
try:
return self._source.update(*args, **kwargs)
finally:
self._value = _MISSING
def reset(self, *args, **kwargs):
self.invalidate()
try:
return self._source.reset(*args, **kwargs)
finally:
self._value = _MISSING
def install(env):
# Only existing scene sensors. Manager actions/controllers/robot data and
# the original sensor objects, native callbacks and their reset guards stay.
wrappers = {}
for name, source in list(env.scene.sensors.items()):
if isinstance(source, EpochSensor):
raise RuntimeError('Sensor epoch wrapper must be installed once')
wrapped = EpochSensor(source)
env.scene.sensors[name] = wrapped
if env.scene[name] is not wrapped:
raise RuntimeError('Scene sensor lookup did not retain epoch wrapper')
wrappers[name] = wrapped
if not wrappers:
raise RuntimeError('No real sensors to qualify')
env._performance_sensor_epochs = wrappers
return {'implementation': __name__ + '.EpochSensor', 'sensors': sorted(wrappers)}
def report(env):
return {name: {'requests': s.data_requests, 'fetches': s.data_fetches,
'invalidations': s.invalidations}
for name, s in getattr(env, '_performance_sensor_epochs', {}).items()}
@@ -0,0 +1,167 @@
"""Read-only live Kit presentation. Imported after AppLauncher, never by CPU API.
No control/physics configuration or robot-pose writes. Original asset includes
its blue 3 kg payload. Final viewing pumps Kit with player physics disabled.
"""
import time
def prepare_native():
"""Only GUI PREP/RUN load native presentation dependencies, after Kit."""
global carb, get_eventdispatcher, omni, ui, Gf, UsdGeom, UsdLux
import carb.settings
from carb.eventdispatcher import get_eventdispatcher
import omni.kit.app
import omni.kit.viewport.utility
import omni.ui as ui
import omni.usd
from pxr import Gf, UsdGeom, UsdLux
PHASES = ('SUPPORT / bearing load', 'UNLOAD', 'LIFT / separate',
'SWING / airborne XY', 'TOUCHDOWN', 'RELOAD / bearing load')
HOLD_SECONDS = 600
class LivePresentation:
def __init__(self, app, guard, publish):
self.app, self.guard, self.publish = app, guard, publish
self.closed = False
self.render_updates = 0
self.protocol_completed = False
self.close_reason = None
self.hold_no_physics = False
self.window = None
self.last_tick = 0
self.last_publish = 0
# Cancel the OS close request ONLY to preserve evidence and let the sole
# owner finish guarded env.close + worker receipt + SimulationApp.close.
self.quit_subscription = get_eventdispatcher().observe_event(
event_name=omni.kit.app.GLOBAL_EVENT_POST_QUIT,
on_event=self._on_quit, observer_name='go2-fl-owned-close', order=-10000)
carb.settings.get_settings().set_bool('/app/file/ignoreUnsavedOnExit', True)
def _on_quit(self, _event):
omni.kit.app.get_app().try_cancel_shutdown('Go2 FL: preserving supervised result before close')
self.request_close()
def request_close(self):
self.closed = True
self.close_reason = 'window_close'
def attach(self, env):
self.env = env
live_kit = [v for v in env.sim.visualizers
if v.cfg.visualizer_type == 'kit' and v.is_running()]
# This installed launcher does not publish legacy /isaaclab/has_gui.
# Check the REAL application and concrete live Kit visualizer instead.
# Do not set that legacy flag: PhysX uses it to alter scene-query cfg.
if self.app.config.get('headless', True) or not live_kit:
raise RuntimeError('gui_requires_non_headless_app_and_live_Kit_visualizer')
import omni.kit.viewport.utility
stage = omni.usd.get_context().get_stage()
# Camera/light prims only. No modifications to Robot, contact ground,
# rigid body schemas, mass/inertia, materials, controller or fixture.
camera = UsdGeom.Camera.Define(stage, '/World/SkillDemoCamera')
eye, lookat = (0.85, 1.02, 0.62), (0.015, 0.075, 0.24)
matrix = Gf.Matrix4d().SetLookAt(Gf.Vec3d(*eye), Gf.Vec3d(*lookat), Gf.Vec3d(0, 0, 1)).GetInverse()
UsdGeom.Xformable(camera).AddTransformOp().Set(matrix)
camera.CreateFocalLengthAttr(27)
camera.CreateClippingRangeAttr(Gf.Vec2f(.01, 100))
viewport = omni.kit.viewport.utility.get_active_viewport()
if viewport is None:
raise RuntimeError('gui_no_active_viewport')
viewport.set_active_camera(str(camera.GetPath()))
light = UsdLux.DistantLight.Define(stage, '/World/SkillDemoKeyLight')
light.CreateIntensityAttr(1800)
light.CreateAngleAttr(2)
UsdGeom.Xformable(light).AddRotateXYZOp().Set(Gf.Vec3f(-35, -20, -30))
# Maximize usable viewport, while keeping the genuine Kit window frame.
for name in ('Content', 'Content Browser', 'Stage', 'Property', 'Console', 'Simulation', 'Environment'):
window = ui.Workspace.get_window(name)
if window is not None:
window.visible = False
self.window = ui.Window('Go2 FL | LIVE PhysX | 0.4.1', width=510, height=285,
position_x=920, position_y=55)
with self.window.frame:
with ui.VStack(spacing=4):
ui.Label('LIVE SIMULATION - Go2 FL single leg + original 3 kg payload', height=24)
self.mode = ui.Label('', height=22)
self.phase = ui.Label('', height=22)
self.cycle = ui.Label('', height=22)
self.progress = ui.ProgressBar(height=14)
self.contact = ui.Label('', height=22)
self.position = ui.Label('', height=22)
self.message = ui.Label('Original aided fixture | truth sensing | no resets / no training', height=25)
ui.Button('Close window (ABORT while running)', clicked_fn=self.request_close, height=27)
self.update(env)
def report(self):
return {'enabled': True, 'render_updates': self.render_updates,
'protocol_completed': self.protocol_completed, 'last_tick': self.last_tick,
'close_reason': self.close_reason, 'hold_no_physics': self.hold_no_physics,
'camera': '/World/SkillDemoCamera', 'max_final_view_seconds': HOLD_SECONDS,
'source': 'live PhysX and actual state; no playback; original 3kg payload mesh'}
def update(self, env):
from .evaluation_mdp import state
s = state(env)
command = s.protocol_command()
self.last_tick = int(s.substeps[0])
if self.window is not None:
phase = command.phase
self.mode.text = f'Control: {s.protocol.session.controller} | Command: {s.protocol.session.active}'
self.phase.text = f'Phase {phase + 1}/6: {PHASES[phase]} | {command.progress:.0%}'
cycles = s.protocol.session.cycles
self.cycle.text = f'Cycle {min(self.last_tick // 4500 + 1, cycles)}/{cycles} | tick {self.last_tick}/{s.trial.total_ticks}'
self.progress.model.set_value(self.last_tick / s.trial.total_ticks)
# Read the same full-rate physical evidence already captured by the
# recorder, not a synthetic status/derived animation.
f = env.evidence_callback.frames[-1] if env.evidence_callback.frames else env.evidence_callback.initial
if f is not None:
self.contact.text = f'Contact: {bool(s.latch.contact[0])} | Fn {float(f["normal"][0, 2]):.2f} N | gap {float(f["gap"][0])*1000:.2f} mm'
xyz = f['foot'][0].tolist()
self.position.text = f'Actual foot world m: {xyz[0]:+.3f}, {xyz[1]:+.3f}, {xyz[2]:+.3f}'
now = time.monotonic()
if now - self.last_publish >= .5:
self.publish(self.report())
self.last_publish = now
def after_control(self, env):
self.update(env)
# Environment already renders every original 20 physics ticks (25 Hz).
# No additional simulation step and no simulation-time slowing/scaling.
self.render_updates = env.sim.render_generation - self.initial_render_generation
def start(self, env):
self.initial_render_generation = env.sim.render_generation
self.attach(env)
def hold(self, env, complete, *, safely_stopped=False):
self.protocol_completed = complete
if not complete and not safely_stopped:
self.publish(self.report())
return
from .functional_flow_recording_v2 import counters, carry_snapshot
before = counters(env.runtime_hooks)
carry = carry_snapshot(env.evidence_callback.capture.state)
outcome = 'SEQUENCE COMPLETE' if complete else 'SAFE STOP (not full sequence)'
self.message.text = outcome + ' | physics frozen | close Kit to finish (max 10 min)'
deadline = time.monotonic() + HOLD_SECONDS
while not self.closed and self.app.is_running() and time.monotonic() < deadline:
self.guard()
self.update(env)
# Pinned KitVisualizer disables /app/player/playSimulations while
# pumping app.update(). Rendering only; RuntimeHooks remain locked.
env.sim.render()
self.render_updates += 1
time.sleep(1 / 30)
if not self.closed:
self.close_reason = 'view_timeout' if self.app.is_running() else 'window_close'
self.hold_no_physics = (counters(env.runtime_hooks) == before
and carry_snapshot(env.evidence_callback.capture.state) == carry)
self.publish(self.report())
if not self.hold_no_physics:
raise RuntimeError('gui_final_view_changed_carried_physical_state')
def release(self):
# Stop intercepting shutdown only AFTER the evidence owner is finished.
self.quit_subscription = None
@@ -0,0 +1,98 @@
"""v4 live metadata/requests on top of the unchanged full-rate v2 recorder."""
from dataclasses import asdict, replace
import hashlib
import json
from SkillFactory.legs.contact_cycle_sim.skill_mailbox_v4 import consume, publish, send
from SkillFactory.legs.contact_cycle_sim.evaluation_protocol import CYCLE_TICKS
from .functional_flow_recording_v2 import FunctionalFlowRecorder, carry_snapshot
class SkillRecorder(FunctionalFlowRecorder):
def __init__(self, cfg, protocol, guard, mailbox, *, stop_at_tick=None, reject_at_tick=None):
super().__init__(cfg, protocol, guard)
self.session = protocol.session
self.mailbox = mailbox
self.stop_at_tick, self.reject_at_tick = stop_at_tick, reject_at_tick
self.last_status = None
def status(self, event, s, *, state='running', stop=None):
command = s.protocol_command()
frame = self.initial if not self.frames else self.frames[-1]
value = {
'state': state, 'global_tick': event.clock.global_tick,
'cycle_index': event.clock.cycle_index, 'local_tick': event.clock.local_tick,
'completed_cycles': len(self.cycles), 'cycles_requested': self.session.cycles,
'phase': command.phase, 'phase_progress': command.progress,
'active_command': self.session.active, 'pending_commands': list(self.session.pending),
'stop_requested': self.session.stop_requested, 'receipts_count': len(self.session.receipts),
'last_receipt': self.session.receipts[-1] if self.session.receipts else None,
'contact_normal_N': float(frame['normal'][0, 2]),
'contact': bool(s.latch.contact[0]), 'gap_m': float(frame['gap'][0]),
'foot_world_m': frame['foot'][0].tolist(), 'target_world_m': list(command.target_world_m),
'anchors': asdict(s.anchors), 'failure': list(event.causes),
'stop': None if stop is None else asdict(stop),
}
self.last_status = value
publish(self.mailbox / 'status.json', value)
def poll(self):
tick = len(self.frames)
receipt = consume(self.mailbox, self.session, tick)
if self.stop_at_tick is not None and tick >= self.stop_at_tick:
if len(self.session.receipts) >= 64:
raise RuntimeError('budget_live_receipts_cap')
send(self.mailbox, 'stop')
receipt = consume(self.mailbox, self.session, tick)
receipt['source'] = 'public_stop_probe'
publish(self.mailbox / 'receipt.json', receipt)
self.stop_at_tick = None
if self.reject_at_tick is not None and tick >= self.reject_at_tick:
if len(self.session.receipts) >= 64:
raise RuntimeError('budget_live_receipts_cap')
before = (self.session.active, list(self.session.pending), self.session.stop_requested)
def carry_digest():
encoded = json.dumps(carry_snapshot(self.capture.state), sort_keys=True, separators=(',', ':')).encode()
return hashlib.sha256(encoded).hexdigest()
carry_before = carry_digest()
try:
send(self.mailbox, 'queue', 'INVALID')
raise RuntimeError('Illegal command unexpectedly admitted')
except ValueError:
pass
carry_after = carry_digest()
unchanged = (before == (self.session.active, self.session.pending, self.session.stop_requested)
and carry_before == carry_after)
self.session.receipts.append({'operation': 'queue', 'command': 'INVALID', 'accepted': False,
'received_tick': tick, 'state_unchanged': unchanged,
'carry_before_sha256': carry_before, 'carry_after_sha256': carry_after,
'source': 'public_rejection_probe'})
self.reject_at_tick = None
if not unchanged:
raise RuntimeError('recording_invalid_rejection_changed_carry')
return receipt
def before_control(self, observation, action, mean, std):
self.poll()
super().before_control(observation, action, mean, std)
def __call__(self, event, s):
causes = super().__call__(event, s)
if (event.kind == 'initial' or event.kind == 'tick' and
(event.clock.global_tick % 500 == 0 or causes or event.clock.local_tick == CYCLE_TICKS)):
self.status(replace(event, causes=causes), s)
return causes
def seam_callback(self, event, s):
decision = super().seam_callback(event, s)
if decision.admitted:
self.session.admit_endpoint(event.clock.global_tick // CYCLE_TICKS)
return decision
def continuity(self, stop, hooks, cycles):
actual = 0 if stop is None else stop.completed_clock_cycles
intentional = stop is not None and stop.reason == 'requested_stop' and self.session.stop_requested
checked_stop = replace(stop, reason='protocol_complete') if intentional else stop
result = super().continuity(checked_stop, hooks, actual if intentional else cycles)
result.update(cycles_requested=cycles, cycles_completed=actual, requested_stop=intentional)
return result