Source code for semi_cr.core.lab.utils.qua

QUA_CLOCK_CYCLE_NS = 4


[docs] def time_to_qua_cycles( value: float, unit: str, ) -> int: """Convert a physical time to QUA clock cycles.""" scale_to_ns = { "ns": 1.0, "us": 1_000.0, "ms": 1_000_000.0, "s": 1_000_000_000.0, } if unit not in scale_to_ns: raise ValueError(f"Unsupported time unit: {unit}") time_ns = value * scale_to_ns[unit] cycles = round(time_ns / QUA_CLOCK_CYCLE_NS) return int(cycles)
[docs] def qua_cycles_to_time( cycles: int, unit: str = "ms", ) -> float: """Convert QUA clock cycles back to a physical time.""" scale_from_ns = { "ns": 1.0, "us": 1e-3, "ms": 1e-6, "s": 1e-9, } if unit not in scale_from_ns: raise ValueError(f"Unsupported time unit: {unit}") time_ns = cycles * 4 return time_ns * scale_from_ns[unit]