Skip to main contentIBM Quantum Documentation
This page is from an old version of Qiskit SDK and does not exist in the latest version. We recommend you migrate to the latest version. See the release notes for more information.

qiskit.aqua.components.oracles.CustomCircuitOracle

class CustomCircuitOracle(variable_register, output_register, circuit, ancillary_register=None, evaluate_classically_callback=None)

GitHub

The Custom Circuit-based Quantum Oracle.

A helper class to, in essence, ‘wrap’ a user-supplied quantum circuit such that it becomes of type Oracle and hence can be used by algorithms taking an oracle as input.

This class is provided for easy creation of oracles using custom circuits. It is geared towards programmatically experimenting with oracles, where a user directly provides a QuantumCircuit object, corresponding to the intended oracle function, together with the various QuantumRegister objects involved.

Note

The evaluate_classically_callback param is to supply a method to classically evaluate the function (as encoded by the oracle) on a particular input bitstring. For example for an oracle that encodes 3-SAT problems, this method would determine classically if an input variable assignment would satisfy the 3-SAT expression.

The input bitstring is a string of 1’s and 0’s corresponding to the input variable(s). The return should be a (bool, List[int]) tuple where the bool corresponds to the return value of the binary function encoded by the oracle, and the List[int] should just be a different representation of the input variable assignment, which should be equivalent to the bitstring or a quantum measurement.

Examples of existing implementations, for reference, can be found in other oracles such as TruthTableOracle.evaluate_classically() and LogicalExpressionOracle.evaluate_classically().

Parameters

  • variable_register (QuantumRegister) – The register holding variable qubit(s) for the oracle function
  • output_register (QuantumRegister) – The register holding output qubit(s) for the oracle function
  • circuit (QuantumCircuit) – The quantum circuit corresponding to the intended oracle function
  • ancillary_register (Optional[QuantumRegister]) – The register holding ancillary qubit(s)
  • evaluate_classically_callback (Optional[Callable[[str], Tuple[bool, List[int]]]]) – The classical callback function for evaluating the oracle, for example, to use with Grover’s search

Raises

AquaError – Invalid input

__init__

__init__(variable_register, output_register, circuit, ancillary_register=None, evaluate_classically_callback=None)

Parameters

  • variable_register (QuantumRegister) – The register holding variable qubit(s) for the oracle function
  • output_register (QuantumRegister) – The register holding output qubit(s) for the oracle function
  • circuit (QuantumCircuit) – The quantum circuit corresponding to the intended oracle function
  • ancillary_register (Optional[QuantumRegister]) – The register holding ancillary qubit(s)
  • evaluate_classically_callback (Optional[Callable[[str], Tuple[bool, List[int]]]]) – The classical callback function for evaluating the oracle, for example, to use with Grover’s search

Raises

AquaError – Invalid input


Methods

__init__(variable_register, output_register, …)type variable_registerQuantumRegister
construct_circuit()Construct the oracle circuit.

Attributes

ancillary_registerreturns ancillary register
circuit
output_registerreturns output register
variable_registerreturns variable register

ancillary_register

returns ancillary register

circuit

construct_circuit

construct_circuit()

Construct the oracle circuit.

Returns

A quantum circuit for the oracle.

Return type

QuantumCircuit

output_register

returns output register

variable_register

returns variable register

Was this page helpful?
Report a bug or request content on GitHub.