Три фазовых оракула
Создайте ещё три схемы оракулов, отмечающие остальные вычислительные состояния $|00\rangle$, $|01\rangle$, $|10\rangle$. Используйте display_unitary для проверки.
Данный пример CZ(0,1) меняет знак только $|11\rangle$. Подсказка автора: постройте преобразования выбранного состояния в 11 и обратно и сочетайте их с CZ. Порядок битов q1q0. Полная исходная функция отображения матрицы сохранена.
Исходная программа (сохранена без исполнения):
from qiskit import QuantumCircuit
oracle = QuantumCircuit(2)
oracle.cz(0,1) # invert phase of |11>
oracle.draw()
def display_unitary(qc, prefix=""):
"""Simulates a simple circuit and display its matrix representation.
Args:
qc (QuantumCircuit): The circuit to compile to a unitary matrix
prefix (str): Optional LaTeX to be displayed before the matrix
Returns:
None (displays matrix as side effect)
"""
from qiskit import Aer
from qiskit.visualization import array_to_latex
sim = Aer.get_backend('aer_simulator')
# Next, we'll create a copy of the circuit and work on
# that so we don't change anything as a side effect
qc = qc.copy()
# Tell the simulator to save the unitary matrix of this circuit
qc.save_unitary()
unitary = sim.run(qc).result().get_unitary()
display(array_to_latex(unitary, prefix=prefix))
display_unitary(oracle, "U_\\text{oracle}=")