GMSEnvironment#
- class GMSEnvironment(env_args=[])[source]#
This environment provides a convenient interface for constructing quantum algorithms using the Ion-trap native GMS gates. GMS gates allow entangling more than 2 qubits in a single step and can therefore boost performance in many situations. For more information on GMS gates consult https://arxiv.org/abs/quant-ph/9810040 . The techniques for converting the circuits presented to this environment are mostly based on https://ieeexplore.ieee.org/document/9815035 .
This environment allows to code blocks of phase-only gates as we are used to but compiles these blocks to GMS gates.
Examples
We create a function performing the quantum Fourier-transform using GMS gates:
from qrisp import QuantumEnvironment, GMSEnvironment, h, cp, swap import numpy as np def QFT(qv, use_gms = False): n = qv.size if use_gms: env = GMSEnvironment else: env = QuantumEnvironment for i in range(n): h(qv[i]) if i == n-1: break with env(): #This is the block which converted to GMS gates #We can only use the gates p, cp and rz in here for k in range(n-i-1): cp(2*np.pi/2**(k+2), qv[k+i+1], qv[i]) for i in range(n//2): swap(qv[i], qv[n-i-1])
We inspect the resulting quantum circuit:
>>> from qrisp import QuantumFloat, invert >>> qf = QuantumFloat(5) >>> qf[:] = 13 >>> QFT(qf, use_gms = True) >>> print(qf.qs)
QuantumCircuit: -------------- โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ ยป qf.0: โค X โโค H โโค0 โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโยป โโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ ยป qf.1: โโโโโโโโโโโค1 โโค H โโค0 โโโโโโยป โโโโโ โ โโโโโโโ โโโโโโยป qf.2: โค X โโโโโโโค2 GXX converted gate โโโโโโโค1 โโค H โยป โโโโโค โ โ โ GXX converted gate โโโโโโยป qf.3: โค X โโโโโโโค3 โโโโโโโค2 โโโโโโยป โโโโโ โ โ โ โ ยป qf.4: โโโโโโโโโโโค4 โโโโโโโค3 โโโโโโยป โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ ยป ยซ ยซqf.0: โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโXโ ยซ โ ยซqf.1: โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโXโโโโผโ ยซ โโโโโโโโโโโโโโโโโโโโโโโ โ โ ยซqf.2: โค0 โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโผโ ยซ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ ยซqf.3: โค1 GXX converted gate โโค H โโค0 โโโXโโโโผโ ยซ โ โโโโโโโ GXX converted gate โโโโโโ โ ยซqf.4: โค2 โโโโโโโค1 โโค H โโXโ ยซ โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ Live QuantumVariables: --------------------- QuantumFloat qfNow we check that the GMS version indeed performs the same operation as the CNOT version by performing the inverse of the CNOT version.
>>> with invert(): QFT(qf, use_gms = False) >>> print(qf) {13: 1.0}