harbor run -t openthoughts/tasktrove-exp-flat25-pseudocode-v2-5k-pseudocode-1009harbor download openthoughts/tasktrove-exp-flat25-pseudocode-v2-5k-pseudocode-1009PSEUDOCODE
// Global constants SUPPORTED_LOG_LEVELS = ['trace', 'debug', 'info', 'warn', 'error']
// Global state (module-level) ti._cfg = ConfigDefaults() // instance with default values for all keys ti._current_log_level = 'info' // initial effective level (matches default if not overridden)
// Data structures class ConfigDefaults: // boolean and string keys with their defaults print_preprocessed = False log_level = 'info' gdb_trigger = False advanced_optimization = True debug = False print_ir = False verbose = True fast_math = True async_mode = False flatten_if = False simplify_before_lower_access = True simplify_after_lower_access = True print_benchmark_stat = False kernel_profiler = False check_out_of_bound = False print_accessor_ir = False print_evaluator_ir = False print_struct_llvm_ir = False print_kernel_llvm_ir = False print_kernel_llvm_ir_optimized = False arch = None // optional; may be provided explicitly or via TI_ARCH // NOTE: include any other keys present in init_args as default fields
class SpecConfig: // lightweight, mutable containment of values returned in test mode // Attributes are dynamically set for all relevant keys // Example attributes set: print_preprocessed, log_level, gdb_trigger, arch, etc.
// Public API (to be implemented in module ti) function init(_test_mode: bool = False, **kwargs) -> SpecConfig OR None // 1) Validate keys when in test mode allowed_keys = set(keys_of(ConfigDefaults)) union {'arch'} if _test_mode: for key in kwargs.keys(): if key not in allowed_keys: raise KeyError(key)
// 2) Environment extraction and type coercion helpers (pseudo) env_map = read_environment_variables_with_prefix('TI_') // TI_<KEY> -> value strings; TI_ARCH is handled specially
// 3) Build final values with precedence: kwargs > env_vars > defaults final = new map
for key in keys_of(ConfigDefaults): if key in kwargs: final[key] = kwargs[key] else if key in env_map: final[key] = cast_type(key, env_map[key]) else: final[key] = value_from_default(key)
// arch handling (explicit arg takes precedence over env var) if 'arch' in kwargs and kwargs['arch'] is not None: final['arch'] = kwargs['arch'] else if 'TI_ARCH' in env_map: final['arch'] = env_map['TI_ARCH']
// 4) Apply to global cfg for key in keys_of(ConfigDefaults): ti._cfg.key = final[key]
// 5) Prepare SpecConfig to return in test mode if _test_mode: spec = SpecConfig() for key in union(keys_of(ConfigDefaults), {'arch'}): set attribute spec.key = final[key] // Expose both special and non-special keys as attributes for test access return spec else: return None
function set_logging_level(level: str) if level not in SUPPORTED_LOG_LEVELS: raise ValueError("Unsupported log level") ti._current_log_level = level
function is_logging_effective(level: str) -> bool // Determine order index for levels order = {'trace':0, 'debug':1, 'info':2, 'warn':3, 'error':4} if level not in order or ti._current_log_level not in order: return False return order[level] >= order[ti._current_log_level]
// Helpers and scaffolding for testing compatibility
ti.supported_log_levels = copy_of(SUPPORTED_LOG_LEVELS)
function expected_archs() -> List[String] // Minimal deterministic arch set for tests ti.cpu = 'cpu' ti.cc = 'cc' ti.arches = [ti.cpu, ti.cc] return ti.arches
function arch_name(arch: String) -> String // Map arch value to a human-readable name if arch in [ti.cpu, ti.cc]: return arch else: return arch // minimal passthrough for unknown values
// Environment parsing helpers (conceptual) function read_environment_variables_with_prefix(prefix: String) -> Map[String, String] // Return map of env key (without prefix) to string value for keys that start with prefix // Example: TI_LOG_LEVEL -> key 'LOG_LEVEL' with value 'info' // Implementation details omitted in pseudocode
function cast_type(key: String, value: String) -> Any // Cast environment string to the appropriate type for the given key if key in boolean_keys: return value in ['1', 'true', 'TRUE', 'yes', 'on'] if key == 'log_level': // Accept only supported levels; if invalid, keep as string or raise return value if value in SUPPORTED_LOG_LEVELS else value // default: strings for non-boolean keys return value
function value_from_default(key: String) -> Any // Return the default value for the given key from ConfigDefaults return ConfigDefaults().get_field_value(key)
// Note: The SpecConfig object must support attribute access // Example usage in tests: // spec_cfg = ti.init(_test_mode=True, log_level='debug') // assert spec_cfg.log_level == 'debug' // ti.init(_test_mode=True) // ti.set_logging_level('debug') // assert ti.is_logging_effective('debug')
// End of pseudocode specification