算法结构协议

oracq.algorithms.input_model.interfaces

Python structural protocols shared by the algorithm library; applications may keep defining protocols in their own modules.

class oracq.algorithms.input_model.interfaces.StatePreparationProtocol(*args, **kwargs)[源代码]

基类:Protocol

Requires a state_preparation() method; anything satisfying it can serve as an algorithm's initial-state input.

state_preparation()[源代码]

Return the StatePreparation access view corresponding to this input.

返回:

View that prepares the target state on this input's zero-input registers.

返回类型:

StatePreparation

class oracq.algorithms.input_model.interfaces.UnitaryProtocol(*args, **kwargs)[源代码]

基类:StatePreparationProtocol, Protocol

Adds the full unitary interface unitary() on top of the state-preparation protocol.

unitary()[源代码]

Return the unitary Operation on the full register space.

返回:

Unitary operation acting on all registers of this input.

返回类型:

Operation

class oracq.algorithms.input_model.interfaces.BlockEncodingProtocol(*args, **kwargs)[源代码]

基类:Protocol

Requires a block_encoding() method; anything satisfying it can serve as a block-encoding input.

block_encoding()[源代码]

Return the BlockEncoding access view corresponding to this input.

返回:

Access view encoding this input as a normalized sub-block of a unitary.

返回类型:

BlockEncoding

class oracq.algorithms.input_model.interfaces.CKSSparseProtocol(*args, **kwargs)[源代码]

基类:Protocol

Requires a sparse_access() method; anything satisfying it can serve as a CKS sparse-matrix input.

sparse_access()[源代码]

Return the SparseAccess composed of the CKS location and entry operations.

返回:

Sparse access view composed of a location oracle and an entry oracle.

返回类型:

SparseAccess

class oracq.algorithms.input_model.interfaces.XorDatabaseProtocol(*args, **kwargs)[源代码]

基类:Protocol

Requires a xor_database() method; anything satisfying it can serve as an XOR database input.

xor_database()[源代码]

Return the XorDatabase access view corresponding to this input.

返回:

Database access view that answers queries by XOR.

返回类型:

XorDatabase

class oracq.algorithms.input_model.interfaces.StateOracleProtocol(*args, **kwargs)[源代码]

基类:Protocol

Requires a state_oracle() method; anything satisfying it can serve as an output-state oracle.

state_oracle()[源代码]

Return the StateOracle carrying a success signal.

返回:

Oracle that marks the success subspace within the output state.

返回类型:

StateOracle

oracq.algorithms.input_model.interfaces.as_state_preparation(value)[源代码]

Convert a protocol-satisfying input into a StatePreparation.

参数:

value -- Object satisfying StatePreparationProtocol.

返回:

The concrete view obtained by calling state_preparation().

返回类型:

StatePreparation

抛出:

ContractError -- Reported as INPUT_PROTOCOL when the interface is missing; as INPUT_TYPE when the return value is not a StatePreparation.

oracq.algorithms.input_model.interfaces.checked_state_preparation(value, *, adjoint=False, controlled=False, path='preparation')[源代码]

Obtain a zero-input, clean-work preparation; the calling algorithm selects the transformation capabilities it needs.

参数:
  • value -- Input object satisfying StatePreparationProtocol.

  • adjoint -- Whether the preparation must offer a Hermitian-adjoint version.

  • controlled -- Whether the preparation must support a controlled version.

  • path -- Path name of this input in the contract report.

返回:

Preparation view that passed the zero-input and clean-work checks.

返回类型:

StatePreparation

oracq.algorithms.input_model.interfaces.as_block_encoding(value)[源代码]

Convert a protocol-satisfying input into a BlockEncoding.

参数:

value -- Object satisfying BlockEncodingProtocol.

返回:

The concrete view obtained by calling block_encoding().

返回类型:

BlockEncoding

抛出:

ContractError -- Reported as INPUT_PROTOCOL when the interface is missing; as INPUT_TYPE when the return value is not a BlockEncoding.

oracq.algorithms.input_model.interfaces.as_sparse_access(value)[源代码]

Convert a protocol-satisfying input into a SparseAccess.

参数:

value -- Object satisfying CKSSparseProtocol.

返回:

The concrete view obtained by calling sparse_access().

返回类型:

SparseAccess

抛出:

ContractError -- Reported as INPUT_PROTOCOL when the interface is missing; as INPUT_TYPE when the return value is not a SparseAccess.

oracq.algorithms.input_model.interfaces.as_qlss_matrix(value)[源代码]

Convert a matrix input into a BlockEncoding or SparseAccess according to the available interface.

When BlockEncodingProtocol is satisfied the block-encoding view is returned preferentially; otherwise the sparse access view is taken per CKSSparseProtocol.

参数:

value -- Matrix input object.

返回:

A BlockEncoding when the block-encoding protocol is satisfied, otherwise a SparseAccess.

抛出:

ContractError -- Neither protocol is satisfied, or the obtained return value has the wrong type.

oracq.algorithms.input_model.interfaces.operator_state_contract(name, *, matrix='generator', state='initial', composable=True)[源代码]

Requirements of the current BE-type evolution algorithms; other algorithms may define entirely different contracts.

参数:
  • name -- Contract name, used in reports and diagnostics.

  • matrix -- Path name of the block-encoding matrix input in the contract.

  • state -- Path name of the initial-state preparation input in the contract.

  • composable -- Whether the initial state requires adjoint and controlled capabilities for use by composable algorithms.

返回:

Contract requiring the matrix to be a block encoding with adjoint and controlled capabilities, the initial state to be a zero-input and clean-work preparation, and constraining both to equal register widths.

返回类型:

AlgorithmContract