নোট
এই পৃষ্ঠাটি tutorials/simulators/4_custom_gate_noise.ipynb -থেকে বানানো হয়েছে।
বিশেষায়িত (কাস্টম) ঐকিক (ইউনিটারি) যুক্তিবর্তনীতে (গেইট) ত্রুটি ব্যবহার করা¶
ভূমিকা¶
এই নোটবুকে দেখানো হয়েছে কিভাবে একটা কোয়ান্টাম বর্তনীতে বিশেষায়িত (কাস্টম) ঐকিক (ইউনিটারি) যুক্তিবর্তনী (গেইট) যোগ করতে হয় এবং Qiskit এয়ারের ত্রুটি সিমুলেশনে ব্যবহার করতে হয়।
[1]:
from qiskit import transpile, QuantumCircuit
import qiskit.quantum_info as qi
from qiskit_aer import AerSimulator
from qiskit_aer.noise import NoiseModel, amplitude_damping_error
from qiskit.tools.visualization import plot_histogram
ম্যাট্রিক্স অপারেটর বানানো¶
আমরা qiskit.quantum_info
-এর Operator
ক্লাস ব্যবহার করে ইচ্ছামতো ম্যাট্রিক্স অপারেটর বানাতে পারি। অপারেটরটি ঐকিক (ইউনিটারি) হলে সেটাকে কোয়ান্টাম বর্তনীতে (সার্কিট) যোগ করে Qiskit এয়ারে সিমুলেশনের কাজে ব্যবহার করা যায়।
CNOT ও iSWAP যুক্তিবর্তনীর (গেইট) জন্য দুটো অপারেটর বানানো যাক:
[2]:
# CNOT matrix operator with qubit-0 as control and qubit-1 as target
cx_op = qi.Operator([[1, 0, 0, 0],
[0, 0, 0, 1],
[0, 0, 1, 0],
[0, 1, 0, 0]])
# iSWAP matrix operator
iswap_op = qi.Operator([[1, 0, 0, 0],
[0, 0, 1j, 0],
[0, 1j, 0, 0],
[0, 0, 0, 1]])
বিঃ দ্রঃ [a, b]
তালিকার কিউবিটের ক্ষেত্রে ম্যাট্রিক্স টা হবে একটা টেনসর গুনফল \(U_{b}\o * U_{a}\)
বর্তনীতে (সার্কিট) অপারেটরের ব্যবহার¶
বর্তনীতে (সার্কিট) কিভাবে এটা ব্যবহার করতে হয় তা দেখা যাক। উদাহরণরূপে আমরা একটা CNOT যুক্তিবর্তনীকে (গেইট) এবং একটা iSWAP যুক্তিবর্তনীকে (গেইট) একক কিউবিট যুক্তিবর্তনীতে (গেইট) ভাঙলাম।
[3]:
# CNOT in terms of iSWAP and single-qubit gates
cx_circ = QuantumCircuit(2, name='cx<iSWAP>')
# Add gates
cx_circ.sdg(1)
cx_circ.h(1)
cx_circ.sdg(0)
cx_circ.unitary(iswap_op, [0, 1], label='iswap')
cx_circ.sdg(0)
cx_circ.h(0)
cx_circ.sdg(0)
cx_circ.unitary(iswap_op, [0, 1], label='iswap')
cx_circ.s(1)
print(cx_circ)
┌─────┐ ┌────────┐┌─────┐┌───┐┌─────┐┌────────┐
q_0: ┤ SDG ├─────┤0 ├┤ SDG ├┤ H ├┤ SDG ├┤0 ├─────
├─────┤┌───┐│ iswap │└─────┘└───┘└─────┘│ iswap │┌───┐
q_1: ┤ SDG ├┤ H ├┤1 ├───────────────────┤1 ├┤ S ├
└─────┘└───┘└────────┘ └────────┘└───┘
মনে রাখতে হবে আমরা ঐকিকে "iswap"
যোগ করার সময় একটা ঐচ্ছিক নাম (লেবেল) দিয়েছিলাম। এতে Qiskit এয়ারের NoiseModel
এর মধ্যে এই ঐকিকটাকে চিহ্নিত করতে সাহায্য করবে যাতে আমরা ত্রুটিপূর্ণ বর্তনী (সার্কিট) সিমুলেশনের এই বিশেষায়িত (কাস্টম) ঐকিক (ইউনিটারি) যুক্তিবর্তনীতে (গেইট) ত্রুটি যোগ করতে পারি।
এই বর্তনী (সার্কিট) যে সঠিক ফলাফল দিচ্ছে তা যাচাইয়ের জন্য আমরা Operator
ক্লাসটাকে বর্তনীর (সার্কিট) জন্য সিমুলেটররূপে ব্যবহার করতে পারি:
[4]:
# Simulate the unitary for the circuit using Operator:
unitary = qi.Operator(cx_circ)
print(unitary)
Operator([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
[0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j],
[0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],
[0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j]],
input_dims=(2, 2), output_dims=(2, 2))
ফলাফল যাচাইয়ের জন্য আমরা যুক্তিবর্তনী (গেইট) বিশ্বস্ততার গড় গণনা করতে পারি:
[5]:
f_ave = qi.average_gate_fidelity(cx_op, unitary)
print("Average Gate Fidelity: F = {:f}".format(f_ave))
Average Gate Fidelity: F = 1.000000
একটা ত্রুটি নকশায় বিশেষায়িত (কাস্টম) ঐকিক (ইউনিটারি) বানানো¶
কিস্কিট (Qiskit) এয়ারের AerSimulator
-এ বেসিস যুক্তিবর্তনীর (গেইট) "unitary"
দ্বারা নির্দেশিত সকল ঐকিক (ইউনিটারি) অপারেটর ইচ্ছামতো সিমুলেট করা যায়।
[6]:
'unitary' in AerSimulator().configuration().basis_gates
[6]:
True
এর দ্বারা আমাদের সিমুলেশনের বিভিন্ন ঐকিককে QuantumCircuit.unitary
এর label
আর্গুমেন্ট(ঐচ্ছিক) দিয়ে চিহ্নিত করে তাতে ত্রুটি নকশা যোগ করতে পারি।
এটা করার জন্য আমরা একটা NoiseModel
বানাবো যাতে আমাদের বিশেষায়িত (কাস্টম) iSWAP যুক্তিবর্তনীর (গেইট) উপর একটা কোয়ান্টাম ত্রুটি চ্যানেল থাকবে। আমাদের উদাহরণের জন্য আমরা একটা ২-কিউবিট ত্রুটি বানাবো যার মধ্যে দুটো আলাদা অবনমন (ড্যাম্পিং) প্যারামিটারসম্পন্ন এক-কিউবিট বিস্তার অবনমন (ড্যাম্পিং) চ্যানেল থাকবে। এখনকার মতো আমরা ধরে নেবো বর্তনীর বাকি সব নির্দেশনা আদর্শ।
[7]:
# Error parameters
param_q0 = 0.05 # damping parameter for qubit-0
param_q1 = 0.1 # damping parameter for qubit-1
# Construct the error
qerror_q0 = amplitude_damping_error(param_q0)
qerror_q1 = amplitude_damping_error(param_q1)
iswap_error = qerror_q1.tensor(qerror_q0)
# Build the noise model by adding the error to the "iswap" gate
noise_model = NoiseModel()
noise_model.add_all_qubit_quantum_error(iswap_error, 'iswap')
লক্ষ্য করো যখন আমরা একটা ত্রুটি একটা বিশেষায়িত (কাস্টম) নাম (লেবেল) এ যোগ করি (যেমন "iswap"
), NoiseModel
জানে না কোন যুক্তিবর্তনীতে (গেইট) এই নামটা (লেবেল) যোগ হবে, সেজন্য আমাদের আলাদা করে basis_gates
-এর মাধ্যমে যুক্তিবর্তনীর (গেইট) নামটা ত্রুটি নকশায় দিতে হবে। এতে নিশ্চিত হওয়া যায় যে কম্পাইলার সঠিক বেসিস যুক্তিবর্তনীকেই ত্রুটি নকশা সিমুলেশনের জন্য আনরোল করবে। এটা করতে হলে NoiseModel.add_basis_gates
ফাংশন ব্যবহার করতে হবে:
[8]:
noise_model.add_basis_gates(['unitary'])
print(noise_model.basis_gates)
['cx', 'id', 'u3', 'unitary']
স্বতঃসিদ্ধ নিয়মানুসারে দূষণ বা ত্রুটি মডেলের বেসিস বা ভিত্তি যুক্তিবর্তনীগুলি (গেইট) হলো ['cx','id','u3']
এবং যেকোনো সাধারণ AerSimulator
বেসিস বা ভিত্তি যুক্তিবর্তনীগুলি (গেইট) যা দূষণ বা ত্রুটি মডেলের সাথে যোগ করা হয়েছে।
একটা বিশেষায়িত (কাস্টম) ঐকিক (ইউনিটারি) ত্রুটি নকশা সিমুলেট করা¶
প্রথমে আমরা আগের CX বর্তনী (সার্কিট) নিই এবং একটা প্রাথমিক হ্যাডামার্ড যুক্তিবর্তনী ও চূড়ান্ত পরিমাপ যোগ করি। এতে একটা বর্তনী (সার্কিট) তৈরী হবে যেটা একটা বেল স্টেট বানাবে। এটাকে আমরা AerSimulator
-এ আদর্শ ও ত্রুটিপূর্ণ (নয়েজী) উভয়ক্ষেত্রের জন্য সিমুলেট করবো।
[9]:
# Bell state circuit where iSWAPS should be inserted at barrier locations
bell_circ = QuantumCircuit(2, 2, name='bell')
bell_circ.h(0)
bell_circ.append(cx_circ, [0, 1])
bell_circ.measure([0,1], [0,1])
print(bell_circ)
┌───┐┌────────────┐┌─┐
q_0: ┤ H ├┤0 ├┤M├───
└───┘│ cx<iSWAP> │└╥┘┌─┐
q_1: ─────┤1 ├─╫─┤M├
└────────────┘ ║ └╥┘
c: 2/════════════════════╩══╩═
0 1
আদর্শ ফলাফল¶
Let’s first see the ideal output. Since this generates a Bell-state we expect two peaks for 00 and 11.
[10]:
# Create ideal simulator backend and transpile circuit
sim_ideal = AerSimulator()
tbell_circ = transpile(bell_circ, sim_ideal)
ideal_result = sim_ideal.run(tbell_circ).result()
ideal_counts = ideal_result.get_counts(0)
plot_histogram(ideal_counts,
title='Ideal output for iSWAP bell-state preparation')
[10]:

ত্রুটিপূর্ণ বর্তনী চালানো¶
Finally, let’s now simulate it with our custom noise model. Since there is a small amplitude damping error on the two-qubit gates we expect small additional peaks for the 01 and 10 outcome probabilities.
[11]:
# Create noisy simulator and transpile circuit
sim_noise = AerSimulator(noise_model=noise_model)
tbell_circ_noise = transpile(bell_circ, sim_noise)
# Run on the simulator without noise
noise_result = sim_noise.run(tbell_circ_noise).result()
noise_counts = noise_result.get_counts(bell_circ)
plot_histogram(noise_counts,
title='Noisy output for iSWAP bell-state preparation')
[11]:

[12]:
import qiskit.tools.jupyter
%qiskit_version_table
%qiskit_copyright
Version Information
Qiskit Software | Version |
---|---|
Qiskit | 0.25.0 |
Terra | 0.17.0 |
Aer | 0.8.0 |
Ignis | 0.6.0 |
Aqua | 0.9.0 |
IBM Q Provider | 0.12.2 |
System information | |
Python | 3.7.7 (default, May 6 2020, 04:59:01) [Clang 4.0.1 (tags/RELEASE_401/final)] |
OS | Darwin |
CPUs | 6 |
Memory (Gb) | 32.0 |
Fri Apr 02 12:12:41 2021 EDT |
This code is a part of Qiskit
© Copyright IBM 2017, 2021.
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.
[ ]: