Skip to main contentIBM Quantum Documentation
This page is from a dev version of Qiskit SDK. This is a new interface that does not exist in the stable version.

BitFlipOracleGate

class qiskit.circuit.library.BitFlipOracleGate(expression, var_order=None, label=None)

GitHub

Bases: Gate

Implements a bit-flip oracle

The Bit-flip Oracle Gate object constructs circuits for any arbitrary input logical expressions. A logical expression is composed of logical operators & (logical AND), | (logical OR), ~ (logical NOT), and ^ (logical XOR). as well as symbols for literals (variables). For example, ‘a & b’, and (v0 | ~v1) & (~v2 & v3) are both valid string representation of boolean logical expressions.

A bit-flip oracle for a boolean function f(x) performs the following quantum operation:

xyxf(x)y|x\rangle|y\rangle \mapsto |x\rangle|f(x)\oplus y\rangle

For convenience, this oracle, in addition to parsing arbitrary logical expressions, also supports input strings in the DIMACS CNF format, which is the standard format for specifying SATisfiability (SAT) problem instances in Conjunctive Normal Form (CNF), which is a conjunction of one or more clauses, where a clause is a disjunction of one or more literals. See qiskit.circuit.library.bit_flip_oracle.BitFlipOracleGate.from_dimacs_file().

From 16 variables on, possible performance issues should be expected when using the default synthesizer.

Parameters

  • expression (str) – A Python-like boolean expression.
  • var_order (list[str] | None) – A list with the order in which variables will be created. (default: by appearance)
  • label (str | None) – A label for the gate to display in visualizations. Per default, the label is set to display the textual represntation of the boolean expression (truncated if needed)

Attributes

base_class

Get the base class of this instruction. This is guaranteed to be in the inheritance tree of self.

The “base class” of an instruction is the lowest class in its inheritance tree that the object should be considered entirely compatible with for _all_ circuit applications. This typically means that the subclass is defined purely to offer some sort of programmer convenience over the base class, and the base class is the “true” class for a behavioral perspective. In particular, you should not override base_class if you are defining a custom version of an instruction that will be implemented differently by hardware, such as an alternative measurement strategy, or a version of a parametrized gate with a particular set of parameters for the purposes of distinguishing it in a Target from the full parametrized gate.

This is often exactly equivalent to type(obj), except in the case of singleton instances of standard-library instructions. These singleton instances are special subclasses of their base class, and this property will return that base. For example:

>>> isinstance(XGate(), XGate)
True
>>> type(XGate()) is XGate
False
>>> XGate().base_class is XGate
True

In general, you should not rely on the precise class of an instruction; within a given circuit, it is expected that Instruction.name should be a more suitable discriminator in most situations.

decompositions

Get the decompositions of the instruction from the SessionEquivalenceLibrary.

definition

Return definition in terms of other basic gates.

label

Return instruction label

mutable

Is this instance is a mutable unique instance or not.

If this attribute is False the gate instance is a shared singleton and is not mutable.

name

Return the name.

num_clbits

Return the number of clbits.

num_qubits

Return the number of qubits.

params

The parameters of this Instruction. Ideally these will be gate angles.


Methods

from_dimacs_file

classmethod from_dimacs_file(filename)

GitHub

Create a BitFlipOracleGate from the string in the DIMACS format.

It is possible to build a BitFlipOracleGate from a file in DIMACS CNF format, which is the standard format for specifying SATisfiability (SAT) problem instances in Conjunctive Normal Form (CNF), which is a conjunction of one or more clauses, where a clause is a disjunction of one or more literals.

The following is an example of a CNF expressed in the DIMACS format:

c DIMACS CNF file with 3 satisfying assignments: 1 -2 3, -1 -2 -3, 1 2 -3.
p cnf 3 5
-1 -2 -3 0
1 -2 3 0
1 2 -3 0
1 -2 -3 0
-1 2 3 0

The first line, following the c character, is a comment. The second line specifies that the CNF is over three boolean variables — let us call them x1,x2,x3x_1, x_2, x_3, and contains five clauses. The five clauses, listed afterwards, are implicitly joined by the logical AND operator, \land, while the variables in each clause, represented by their indices, are implicitly disjoined by the logical OR operator, \lor. The - symbol preceding a boolean variable index corresponds to the logical NOT operator, ¬\lnot. Character 0 (zero) marks the end of each clause. Essentially, the code above corresponds to the following CNF:

(¬x1¬x2¬x3)(x1¬x2x3)(x1x2¬x3)(x1¬x2¬x3)(¬x1x2x3)(\lnot x_1 \lor \lnot x_2 \lor \lnot x_3) \land (x_1 \lor \lnot x_2 \lor x_3) \land (x_1 \lor x_2 \lor \lnot x_3) \land (x_1 \lor \lnot x_2 \lor \lnot x_3) \land (\lnot x_1 \lor x_2 \lor x_3).

Parameters

filename (str) – A file in DIMACS format.

Returns

A quantum gate with a bit-flip oracle.

Return type

BitFlipOracleGate

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