83 lines
4.3 KiB
Plaintext
83 lines
4.3 KiB
Plaintext
---
|
||
title: classicalfunction
|
||
description: API reference for qiskit.circuit.classicalfunction
|
||
in_page_toc_min_heading_level: 2
|
||
python_api_type: module
|
||
python_api_name: qiskit.circuit.classicalfunction
|
||
---
|
||
|
||
<span id="module-qiskit.circuit.classicalfunction" />
|
||
|
||
<span id="qiskit-circuit-classicalfunction" />
|
||
|
||
# ClassicalFunction compiler
|
||
|
||
<span id="module-qiskit.circuit.classicalfunction" />
|
||
|
||
`qiskit.circuit.classicalfunction`
|
||
|
||
## Overview
|
||
|
||
The classical function compiler provides the necessary tools to map a classical irreversible functions into quantum circuits. Below is a simple example of how to synthesize a simple boolean function defined using Python into a QuantumCircuit:
|
||
|
||
> ```python
|
||
> from qiskit.circuit import classical_function, Int1
|
||
>
|
||
> @classical_function
|
||
> def grover_oracle(a: Int1, b: Int1, c: Int1, d: Int1) -> Int1:
|
||
> return (not a and b and not c and d)
|
||
>
|
||
> quantum_circuit = grover_oracle.synth()
|
||
> quantum_circuit.draw()
|
||
> ```
|
||
>
|
||
> ```python
|
||
>
|
||
> q_0: ──o──
|
||
> │
|
||
> q_1: ──■──
|
||
> │
|
||
> q_2: ──o──
|
||
> │
|
||
> q_3: ──■──
|
||
> ┌─┴─┐
|
||
> q_4: ┤ X ├
|
||
> └───┘
|
||
> ```
|
||
|
||
Following Qiskit’s little-endian bit ordering convention, the left-most bit (a) is the most significant bit and the right-most bit (d) is the least significant bit. The resulting
|
||
|
||
## Supplementary Information
|
||
|
||
**Tweedledum**
|
||
|
||
Tweedledum is a C++-17 header-only library that implements a large set of reversible (and quantum) synthesis, optimization, and mapping algorithms. The classical function compiler relies on it and its dependencies to both represent logic networks and synthesize them into quantum circuits.
|
||
|
||
**ClassicalFunction data types**
|
||
|
||
At the moment, the only type supported by the classical\_function compilers is `qiskit.circuit.classicalfunction.types.Int1`. The classical function function to parse *must* include type hints (just `Int1` for now). The resulting gate will be a gate in the size of the sum of all the parameters and the return.
|
||
|
||
The type `Int1` means the classical function will only operate at bit level.
|
||
|
||
## ClassicalFunction compiler API
|
||
|
||
### classical\_function
|
||
|
||
Decorator for a classical function that returns a ClassicalFunction object.
|
||
|
||
### ClassicalFunction
|
||
|
||
| | |
|
||
| --------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
|
||
| [`ClassicalFunction`](qiskit.circuit.classicalfunction.ClassicalFunction "qiskit.circuit.classicalfunction.ClassicalFunction")(source\[, name]) | Represent a classical function function and its logic network. |
|
||
| [`BooleanExpression`](qiskit.circuit.classicalfunction.BooleanExpression "qiskit.circuit.classicalfunction.BooleanExpression")(expression\[, name]) | The Boolean Expression gate. |
|
||
|
||
### Exceptions
|
||
|
||
| | |
|
||
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------- |
|
||
| [`ClassicalFunctionCompilerTypeError`](qiskit.circuit.classicalfunction.ClassicalFunctionCompilerTypeError "qiskit.circuit.classicalfunction.ClassicalFunctionCompilerTypeError")(\*message) | ClassicalFunction compiler type error. |
|
||
| [`ClassicalFunctionParseError`](qiskit.circuit.classicalfunction.ClassicalFunctionParseError "qiskit.circuit.classicalfunction.ClassicalFunctionParseError")(\*message) | ClassicalFunction compiler parse error. |
|
||
| [`ClassicalFunctionCompilerTypeError`](qiskit.circuit.classicalfunction.ClassicalFunctionCompilerTypeError "qiskit.circuit.classicalfunction.ClassicalFunctionCompilerTypeError")(\*message) | ClassicalFunction compiler type error. |
|
||
|