French
Languages
English
Bengali
French
German
Japanese
Korean
Portuguese
Spanish
Tamil

Note

Cette page a été générée à partir de tutorials/circuits_advanced/05_pulse_gates.ipynb.

Portes d’impulsions

La plupart des algorithmes quantiques peuvent être décrits sous forme de circuits contenant des opérations. Lorsque nous avons besoin d’un contrôle de bas niveau très précis nous pouvons utiliser les portes d’impulsion. Les portes d’impulsions enlèvent les contraintes liées à l’execution de circuits utilisant les portes de base uniquement, et permettent aussi de reprogrammer les portes de bases.

Les portes d’impulsions vous permettent de faire correspondre une porte quantique (par exemple, X) à un programme Qiskit Pulse, appelé Schedule. Cette correspondance est appelée une calibration. Une calibration de haute fidélité est une calibration qui implémente fidèlement l’opération voulue (par exemple, la fidélité avec laquelle une porte X fait passer l’état de \(|0\rangle\) à \(|1\rangle\), etc.).

Un schedule (planning) spécifie la dynamique temporelle exacte des signaux d’entrée sur tous les canaux channels allant vers le système. Il existe généralement plusieurs canaux par qubit, tels que le canal d’entrée et le canal de mesure. Cette interface est plus puissante et nécessite une compréhension plus approfondie de la physique des dispositifs sous-jacents.

It’s important to note that Pulse programs operate on physical qubits. A drive pulse on qubit \(a\) will not enact the same logical operation on the state of qubit \(b\) – in other words, gate calibrations are not interchangeable across qubits. This is in contrast to the circuit level, where an X gate is defined independent of its qubit operand.

Cette page vous montre comment ajouter une calibration à votre circuit.

Note: Not all providers support pulse gates.

Construire votre circuit

Let’s start with a very simple example, a Bell state circuit.

[1]:
from qiskit import QuantumCircuit

circ = QuantumCircuit(2, 2)
circ.h(0)
circ.cx(0, 1)
circ.measure(0, 0)
circ.measure(1, 1)

circ.draw('mpl')
[1]:
../../_images/tutorials_circuits_advanced_05_pulse_gates_2_0.png

Construire vos calibrations

Now that we have our circuit, let’s define a calibration for the Hadamard gate on qubit 0.

Dans la pratique, la forme de l’impulsion et ses paramètres devraient être optimisés à travers une série d’expériences de Rabi (voir le Qiskit Textbook pour une preemière approche). Pour cette démonstration, notre Hadamard sera une impulsion gaussienne. Nous allons jouer notre impulsion sur le canal d’entrée du qubit 0.

Don’t worry too much about the details of building the calibration itself; you can learn all about this on the following page: building pulse schedules.

[2]:
from qiskit import pulse
from qiskit.pulse.library import Gaussian
from qiskit.providers.fake_provider import FakeValencia

backend = FakeValencia()

with pulse.build(backend, name='hadamard') as h_q0:
    pulse.play(Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(0))

Let’s draw the new schedule to see what we’ve built.

[3]:
h_q0.draw()
[3]:
../../_images/tutorials_circuits_advanced_05_pulse_gates_6_0.png

Connectez votre calibration à votre circuit

Il ne reste plus qu’à compléter l’enregistrement. La méthode de circuit add_calibration a besoin d’informations sur la porte et d’une référence à la planification pour terminer la correspondance:

QuantumCircuit.add_calibration(gate, qubits, schedule, parameters)

The gate can either be a circuit.Gate object or the name of the gate. Usually, you’ll need a different schedule for each unique set of qubits and parameters. Since the Hadamard gate doesn’t have any parameters, we don’t have to supply any.

[4]:
circ.add_calibration('h', [0], h_q0)

Enfin, notez que le transpilleur respectera vos calibrations. Utilisez-le comme vous le feriez normalement (ici, notre exemple est trop simple pour que le transpilleur puisse optimiser, donc la sortie est la même).

[5]:
from qiskit import transpile
from qiskit.providers.fake_provider import FakeHanoi

backend = FakeHanoi()

circ = transpile(circ, backend)

print(backend.configuration().basis_gates)
circ.draw('mpl', idle_wires=False)
['id', 'rz', 'sx', 'x', 'cx', 'reset']
[5]:
../../_images/tutorials_circuits_advanced_05_pulse_gates_10_1.png

Notez que h n’est pas une porte de base pour le backend simulé FakeHanoï. Puisque nous avons ajouté une calibration pour elle, le transpilleur traitera notre porte comme une porte de base; mais seulement sur les qubits pour lesquels elle a été définie. Une porte de Hadamard appliquée à un autre qubit aurait été transformée en une suite de portes de base.

That’s it!

Portes personnalisées

We’ll briefly show the same process for nonstandard, completely custom gates. This demonstration includes a gate with parameters.

[6]:
from qiskit import QuantumCircuit
from qiskit.circuit import Gate

circ = QuantumCircuit(1, 1)
custom_gate = Gate('my_custom_gate', 1, [3.14, 1])
# 3.14 is an arbitrary parameter for demonstration
circ.append(custom_gate, [0])
circ.measure(0, 0)

circ.draw('mpl')
[6]:
../../_images/tutorials_circuits_advanced_05_pulse_gates_12_0.png
[7]:
with pulse.build(backend, name='custom') as my_schedule:
    pulse.play(Gaussian(duration=64, amp=0.2, sigma=8), pulse.drive_channel(0))

circ.add_calibration('my_custom_gate', [0], my_schedule, [3.14, 1])
# Alternatively: circ.add_calibration(custom_gate, [0], my_schedule)

Si nous utilisons la variable custom_gate de l’instance Gate pour ajouter l’étalonnage, les paramètres sont dérivés de cette instance. N’oubliez pas que l’ordre des paramètres est significatif.

[8]:
circ = transpile(circ, backend)
circ.draw('mpl', idle_wires=False)
[8]:
../../_images/tutorials_circuits_advanced_05_pulse_gates_15_0.png

Normally, if we tried to transpile our circ, we would get an error. There was no functional definition provided for "my_custom_gate", so the transpiler can’t unroll it to the basis gate set of the target device. We can show this by trying to add "my_custom_gate" to another qubit which hasn’t been calibrated.

[9]:
circ = QuantumCircuit(2, 2)
circ.append(custom_gate, [1])


from qiskit import QiskitError
try:
    circ = transpile(circ, backend)
except QiskitError as e:
    print(e)
"Cannot unroll the circuit to the given basis, ['id', 'rz', 'sx', 'x', 'cx', 'reset']. Instruction my_custom_gate not found in equivalence library and no rule found to expand."
[10]:
import qiskit.tools.jupyter
%qiskit_version_table
%qiskit_copyright

Version Information

Qiskit SoftwareVersion
qiskit-terra0.21.2
qiskit-aer0.10.4
qiskit-ibmq-provider0.19.2
qiskit0.37.2
System information
Python version3.10.7
Python compilerGCC 12.2.0
Python buildmain, Sep 6 2022 21:22:27
OSLinux
CPUs32
Memory (Gb)125.64828109741211
Mon Sep 12 15:28:25 2022 EDT

This code is a part of Qiskit

© Copyright IBM 2017, 2022.

This code is licensed under the Apache License, Version 2.0. You may
obtain a copy of this license in the LICENSE.txt file in the root directory
of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.

Any modifications or derivative works of this code must retain this
copyright notice, and modified files need to carry a notice indicating
that they have been altered from the originals.