PhaseOracleGate
class qiskit.circuit.library.PhaseOracleGate(expression, var_order=None, label=None)
Bases: Gate
Implements a phase oracle.
The Phase 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 phase oracle for a boolean function f(x) performs the following quantum operation:
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.phase_oracle.PhaseOracleGate.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)
Create a PhaseOracle from the string in the DIMACS format.
It is possible to build a PhaseOracle 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 , and contains five clauses. The five clauses, listed afterwards, are implicitly joined by the logical AND operator, , while the variables in each clause, represented by their indices, are implicitly disjoined by the logical OR operator, . The symbol preceding a boolean variable index corresponds to the logical NOT operator, . Character 0 (zero) marks the end of each clause. Essentially, the code above corresponds to the following CNF:
.
Parameters
filename (str) – A file in DIMACS format.
Returns
A quantum circuit with a phase oracle.
Return type