算法结构协议¶
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)[源代码]¶
基类:
ProtocolRequires a
state_preparation()method; anything satisfying it can serve as an algorithm's initial-state input.
- class oracq.algorithms.input_model.interfaces.UnitaryProtocol(*args, **kwargs)[源代码]¶
基类:
StatePreparationProtocol,ProtocolAdds the full unitary interface
unitary()on top of the state-preparation protocol.
- class oracq.algorithms.input_model.interfaces.BlockEncodingProtocol(*args, **kwargs)[源代码]¶
基类:
ProtocolRequires a
block_encoding()method; anything satisfying it can serve as a block-encoding input.
- class oracq.algorithms.input_model.interfaces.CKSSparseProtocol(*args, **kwargs)[源代码]¶
基类:
ProtocolRequires a
sparse_access()method; anything satisfying it can serve as a CKS sparse-matrix input.
- class oracq.algorithms.input_model.interfaces.XorDatabaseProtocol(*args, **kwargs)[源代码]¶
基类:
ProtocolRequires a
xor_database()method; anything satisfying it can serve as an XOR database input.
- class oracq.algorithms.input_model.interfaces.StateOracleProtocol(*args, **kwargs)[源代码]¶
基类:
ProtocolRequires a
state_oracle()method; anything satisfying it can serve as an output-state oracle.
- 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().- 返回类型:
- 抛出:
ContractError -- Reported as
INPUT_PROTOCOLwhen the interface is missing; asINPUT_TYPEwhen the return value is not aStatePreparation.
- 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.
- 返回类型:
- 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().- 返回类型:
- 抛出:
ContractError -- Reported as
INPUT_PROTOCOLwhen the interface is missing; asINPUT_TYPEwhen the return value is not aBlockEncoding.
- 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().- 返回类型:
- 抛出:
ContractError -- Reported as
INPUT_PROTOCOLwhen the interface is missing; asINPUT_TYPEwhen the return value is not aSparseAccess.
- oracq.algorithms.input_model.interfaces.as_qlss_matrix(value)[源代码]¶
Convert a matrix input into a
BlockEncodingorSparseAccessaccording to the available interface.When
BlockEncodingProtocolis satisfied the block-encoding view is returned preferentially; otherwise the sparse access view is taken perCKSSparseProtocol.- 参数:
value -- Matrix input object.
- 返回:
A
BlockEncodingwhen the block-encoding protocol is satisfied, otherwise aSparseAccess.- 抛出:
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.
- 返回类型: