# Grover, CCZ Gate on IBM Quantum Lab & unexpected outputs

Studying Grover on IBM lab using Qiskit. But the following code produces unexpected outputs. Note that PhaseOracle produces 2 CCZ gates. Could anyone check (and explain) why are those unexpected counts/outputs(given at the bottom) being produced?

Note that when I try a similar code with similar logical expressions with aqua (which is deprecated, the expected outputs are produced)

from qiskit import *
from qiskit.tools.visualization import plot_histogram
from qiskit.circuit.library import PhaseOracle
from qiskit.algorithms import Grover, AmplificationProblem
%matplotlib inline

matplotlib inline
oracle = PhaseOracle('((A & C) | (B & D)) & ~(C & D)')
problem = AmplificationProblem(oracle=oracle, is_good_state=oracle.evaluate_bitstring)
backend = Aer.get_backend('qasm_simulator')
grover = Grover(quantum_instance=backend)
result = grover.amplify(problem)
print(result.circuit_results)
{'0111': 259, '1100': 244, '1101': 234, '0011': 287}

• Note that; if I set up the circuit manually, I can achieve correct results with expected probabilities. For example, I can catch 100% "111" with a manually created circuit with 3 qbits. (for a logical expression like (A&B&C) However, the code given above below not return 111 with 100% probability. Jan 24 at 9:02
• from qiskit import * from qiskit.tools.visualization import plot_histogram from qiskit.circuit.library import PhaseOracle from qiskit.algorithms import Grover, AmplificationProblem %matplotlib inline matplotlib inline oracle = PhaseOracle('((A & B & C)') problem = AmplificationProblem(oracle=oracle, is_good_state=oracle.evaluate_bitstring) backend = Aer.get_backend('qasm_simulator') grover = Grover(quantum_instance=backend) result = grover.amplify(problem) print(result.circuit_results) Jan 24 at 9:02

Qiskit Terra internally uses Tweedledum library to parse logical expressions. By default, Tweedledum sort the variables by the order of their appearance in the logical expressions. In your case, the order is A then C then B and finally D. So, you should interpret the output bitstring as DBCA.
On the other hand, in Qiskit Aqua's LogicalExpressionOracle` the variables used to be sorted alphabetically.