Bengali
Languages
English
Bengali
French
German
Japanese
Korean
Portuguese
Spanish
Tamil

নোট

এই পৃষ্ঠাটি tutorials/circuits_advanced/1_advanced_circuits.ipynb থেকে উৎপন্ন হয়েছে।

কোয়ান্টাম বর্তনী দৃষ্টিগোচর করা

[1]:
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister

কোয়ান্টাম সার্কিট সিমুলেট করা

কোয়ান্টাম বর্তনী (সার্কিট) তৈরি করার সময় এটি প্রায়শই সার্কিট আঁকতে সহায়তা করে। এটি স্থানীয়ভাবে একটি QuantumCircuit বস্তু দ্বারা সমর্থিত। আপনি হয় সার্কিটের print() কল করতে পারেন, বা অবজেক্টের উপর draw() পদ্ধতি কল করতে পারেন। এটি বর্তনীর একটি ASCII art version যেটি দৃশ্যায়নটিকে বানায়।

[2]:
# Build a quantum circuit
circuit = QuantumCircuit(3, 3)

circuit.x(1)
circuit.h(range(3))
circuit.cx(0, 1)
circuit.measure(range(3), range(3));
[3]:
print(circuit)
     ┌───┐          ┌─┐
q_0: ┤ H ├───────■──┤M├───
     ├───┤┌───┐┌─┴─┐└╥┘┌─┐
q_1: ┤ X ├┤ H ├┤ X ├─╫─┤M├
     ├───┤└┬─┬┘└───┘ ║ └╥┘
q_2: ┤ H ├─┤M├───────╫──╫─
     └───┘ └╥┘       ║  ║
c_0: ═══════╬════════╩══╬═
            ║           ║
c_1: ═══════╬═══════════╩═
            ║
c_2: ═══════╩═════════════

[4]:
circuit.draw()
[4]:
     ┌───┐          ┌─┐
q_0: ┤ H ├───────■──┤M├───
     ├───┤┌───┐┌─┴─┐└╥┘┌─┐
q_1: ┤ X ├┤ H ├┤ X ├─╫─┤M├
     ├───┤└┬─┬┘└───┘ ║ └╥┘
q_2: ┤ H ├─┤M├───────╫──╫─
     └───┘ └╥┘       ║  ║
c_0: ═══════╬════════╩══╬═
            ║           ║
c_1: ═══════╬═══════════╩═
            ║
c_2: ═══════╩═════════════
                          

বর্তনীর জন্য বিকল্প দৃশ্যায়ন

A text output is useful for quickly seeing the output while developing a circuit, but it doesn’t provide the most flexibility in its output. There are two alternative output renderers for the quantum circuit. One uses matplotlib, and the other uses LaTeX, which leverages the qcircuit package. These can be specified by using mpl and latex values for the output kwarg on the draw() method.

[5]:
# Matplotlib Drawing
circuit.draw(output='mpl')
[5]:
../../_images/tutorials_circuits_advanced_03_advanced_circuit_visualization_7_0.png

Circuit.draw() থেকে ফলাফল নিয়ন্ত্রণ

By default, the draw() method returns the rendered image as an object and does not output anything. The exact class returned depends on the output specified: 'text' (the default) returns a TextDrawer object, 'mpl' returns a matplotlib.Figure object, and latex returns a PIL.Image object. Having the return types enables modifying or directly interacting with the rendered output from the drawers. Jupyter notebooks understand these return types and render them for us in this tutorial, but when running outside of Jupyter, you do not have this feature automatically. However, the draw() method has optional arguments to display or save the output. When specified, the filename kwarg takes a path to which it saves the rendered output. Alternatively, if you’re using the mpl or latex outputs, you can leverage the interactive kwarg to open the image in a new window (this will not always work from within a notebook but will be demonstrated anyway).

ফলাফলটি স্বনির্ধারন করা হচ্ছে

ফলাফলের উপর নির্ভর করে, সার্কিট দ্বারা অনুষ্ঠিত সার্কিটর (বর্তনীর) চিত্রটি স্বনির্ধারন করার বিকল্পও রয়েছে।

প্লটের (লেখচিত্রের) অন্তরায় এবং বিট অর্ডারের পশ্চাদ্দিকে ফিরানো থেকে অক্ষম করুন

প্রথম দুটি বিকল্পকে তিনটি ব্যাকেন্ডের মধ্যে ভাগ করা হয়েছে। তারা আপনাকে বিট অর্ডার এবং বেষ্টনীগুলি আঁকা কিনা তা সাজাতে দেয় । reverse_bits কীওয়ার্ড আর্গুমেন্ট এবং plot_barriers কীওয়ার্ড আর্গুমেন্ট দ্বারা এগুলি নিশ্চিত করা যায়। নীচের উদাহরণগুলি যে কোনও আউটপুট ব্যাকএন্ডে কাজ করবে। এখানে সংক্ষিপ্ত করার জন্য mpl ব্যবহৃত হয়েছে।

[8]:
# Draw a new circuit with barriers and more registers

q_a = QuantumRegister(3, name='qa')
q_b = QuantumRegister(5, name='qb')
c_a = ClassicalRegister(3)
c_b = ClassicalRegister(5)

circuit = QuantumCircuit(q_a, q_b, c_a, c_b)

circuit.x(q_a[1])
circuit.x(q_b[1])
circuit.x(q_b[2])
circuit.x(q_b[4])
circuit.barrier()
circuit.h(q_a)
circuit.barrier(q_a)
circuit.h(q_b)
circuit.cswap(q_b[0], q_b[1], q_b[2])
circuit.cswap(q_b[2], q_b[3], q_b[4])
circuit.cswap(q_b[3], q_b[4], q_b[0])
circuit.barrier(q_b)
circuit.measure(q_a, c_a)
circuit.measure(q_b, c_b);
[9]:
# Draw the circuit
circuit.draw(output='mpl')
[9]:
../../_images/tutorials_circuits_advanced_03_advanced_circuit_visualization_11_0.png
[10]:
# Draw the circuit with reversed bit order
circuit.draw(output='mpl', reverse_bits=True)
[10]:
../../_images/tutorials_circuits_advanced_03_advanced_circuit_visualization_12_0.png
[11]:
# Draw the circuit without barriers
circuit.draw(output='mpl', plot_barriers=False)
[11]:
../../_images/tutorials_circuits_advanced_03_advanced_circuit_visualization_13_0.png
[12]:
# Draw the circuit without barriers and reverse bit order
circuit.draw(output='mpl', plot_barriers=False, reverse_bits=True)
[12]:
../../_images/tutorials_circuits_advanced_03_advanced_circuit_visualization_14_0.png

ব্যাকএন্ড-নির্দিষ্ট স্বনির্ধারন

কিছু উপলব্ধ কাস্টমাইজিং বিকল্প কিছু ব্যাকএন্ডের জন্য নির্দিষ্ট। আউটপুটটির সর্বাধিক প্রস্থ নির্ধারণ করতে text ব্যাকএন্ডের জন্য line_length কীওয়ার্ড আর্গুমেন্ট ব্যবহার করা যেতে পারে। যখন চিত্রটি সর্বাধিকের চেয়ে প্রশস্ত হবে, এটি নীচের চিত্রটি wrap করে নেবে । mpl ব্যাকএন্ডে style কীওয়ার্ড আর্গুমেন্ট রয়েছে, যা আউটপুট কাস্টমাইজ করতে ব্যবহৃত হয়। scale বিকল্পটি একটি গুণগত সমন্বয় ফ্যাক্টর সহ আউটপুট চিত্রের আকার স্কেল করতে mpl এবং latex ব্যাকেন্ডগুলি ব্যবহার করে। style কীওয়ার্ড আর্গুমেন্টটি একাধিক বিকল্পের সাথে একটি dict গ্রহণ করে, রঙ পরিবর্তন করার জন্য একটি উচ্চ স্তরের নমনীয়তা সরবরাহ করে, বিভিন্ন ধরণের গেটের জন্য রেন্ডার পাঠ্য পরিবর্তন করে, বিভিন্ন লাইনের শৈলী ইত্যাদি । উপলভ্য বিকল্পগুলি:

  • পাঠ্যের রঙ (str): পাঠ্যের জন্য যে রঙের কোডটি ব্যবহার করা হয়। '#000000' পূর্ণ নির্ধারিত।

  • উপ পাঠ্যের রঙ (str): উপপাঠ্যের জন্য যে রঙের কোডটি ব্যবহার করা হয়। '#000000' পূর্ণ নির্ধারিত।

  • পংক্তির রঙ (str): পংক্তির জন্য যে রঙের কোডটি ব্যবহার করা হয়। '#000000' পূর্ণ নির্ধারিত।

  • ক্রেগ পংক্তির রঙ (str): '#778899' রঙের কোডটি ধ্রুপদী রেজিস্টার পংক্তিগুলির জন্য ব্যবহার করা হয়।

  • গেট পাঠ্যের রঙ (str): '#000000' রঙের কোডটি গেট পাঠ্যের জন্য ব্যবহার করা হয়।

  • গেট মুখের রঙ (str): গেটের জন্য যে রঙের কোডটি ব্যবহার করা হয়। '#ffffff' পূর্ণ নির্ধারিত।

  • অন্তরায় মুখের রঙ (str): অন্তরায়ের জন্য যে রঙের কোডটি ব্যবহার করা হয়। '#bdbdbd' পূর্ণ নির্ধারিত।

  • পটভূমির রঙ (str): পটভূমির জন্য যে রঙের কোডটি ব্যবহার করা হয়। '#ffffff' পূর্ণ নির্ধারিত।

  • অক্ষরের আকার (int): পাঠ্যের জন্য যে অক্ষরের আকারটি ব্যবহার করা হয়। পূর্ণ নির্ধারিত মান হল ১৩।

  • উপঅক্ষরের আকার (int): উপপাঠ্যের জন্য যে অক্ষরের আকারটি ব্যবহার করা হয়। পূর্ণ নির্ধারিত মান হল ৮।

  • displaytext (dict): আউটপুট ভিজুয়ালাইজেশনে প্রত্যেক রকম উপাদান ব্যবহারের জন্য পাঠ্যের একটি ডিকশনারি। ডিফল্ট মানগুলি হ’ল:

    'id': 'id',
    'u0': 'U_0',
    'u1': 'U_1',
    'u2': 'U_2',
    'u3': 'U_3',
    'x': 'X',
    'y': 'Y',
    'z': 'Z',
    'h': 'H',
    's': 'S',
    'sdg': 'S^\\dagger',
    't': 'T',
    'tdg': 'T^\\dagger',
    'rx': 'R_x',
    'ry': 'R_y',
    'rz': 'R_z',
    'reset': '\\left|0\\right\\rangle'
    

    এটি ব্যবহার করা হলে আপনাকে অবশ্যই সমস্ত প্রয়োজনীয় মান নির্দিষ্ট করতে হবে। অসম্পূর্ণ ডিকশনারিটি (অভিধানটি) পাস করার কোনো ব্যবস্থা নেই।

  • displaycolor (dict): প্রতিটি বর্তনী (সার্কিট) উপাদানের জন্য ব্যবহারযোগ্য রঙের কোড। ডিফল্টরূপে, gatefacecolor এর সমস্ত ডিফল্ট মান এবং কী গুলি displaytext এর সমান। এছাড়াও, ঠিক displaytext এর মতো, এখানে অসম্পূর্ণ dict পাসের কোনও ব্যবস্থা নেই।

  • latexdrawerstyle (bool): True সেট করা থাকলে, LaTeX মোড লাগু করুন, যা latex আউটপুট মোডের মতো যুক্তিবর্তনী (গেট) গুলি আঁকবে।

  • usepiformat (bool): সত্য (True) হিসাবে সেট করা হলে, আউটপুট জন্য রেডিয়ান ব্যবহার করুন।

  • fold (int): বর্তনী (সার্কিট) কে ফোল্ড করার জন্য সার্কিট উপাদানের সংখ্যা। ডিফল্ট 20

  • cregbundle (bool): If set True, bundle classical registers.

  • শো ইনডেক্স (বুল): যদি সত্য দিয়ে নিযুক্ত করা থাকে তবে একটি সূচিপত্র আঁকুন।

  • সংকুচিত (কম্প্রেস ) (বুল): যদি সত্য দিয়ে নিযুক্ত করা থাকে তবে একটি সংকুচিত বর্তনী (সার্কিট) আঁকুন ।

  • **ছবির প্রস্থ (ফিগউইড্থ) ** (ইন্ট ): ফলাফলের চিত্রের জন্য সর্বাধিক প্রস্থ (ইঞ্চিতে)।

  • ডিপিআই (ইন্ট): ফলাফল চিত্রের জন্য ব্যবহার করার ডিপিআই। ডিফল্ট -এ ১৫০ ।

  • ** ক্রেগলাইনস্টাইল ** (str): ক্লাসিকাল রেজিস্টার নিবন্ধগুলির জন্য ব্যবহৃত লাইনের শৈলী। পছন্দগুলি হ’ল 'solid', 'doublet', বা কোনও বৈধ matplotlib linestyle কীওয়ার্ড আর্গুমেন্টের মান। ডিফল্ট -এ doublet

[13]:
# Set line length to 80 for above circuit
circuit.draw(output='text')
[13]:
            ░ ┌───┐ ░    ┌─┐
qa_0: ──────░─┤ H ├─░────┤M├───────────────────────────
      ┌───┐ ░ ├───┤ ░    └╥┘┌─┐
qa_1: ┤ X ├─░─┤ H ├─░─────╫─┤M├────────────────────────
      └───┘ ░ ├───┤ ░     ║ └╥┘┌─┐
qa_2: ──────░─┤ H ├─░─────╫──╫─┤M├─────────────────────
            ░ ├───┤ ░     ║  ║ └╥┘    ░ ┌─┐
qb_0: ──────░─┤ H ├─■─────╫──╫──╫──X──░─┤M├────────────
      ┌───┐ ░ ├───┤ │     ║  ║  ║  │  ░ └╥┘┌─┐
qb_1: ┤ X ├─░─┤ H ├─X─────╫──╫──╫──┼──░──╫─┤M├─────────
      ├───┤ ░ ├───┤ │     ║  ║  ║  │  ░  ║ └╥┘┌─┐
qb_2: ┤ X ├─░─┤ H ├─X──■──╫──╫──╫──┼──░──╫──╫─┤M├──────
      └───┘ ░ ├───┤    │  ║  ║  ║  │  ░  ║  ║ └╥┘┌─┐
qb_3: ──────░─┤ H ├────X──╫──╫──╫──■──░──╫──╫──╫─┤M├───
      ┌───┐ ░ ├───┤    │  ║  ║  ║  │  ░  ║  ║  ║ └╥┘┌─┐
qb_4: ┤ X ├─░─┤ H ├────X──╫──╫──╫──X──░──╫──╫──╫──╫─┤M├
      └───┘ ░ └───┘       ║  ║  ║     ░  ║  ║  ║  ║ └╥┘
c0_0: ════════════════════╩══╬══╬════════╬══╬══╬══╬══╬═
                             ║  ║        ║  ║  ║  ║  ║
c0_1: ═══════════════════════╩══╬════════╬══╬══╬══╬══╬═
                                ║        ║  ║  ║  ║  ║
c0_2: ══════════════════════════╩════════╬══╬══╬══╬══╬═
                                         ║  ║  ║  ║  ║
c1_0: ═══════════════════════════════════╩══╬══╬══╬══╬═
                                            ║  ║  ║  ║
c1_1: ══════════════════════════════════════╩══╬══╬══╬═
                                               ║  ║  ║
c1_2: ═════════════════════════════════════════╩══╬══╬═
                                                  ║  ║
c1_3: ════════════════════════════════════════════╩══╬═
                                                     ║
c1_4: ═══════════════════════════════════════════════╩═
                                                       
[14]:
# Change the background color in mpl

style = {'backgroundcolor': 'lightgreen'}

circuit.draw(output='mpl', style=style)
[14]:
../../_images/tutorials_circuits_advanced_03_advanced_circuit_visualization_17_0.png
[15]:
# Scale the mpl output to 1/2 the normal size
circuit.draw(output='mpl', scale=0.5)
[15]:
../../_images/tutorials_circuits_advanced_03_advanced_circuit_visualization_18_0.png

ফাংশন হিসাবে সার্কিট_ড্রয়ার()

আপনার যদি এমন কোনো অ্যাপ্লিকেশন থাকে যেখানে আপনি সার্কিট (বর্তনী) অবজেক্ট পদ্ধতির পরিবর্তে স্বনির্ভর ফাংশন দিয়ে একটি সার্কিট আঁকতে পছন্দ করেন, আপনি সরাসরি circuit_drawer() ফাংশনটি ব্যবহার করতে পারেন, যেটা is qiskit.tools.visualization` এর সর্বসাধারণ স্থিত ইন্টারফেসের অংশ। এই `` ফাংশনটি circuit.draw() পদ্ধতির সাথে অভিন্ন আচরণ করে, ব্যতীত এটি প্রয়োজনীয় আর্গুমেন্ট (যুক্তি) হিসাবে একটি সার্কিট (বর্তনী) অবজেক্ট নেয়।

টীকা: Qiskit টেরা <= 0.7 এ, সার্কিট_ড্রয়ার () ( circuit_drawer()) ফাংশনের জন্য ডিফল্ট আচরণ হ’ল ল্যাটেক্স আউটপুট ব্যাকএন্ড ব্যবহার করা, এবং 0.6.x এ ল্যাটেক্স কোনও কারণে ব্যর্থ হলে mpl একটি fallback অন্তর্ভুক্ত করে। রিলিজ > 0.7 থেকে শুরু করে পাঠ্যের আউটপুটটিতে ডিফল্ট পরিবর্তন হয়।

[17]:
from qiskit.tools.visualization import circuit_drawer
[18]:
circuit_drawer(circuit, output='mpl', plot_barriers=False)
[18]:
../../_images/tutorials_circuits_advanced_03_advanced_circuit_visualization_21_0.png
[19]:
import qiskit.tools.jupyter
%qiskit_version_table
%qiskit_copyright

Version Information

Qiskit SoftwareVersion
QiskitNone
Terra0.15.0
Aer0.5.1
IgnisNone
AquaNone
IBM Q Provider0.7.0
System information
Python3.8.2 (default, Mar 26 2020, 10:43:30) [Clang 4.0.1 (tags/RELEASE_401/final)]
OSDarwin
CPUs4
Memory (Gb)16.0
Fri May 08 08:43:36 2020 EDT

This code is a part of Qiskit

© Copyright IBM 2017, 2020.

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.

[ ]: