Source code for qolumbina.programs.parity.parity_phase
# This code is developed through cross-language conversion from
# https://github.com/MgcosA/Code_of_Testing_Oracle_Quantum_Program_Article/blob/master/qolumbina/programs/Parity.qs
#
# In detail, the raw program is written in Q#, and we rewrite it in Qiskit.
import numpy as np
from qiskit import QuantumCircuit
# ---------- benchmark registration ----------
from ..benchmark_registry import register_benchmark
from pathlib import Path
@register_benchmark(
Path(__file__).stem,
family=Path(__file__).resolve().parent.name,
description="Parity oracle (phase version)",
class_name="ParityPhase",
source={
"repo": "https://github.com/MgcosA/Code_of_Testing_Oracle_Quantum_Program_Article/blob/master/",
"file": "qolumbina/programs/Parity.qs",
"sdk": "Q#",
"available_doc": True
},
testability_refactoring=[
"Cross-language translation",
"Structure reorganization"
]
)
def create_parity_phase(input_qubits):
return ParityPhase(input_qubits=input_qubits)
[docs]
class ParityPhase(QuantumCircuit):
r"""
Phase version of the parity oracle.
"""
def __init__(self, input_qubits: int, name: str | None = None):
r"""
Args:
input_qubits: Number of input qubits :math:`n`.
name: Optional name of the circuit.
"""
super().__init__(input_qubits, name=name or "ParityPhase")
self._input_qubits = input_qubits
self._build()
def _build(self):
qs = self.qubits
# Qiskit does not have a direct MultiZ gate,
# we implement it by applying Z to all qubits
for q in qs:
self.z(q)