Structural validation

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)[source]

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

Parameters:
  • condition – check result interpreted with boolean semantics.

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

Raises:

ValidationError – condition is false.

oracq.infrastructure.validation.integer(value, lo, hi, message)[source]

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

Parameters:
  • value – value to check.

  • lo – minimum allowed value, inclusive.

  • hi – maximum allowed value, inclusive.

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

Raises:

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

oracq.infrastructure.validation.name(value)[source]

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

Parameters:

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

Raises:

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

oracq.infrastructure.validation.reg_type(dtype)[source]

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

Parameters:

dtype – storage type object to check.

Raises:

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

oracq.infrastructure.validation.locations(ref)[source]

Expand all qubit coordinates covered by a view reference.

Parameters:

ref – register view to expand.

Returns:

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

Return type:

tuple

oracq.infrastructure.validation.capture_map(module)[source]

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

oracq.infrastructure.validation.validate(program, *, require_closed=False)[source]

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.

Parameters:
  • program – Program to validate.

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

Returns:

the same program object that passed validation.

Return type:

Program

Raises:

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.