结构验证

oracq.infrastructure.validation

Closed operation set, type, aliasing, resource and acyclic call checks for RIR.

oracq.infrastructure.validation.KINDS = {'bits', 'rational', 'sint', 'uint'}

Set of register kinds that are allowed.

oracq.infrastructure.validation.UNARY = {'h', 'phase', 'rx', 'ry', 'rz', 's', 't', 'x', 'y', 'z'}

Set of allowed unary quantum primitive operation names.

oracq.infrastructure.validation.ROTATIONS = {'phase', 'rx', 'ry', 'rz'}

Set of rotation primitive names that carry an angle argument; a subset of UNARY.

oracq.infrastructure.validation.BINARY = {'swap', 'xor'}

Set of allowed binary quantum primitive operation names.

oracq.infrastructure.validation.IDENTIFIER = re.compile('[A-Za-z_][A-Za-z0-9_]*\\Z')

starts with a letter or underscore, followed by letters, digits or underscores.

Type:

Regex pattern for valid identifiers

oracq.infrastructure.validation.require(condition, message)[源代码]

Assert that a structural check condition holds, otherwise raise ValidationError.

参数:
  • condition -- check result interpreted with boolean semantics.

  • message -- error description written into the exception on failure.

抛出:

ValidationError -- condition is false.

oracq.infrastructure.validation.integer(value, lo, hi, message)[源代码]

Assert that value is an integer within the closed interval lo..hi.

参数:
  • value -- value to check.

  • lo -- minimum allowed value, inclusive.

  • hi -- maximum allowed value, inclusive.

  • message -- error description written into the exception on failure.

抛出:

ValidationError -- value is not an int or lies outside the interval.

oracq.infrastructure.validation.name(value)[源代码]

Assert that value is a valid identifier string matching the IDENTIFIER pattern.

参数:

value -- identifier to check, such as a register name, resource name or module name.

抛出:

ValidationError -- value is not a string or contains illegal characters.

oracq.infrastructure.validation.reg_type(dtype)[源代码]

Assert that dtype is a register type with a known kind and width 0..64.

参数:

dtype -- storage type object to check.

抛出:

ValidationError -- dtype is not a RegType, its kind is unknown, or its width is out of range.

oracq.infrastructure.validation.locations(ref)[源代码]

Expand all qubit coordinates covered by a view reference.

参数:

ref -- register view to expand.

返回:

tuple of (register name, bit index) pairs in view segment order.

返回类型:

tuple

oracq.infrastructure.validation.capture_map(module)[源代码]

Parse the linker resource-origin attribute; ensures the referenced mapping exists and is one-to-one.

oracq.infrastructure.validation.validate(program, *, require_closed=False)[源代码]

Run full structural validation on an RIR program and return it unchanged.

Covers cross-node rules such as module signatures and attributes, register and view rules, primitive arity and aliasing constraints, control register protection, QRAM resource matching and an acyclic call graph, and checks that modules called in a controlled or adjoint context provide the corresponding capabilities; the rules stay consistent with docs/reference/rir.md.

参数:
  • program -- Program to validate.

  • require_closed -- when true, additionally require the program to contain no unbound open oracle declarations.

返回:

the same program object that passed validation.

返回类型:

Program

抛出:

ValidationError -- the program violates a structural or semantic constraint; or a standard exception indicating that the input is not a valid RIR object was caught.