Twine QFT Service¶
The Quantum Fourier Transform (QFT) is a critical component of many quantum algorithms, but implementing it on real hardware is challenging due to the heavy overhead of moving quantum information around via SWAP gates.
The ParityOS TwineQFTService implements the state-of-the-art compilation method introduced in Demonstrating Record Fidelity for the Quantum Fourier Transform. Instead of using SWAP gates, the Parity Twine method tracks the flow of parity information across the hardware. This drastically reduces gate count and circuit depth, achieving record-breaking fidelity and enabling the execution of QFT circuits at unprecedented scales.
Prerequisites¶
Ensure you have the required packages installed in your Python environment:
parityosparityos-qiskitqiskit-ibm-runtime(optional)
Define the Target Device Model¶
Option A: Create a Custom Device Model¶
We define a custom 4x4 rectangular coupling map with nearest-neighbor connectivity supporting RZ and CNOT as native gates.
from parityos.devices.device_connectivity import get_rectangular_nearest_neighbor_connectivity
from parityos.devices.device_model import DeviceGate, DeviceModel, DeviceQubit
from parityos.operators import CNOT, RZ
# Create custom device model
dimensions = (4, 4)
nearest_neighbor_connectivity = get_rectangular_nearest_neighbor_connectivity(*dimensions)
native_operators = [DeviceGate(RZ(q)) for q in nearest_neighbor_connectivity.qubits] + [
DeviceGate(CNOT(*connection.qubits))
for connection in nearest_neighbor_connectivity.qubit_connections
if len(connection) == 2
]
device_qubits = {DeviceQubit(qubit) for qubit in nearest_neighbor_connectivity.qubits}
device_model = DeviceModel(device_qubits, native_operators)
Option B: Use an IBM Quantum Backend as Device Model¶
Alternatively, you can convert an existing IBM Quantum backend into a ParityOS device model using the parityos_qiskit adapter.
# Use IBM Quantum backend as device model
from parityos_qiskit.backend_to_device_model import convert_backend_to_device_model
from qiskit_ibm_runtime.fake_provider import FakeSherbrooke
backend = FakeSherbrooke()
device_model = convert_backend_to_device_model(backend)
Configure and Run the Twine QFT Service¶
With the device model ready, authenticate with ParityOS, initialize the service, and submit your QFT compilation job.
from parityos.services.authentication import InteractiveAuth
from parityos.services.client import HTTPClient
from parityos.services.service import TwineQFTInput, TwineQFTService
from parityos_qiskit.exporter import export_parityos_to_qiskit
client = HTTPClient(InteractiveAuth("my_parityos_username")) # authenticate
twine_qft_service = TwineQFTService(client) # instantiate the Twine QFT service
job_data = TwineQFTInput(number_of_qubits=4, device=device_model) # define input
result = twine_qft_service.run(job_data) # run parity twine qft compilation
Extract and Convert Results¶
The result object contains Parity Twine QFT circuit and a qubit mapping that depicts the qubit labels at the initialization and the end of the circuit.
You can export the ParityOS circuit back to Qiskit for using again the parityos_qiskit adapter.
pos_circuit = result.parameterized_circuit
qiskit_circuit = export_parityos_to_qiskit(pos_circuit) # convert ParityOS Circuit to Qiskit QuantumCircuit
print(qiskit_circuit.circuit)
print(result.relabeling_map)