Algorithm structure protocols¶
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)[source]¶
Bases:
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)[source]¶
Bases:
StatePreparationProtocol,ProtocolAdds the full unitary interface
unitary()on top of the state-preparation protocol.
- class oracq.algorithms.input_model.interfaces.BlockEncodingProtocol(*args, **kwargs)[source]¶
Bases:
ProtocolRequires a
block_encoding()method; anything satisfying it can serve as a block-encoding input.
- class oracq.algorithms.input_model.interfaces.CKSSparseProtocol(*args, **kwargs)[source]¶
Bases:
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)[source]¶
Bases:
ProtocolRequires a
xor_database()method; anything satisfying it can serve as an XOR database input.
- class oracq.algorithms.input_model.interfaces.StateOracleProtocol(*args, **kwargs)[source]¶
Bases:
ProtocolRequires a
state_oracle()method; anything satisfying it can serve as an output-state oracle.
- oracq.algorithms.input_model.interfaces.as_state_preparation(value)[source]¶
Convert a protocol-satisfying input into a
StatePreparation.- Parameters:
value – Object satisfying
StatePreparationProtocol.- Returns:
The concrete view obtained by calling
state_preparation().- Return type:
- Raises:
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')[source]¶
Obtain a zero-input, clean-work preparation; the calling algorithm selects the transformation capabilities it needs.
- Parameters:
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.
- Returns:
Preparation view that passed the zero-input and clean-work checks.
- Return type:
- oracq.algorithms.input_model.interfaces.as_block_encoding(value)[source]¶
Convert a protocol-satisfying input into a
BlockEncoding.- Parameters:
value – Object satisfying
BlockEncodingProtocol.- Returns:
The concrete view obtained by calling
block_encoding().- Return type:
- Raises:
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)[source]¶
Convert a protocol-satisfying input into a
SparseAccess.- Parameters:
value – Object satisfying
CKSSparseProtocol.- Returns:
The concrete view obtained by calling
sparse_access().- Return type:
- Raises:
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)[source]¶
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.- Parameters:
value – Matrix input object.
- Returns:
A
BlockEncodingwhen the block-encoding protocol is satisfied, otherwise aSparseAccess.- Raises:
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)[source]¶
Requirements of the current BE-type evolution algorithms; other algorithms may define entirely different contracts.
- Parameters:
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.
- Returns:
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.
- Return type: