In this notebook, we simulate a 10-qubit Quantum Fourier Transform (QFT) algorithm. The QFT algorithm is one of the most important quantum algorithms in quantum computing. It is, for instance, part of the Shor algorithm for integer factorization. The following code defines a 10-qubit QFT algorithm using CNOT and single qubit rotations and runs the simulation both at the gate level and at the pulse level.

In [1]:

```
from qutip import basis, fidelity
from qutip_qip.algorithms import qft_gate_sequence
from qutip_qip.device import LinearSpinChain
from qutip.ipynbtools import version_table
import qutip_qip
num_qubits = 10
# The QFT circuit
qc = qft_gate_sequence(num_qubits, swapping=False, to_cnot=True)
# Gate-level simulation
state1 = qc.run(basis([2] * num_qubits, [0] * num_qubits))
# Pulse-level simulation
processor = LinearSpinChain(num_qubits)
processor.load_circuit(qc)
state2 = processor.run_state(basis([2] * num_qubits,
[0] * num_qubits)).states[-1]
fidelity(state1, state2)
```

Out[1]:

0.9999593896497468

In [2]:

```
def get_control_latex(model):
"""
Get the labels for each Hamiltonian.
It is used in the method method :meth:`.Processor.plot_pulses`.
It is a 2-d nested list, in the plot,
a different color will be used for each sublist.
"""
num_qubits = model.num_qubits
num_coupling = model._get_num_coupling()
return [
{f"sx{m}": r"$\sigma_x^{}$".format(m) for m in range(num_qubits)},
{f"sz{m}": r"$\sigma_z^{}$".format(m) for m in range(num_qubits)},
{f"g{m}": r"$g_{}$".format(m) for m in range(num_coupling)},
]
fig, axes = processor.plot_pulses(
figsize=(5, 7), dpi=150, pulse_labels=get_control_latex(processor.model)
)
axes[-1].set_xlabel("$t$");
```

In [3]:

```
print("qutip-qip version:", qutip_qip.version.version)
version_table()
```

qutip-qip version: 0.3.0.dev0+fa929ff

Out[3]:

Software | Version |
---|---|

QuTiP | 4.7.1 |

Numpy | 1.22.4 |

SciPy | 1.8.1 |

matplotlib | 3.5.2 |

Cython | 0.29.33 |

Number of CPUs | 2 |

BLAS Info | Generic |

IPython | 8.11.0 |

Python | 3.10.4 | packaged by conda-forge | (main, Mar 24 2022, 17:39:04) [GCC 10.3.0] |

OS | posix [linux] |

Wed Mar 15 08:12:28 2023 UTC |