State-preparation composition

oracq.algorithms.common.state_preparation

Composition utilities for initial state extension, applying encodings and physical subspace selection.

oracq.algorithms.common.state_preparation.extend_initial(prep, extra_width)[source]

Extend the target space of a state preparation prep by extra_width high bits.

The original preparation acts on the low bits of the extended target and the new high bits stay zero; the zero-input promise is preserved.

Parameters:
  • prep – The original StatePreparation.

  • extra_width – Number of high qubits to append.

Returns:

Preparation whose target width is prep.width + extra_width.

Return type:

StatePreparation

oracq.algorithms.common.state_preparation.select_subspace(state, output_width, high_value=0, *, label='selection')[source]

Select the physical subspace out of the target space of a state oracle.

The low output_width bits serve as the output, while the remaining high bits are folded into signal and required to equal high_value; the success condition is that the whole signal register returns to zero.

Parameters:
  • state – The input StateOracle, with width not less than output_width.

  • output_width – The selected physical output width.

  • high_value – The value that the discarded high bits must equal, zero by default.

  • label – Label used for the generated module name and algorithm attribute.

Returns:

State oracle with output width output_width and a signal holding the original signal bits plus the appended high bits.

Return type:

StateOracle

Raises:

ValidationError – output_width exceeds state.width, or high_value is out of range.

oracq.algorithms.common.state_preparation.apply_be_to_state(a, prep)[source]

Apply a block encoding a to an already prepared initial state, yielding a state oracle.

The signal bits of a occupy the low bits of signal and the workspace of prep is folded into its high bits; the success condition is that the whole signal register returns to zero.

Parameters:
  • a – The BlockEncoding of the operator to apply.

  • prep – A StatePreparation with the same target width as a.

Returns:

State oracle with unchanged target width and an attached signal register.

Return type:

StateOracle

Raises:

ValidationError – The two target widths differ.