数学函数降低

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)[源代码]

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_width bits.

参数:
  • name -- The port base name; complex ports append the _real/_imag suffixes to it.

  • kind -- The port kind: real, complex, bool or index.

  • fmt -- The FixedFormat fixed-point format, deciding numeric ports' register widths.

  • index_width -- The unsigned bit width of the index kind.

返回:

A list of (register name, Bits) pairs.

返回类型:

list

class oracq.infrastructure.mathfunc.lowering.CompiledFunction(operation, math_ir, fmt, output_names, input_layout, output_layout)[源代码]

基类:object

The complete result of one math function compilation.

变量:
  • 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 MathProgram object that produced the module.

  • fmt (oracq.algorithms.common.arithmetic.FixedFormat) -- The FixedFormat fixed-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
program()[源代码]

Return the full RIR program of the compilation result.

返回:

The program merging the entry module and its dependency modules; semantics match Operation.program.

返回类型:

Program

class oracq.infrastructure.mathfunc.lowering.Lowerer(program, fmt, config, output_names=None)[源代码]

基类:object

Lowers 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.

参数:
  • program -- The MathProgram to lower; fully validated immediately at construction.

  • fmt -- The FixedFormat fixed-point format.

  • config -- The MathConfig math 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)[源代码]

Lower the named function and cache the result; each function is compiled once.

参数:

key -- Function symbol name in program.function_map, usually the entry.

返回:

The function's module, input/output layouts and generation configuration.

返回类型:

CompiledFunction

抛出:

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.