Math-function lowering¶
oracq.infrastructure.mathfunc.lowering
Automatic compute/XOR/uncompute lowering from MIR to modular RIR.
- oracq.infrastructure.mathfunc.lowering.ports(name, kind, fmt, index_width=0)[source]¶
Expand one port’s physical register names and bit widths by math kind.
complex splits into real/imaginary fixed-point registers, real occupies one fixed-point word, bool one bit, and index an unsigned register of
index_widthbits.- Parameters:
name – The port base name; complex ports append the
_real/_imagsuffixes to it.kind – The port kind: real, complex, bool or index.
fmt – The
FixedFormatfixed-point format, deciding numeric ports’ register widths.index_width – The unsigned bit width of the index kind.
- Returns:
A list of
(register name, Bits)pairs.- Return type:
list
- class oracq.infrastructure.mathfunc.lowering.CompiledFunction(operation, math_ir, fmt, output_names, input_layout, output_layout)[source]¶
Bases:
objectThe complete result of one math function compilation.
- Variables:
operation (oracq.infrastructure.builder.Operation) – The lowered reversible
Operation; inputs stay unchanged, outputs and status are XOR-written back.math_ir (oracq.infrastructure.mathfunc.graph.MathProgram) – The original
MathProgramobject that produced the module.fmt (oracq.algorithms.common.arithmetic.FixedFormat) – The
FixedFormatfixed-point format used for generation.output_names (tuple[str, ...]) – The output port names of the entry’s return values.
input_layout (tuple[tuple[str, tuple[str, ...]], ...]) – Mapping from each logical input to its expanded physical register names; each entry is (parameter name, (register name, …)).
output_layout (tuple[tuple[str, tuple[str, ...]], ...]) – Mapping from each logical output to its expanded physical register names, structured like
input_layout.
- operation¶
- math_ir¶
- fmt¶
- output_names¶
- input_layout¶
- output_layout¶
- class oracq.infrastructure.mathfunc.lowering.Lowerer(program, fmt, config, output_names=None)[source]¶
Bases:
objectLowers an MIR math function graph into reversible quantum modules of modular RIR.
Every function, helpers included, lowers to an independent RIR module; calls are kept as Call and are not expanded during lowering. Input ports stay unchanged, results and status bits are XOR-written back, and private intermediates are finally uncomputed to zero.
- Parameters:
program – The
MathProgramto lower; fully validated immediately at construction.fmt – The
FixedFormatfixed-point format.config – The
MathConfigmath kernel degree and approximation interval configuration.output_names – Output register names of the entry’s return values; when omitted a single return is out and multiple returns are out_0, out_1 and so on.
- program¶
- fmt¶
- config¶
- outputs¶
- cache¶
- lower(key)[source]¶
Lower the named function and cache the result; each function is compiled once.
- Parameters:
key – Function symbol name in
program.function_map, usually the entry.- Returns:
The function’s module, input/output layouts and generation configuration.
- Return type:
- Raises:
ValidationError – The output port names do not match the number of return values, expanded registers collide, or the fixed-point format cannot hold an index parameter’s full range.