RIR 对象¶
oracq.infrastructure.ir
RIR v0.1: immutable, serializable register-level operation graph.
- oracq.infrastructure.ir.VERSION = '0.1'¶
Current RIR specification version; the default
versionvalue for newly createdProgramobjects.
- exception oracq.infrastructure.ir.ValidationError[源代码]¶
基类:
ValueErrorInput violates a structural or semantic rule of RIR.
- class oracq.infrastructure.ir.RegType(kind, width)[源代码]¶
基类:
objectStorage type of a register, consisting of a bit pattern interpretation and a bit width.
- 变量:
kind (str) -- bit pattern interpretation; one of
bits,uint,sintorrational.width (int) -- bit width in 0..64; zero width denotes an empty interface.
- kind¶
- width¶
- oracq.infrastructure.ir.Bits(width)[源代码]¶
Return a
RegTypewith thebitsinterpretation, denoting a bit string without numeric meaning.- 参数:
width -- bit width in 0..64; zero width denotes an empty interface.
- 返回:
storage type with kind
bitsand bit width equal towidth.- 返回类型:
- oracq.infrastructure.ir.UInt(width)[源代码]¶
Return a
RegTypewith theuintinterpretation, denoting an unsigned integer from 0 to 2^width-1.- 参数:
width -- bit width in 0..64; zero width denotes an empty interface.
- 返回:
storage type with kind
uintand bit width equal towidth.- 返回类型:
- oracq.infrastructure.ir.SInt(width)[源代码]¶
Return a
RegTypewith thesintinterpretation, denoting a two's-complement integer; bit operations still act on the raw word.- 参数:
width -- bit width in 0..64; zero width denotes an empty interface.
- 返回:
storage type with kind
sintand bit width equal towidth.- 返回类型:
- oracq.infrastructure.ir.Rational(width)[源代码]¶
Return a
RegTypewith therationalinterpretation, denoting an unsigned word divided by 2^width.- 参数:
width -- bit width in 0..64; also the base-2 exponent of the denominator.
- 返回:
storage type with kind
rationaland bit width equal towidth.- 返回类型:
- class oracq.infrastructure.ir.Register(name, type)[源代码]¶
基类:
objectFormal quantum register declaration of a module.
- 变量:
name (str) -- register name; unique within the module and free of conflicts with resource names.
type (oracq.infrastructure.ir.RegType) -- storage type of the register.
- name¶
- type¶
- class oracq.infrastructure.ir.Span(register, start, width)[源代码]¶
基类:
objectA contiguous qubit range within a root register.
- 变量:
register (str) -- root register name.
start (int) -- index of the range start; index 0 is the least significant bit.
width (int) -- bit width of the range.
- register¶
- start¶
- width¶
- class oracq.infrastructure.ir.Ref(parts, type)[源代码]¶
基类:
objectRegister view concatenated from least to most significant bit, carrying no physical qubit numbers.
- parts¶
- type¶
- property width¶
Total bit width of the view, i.e. the bit width of
type.
- oracq.infrastructure.ir.fuse(*refs)[源代码]¶
Concatenate multiple views from least to most significant bit into a composite view that may cross root registers.
- 参数:
*refs -- sequence of views occupying low to high bits in order.
- 返回:
new view whose
partsare concatenated in order, interpreted asbits.- 返回类型:
- class oracq.infrastructure.ir.QRAM(address_width, data_width)[源代码]¶
基类:
objectType declaration of a QRAM resource.
Memory is a mapping from addresses to unsigned data words with unspecified cells equal to zero; contents are not written into the program JSON and are bound separately as execution input.
- 变量:
address_width (int) -- bit width of an address word in 1..64.
data_width (int) -- bit width of a data word in 1..64.
- address_width¶
- data_width¶
- class oracq.infrastructure.ir.Resource(name, type)[源代码]¶
基类:
objectFormal QRAM parameter declaration of a module.
- 变量:
name (str) -- resource name; unique within the module and free of conflicts with register names.
type (oracq.infrastructure.ir.QRAM) --
QRAMtype of the resource.
- name¶
- type¶
- class oracq.infrastructure.ir.Primitive(op, operands, angle=None, value=None)[源代码]¶
基类:
objectRegister-level primitive instruction.
A broadcast gate stays a single register-level operation in the IR and is not split for containing multiple physical gates.
- 变量:
op (str) -- gate name, such as
h,rx,phase,xor,swap,add_const.operands (tuple[oracq.infrastructure.ir.Ref, ...]) -- tuple of operand views.
angle (float | None) -- rotation or phase angle in radians;
Nonefor gates that do not use it.value (int | None) -- modular addend of
add_const;Nonefor gates that do not use it.
- op¶
- operands¶
- angle = None¶
- value = None¶
- class oracq.infrastructure.ir.Load(resource, address, data)[源代码]¶
基类:
objectQRAM query instruction:
datais XORed with the content of the addressed cell.The instruction is self-inverse, does not require the target to start at zero, and does not modify the address or the classical memory.
- 变量:
resource (str) -- formal QRAM resource name being queried.
address (oracq.infrastructure.ir.Ref) -- address view; its width must match the resource declaration.
data (oracq.infrastructure.ir.Ref) -- data view; its width must match the resource declaration and it must not overlap the address.
- resource¶
- address¶
- data¶
- class oracq.infrastructure.ir.Store(resource, address, data)[源代码]¶
基类:
objectQRAM random-write instruction: at execution time assigns the classical cell to the data view.
The address and data views must be in a definite basis state; the instruction changes no qubits, may only appear in a module body or a
Repeatbody, and is forbidden insideControlandAdjointbodies.- 变量:
resource (str) -- formal QRAM resource name being written.
address (oracq.infrastructure.ir.Ref) -- address view; its width must match the resource declaration.
data (oracq.infrastructure.ir.Ref) -- data view; its width must match the resource declaration and it must not overlap the address.
- resource¶
- address¶
- data¶
- class oracq.infrastructure.ir.Call(module, arguments, resources=())[源代码]¶
基类:
objectModule call instruction; the callee definition is shared in the
Programand not inlined at call sites.- 变量:
module (str) -- callee module name.
arguments (tuple[oracq.infrastructure.ir.Ref, ...]) -- quantum argument views bound in callee signature order.
resources (tuple[str, ...]) -- resource argument names bound in callee signature order.
- module¶
- arguments¶
- resources = ()¶
- class oracq.infrastructure.ir.Repeat(count, body)[源代码]¶
基类:
objectStatic repetition instruction: applies the body instructions in order
counttimes.The generation and serialization stages do not copy the instruction body by
count.- 变量:
count (int) -- repeat count in 0..2^63-1; zero repetitions is the identity operation.
body (tuple[oracq.infrastructure.ir.Primitive | oracq.infrastructure.ir.Load | oracq.infrastructure.ir.Store | oracq.infrastructure.ir.Call | oracq.infrastructure.ir.Repeat | oracq.infrastructure.ir.Control | oracq.infrastructure.ir.Adjoint, ...]) -- tuple of instructions being repeated; it must be structurally valid even when
countis zero.
- count¶
- body¶
- class oracq.infrastructure.ir.Control(register, value, body)[源代码]¶
基类:
objectCoherent control instruction: applies the body instructions when the control view equals the given value, otherwise is the identity.
The control register participates in coherent control as a quantum condition and is not measured; the control bits are protected throughout the
body.- 变量:
register (oracq.infrastructure.ir.Ref) -- nonempty control view.
value (int) -- unsigned comparison value for the control view.
body (tuple[oracq.infrastructure.ir.Primitive | oracq.infrastructure.ir.Load | oracq.infrastructure.ir.Store | oracq.infrastructure.ir.Call | oracq.infrastructure.ir.Repeat | oracq.infrastructure.ir.Control | oracq.infrastructure.ir.Adjoint, ...]) -- tuple of instructions executed under control.
- register¶
- value¶
- body¶
- class oracq.infrastructure.ir.Adjoint(body)[源代码]¶
基类:
objectAdjoint instruction: reverses the order of the body instructions and takes the adjoint of each operation.
Creation does not rewrite or expand its body; a double adjoint recovers the original operation.
- 变量:
body (tuple[oracq.infrastructure.ir.Primitive | oracq.infrastructure.ir.Load | oracq.infrastructure.ir.Store | oracq.infrastructure.ir.Call | oracq.infrastructure.ir.Repeat | oracq.infrastructure.ir.Control | oracq.infrastructure.ir.Adjoint, ...]) -- tuple of instructions being adjointed.
- body¶
- oracq.infrastructure.ir.Instruction = oracq.infrastructure.ir.Primitive | oracq.infrastructure.ir.Load | oracq.infrastructure.ir.Store | oracq.infrastructure.ir.Call | oracq.infrastructure.ir.Repeat | oracq.infrastructure.ir.Control | oracq.infrastructure.ir.Adjoint¶
Union type alias of RIR instruction nodes.
- class oracq.infrastructure.ir.Module(name, registers, resources, body, attributes=(), locals=())[源代码]¶
基类:
objectModule definition consisting of a call signature, QRAM resources and an ordered instruction body.
- 变量:
name (str) -- module name; unique within the
Program.registers (tuple[oracq.infrastructure.ir.Register, ...]) -- ordered list of public quantum parameters.
resources (tuple[oracq.infrastructure.ir.Resource, ...]) -- ordered list of formal QRAM parameters.
body (tuple[oracq.infrastructure.ir.Primitive | oracq.infrastructure.ir.Load | oracq.infrastructure.ir.Store | oracq.infrastructure.ir.Call | oracq.infrastructure.ir.Repeat | oracq.infrastructure.ir.Control | oracq.infrastructure.ir.Adjoint, ...] | None) -- ordered instruction body;
Nonedenotes an open declaration, i.e. an oracle slot whose implementation is not yet bound.attributes (tuple[tuple[str, str | int | float | bool], ...]) -- ordered attribute pairs with values limited to strings, integers, finite floats or booleans.
locals (tuple[oracq.infrastructure.ir.Register, ...]) -- module-private work registers with zero input and zero output, not part of the public call signature.
- name¶
- registers¶
- resources¶
- body¶
- attributes = ()¶
- locals = ()¶
- class oracq.infrastructure.ir.Program(entry, modules, version='0.1')[源代码]¶
基类:
objectComplete program: the module table plus the entry module name.
- 变量:
entry (str) -- entry module name; must refer to a module defined in
modules.modules (tuple[oracq.infrastructure.ir.Module, ...]) -- all module definitions; definitions are shared across call sites without copying bodies.
version (str) -- RIR version string; the reader additionally accepts historic versions
0.1and0.2.
- entry¶
- modules¶
- version = '0.1'¶
- property module_map¶
Index of module definitions keyed by module name.
- property main¶
Definition of the entry module.