Tamil
மொழிகள்
English
Bengali
French
German
Japanese
Korean
Portuguese
Spanish
Tamil

Note

இந்தப் பக்கம் tutorials/circuits_advanced/03_advanced_circuit_visualization.ipynb இருந்து உருவாக்கப்பட்டது.

ஒரு குவாண்டம் சுற்று காட்சிப்படுத்துதல்

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

ஒரு குவாண்டம் சுற்று வரைதல்

ஒரு quantum circuit கட்டும் போது, ​​இது பெரும்பாலும் சுற்று வரைய உதவுகிறது. இது quantum circuit பொருளால் சொந்தமாக ஆதரிக்கப்படுகிறது. நீங்கள் சுற்றுக்கு 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).

வெளியீட்டைத் தனிப்பயனாக்குதல்

வெளியீட்டைப் பொறுத்து, சுற்று வழங்கிய சுற்று வரைபடத்தைத் தனிப்பயனாக்க விருப்பங்களும் உள்ளன.

Plot Barriers மற்றும் தலைகீழ் பிட் வரிசையை முடக்கு

முதல் இரண்டு விருப்பங்கள் மூன்று பின்தளத்தில் பகிரப்படுகின்றன. பிட் ஆர்டர்கள் மற்றும் நீங்கள் தடைகளை வரையலாமா இல்லையா என்பதை கட்டமைக்க அவை உங்களை அனுமதிக்கின்றன. இவற்றை முறையே 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 குவார்க் வெளியீட்டிற்கு அதிகபட்ச அகலத்தை அமைக்கப் பயன்படுத்தலாம். ஒரு வரைபடம் அதிகபட்சத்தை விட அகலமாக இருக்கும்போது, ​​அது கீழே உள்ள வரைபடத்தை மடிக்கும். mpl பின்தளத்தில் style குவார்க் உள்ளது, இது வெளியீட்டைத் தனிப்பயனாக்கப் பயன்படுகிறது. scale விருப்பம், mpl மற்றும் latex பின்தளத்தில் வெளியீட்டுப் படத்தின் அளவை பெருக்க சரிசெய்தல் காரணியுடன் அளவிட பயன்படுகிறது. style குவார்க் பல விருப்பங்களுடன் dict ஐ எடுத்துக்கொள்கிறது, வண்ணங்களை மாற்றுவதற்கான உயர் மட்ட நெகிழ்வுத்தன்மையை வழங்குகிறது, வெவ்வேறு வகையான வாயில்கள், வெவ்வேறு வரி பாணிகள் போன்றவற்றுக்கு வழங்கப்பட்ட உரையை மாற்றுகிறது. கிடைக்கக்கூடிய விருப்பங்கள்:

  • textcolor (str): உரைக்கு பயன்படுத்த வேண்டிய வண்ண குறியீடு. இயல்புநிலை '#000000'

  • subtextcolor (str): துணை உரைக்கு பயன்படுத்த வேண்டிய வண்ண குறியீடு. இயல்புநிலை '# 000000'

  • linecolor (str): வரிகளுக்கு பயன்படுத்த வேண்டிய வண்ண குறியீடு. இயல்புநிலை '# 000000'

  • creglinecolor (str): கிளாசிக்கல் பதிவு வரிகளுக்கு பயன்படுத்த வண்ண குறியீடு '# 778899'

  • gatetextcolor (str): கேட் உரைக்கு பயன்படுத்த வேண்டிய வண்ண குறியீடு '#000000'

  • gatefacecolor (str): வாயில்களுக்கு பயன்படுத்த வேண்டிய வண்ண குறியீடு. இயல்புநிலை '#ffffff'

  • barrierfacecolor (str): தடைகளுக்கு பயன்படுத்த வண்ண குறியீடு. இயல்புநிலை '#bdbdbd'

  • backgroundcolor (str): பின்னணிக்கு பயன்படுத்த வேண்டிய வண்ண குறியீடு. இயல்புநிலை '#ffffff'

  • fontsize (int): உரைக்கு பயன்படுத்த வேண்டிய எழுத்துரு அளவு. அதன் இயல்புநிலை 13

  • subfontsize (int): துணை உரைக்கு பயன்படுத்த வேண்டிய எழுத்துரு அளவு. அதன் இயல்புநிலை 8

  • 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 போலவே, முழுமையடையாத ஆணையை நிறைவேற்றுவதற்கான ஏற்பாடுகளும் இல்லை.

  • latexdrawerstyle (bool): உண்மை என அமைக்கப்பட்டால், லாடெக்ஸ் பயன்முறையை இயக்கவும், இது latex வெளியீட்டு முறைகள் போன்ற வாயில்களை வரையும்.

  • usepiformat (bool): உண்மை என அமைக்கப்பட்டால், வெளியீட்டிற்கு ரேடியன்களைப் பயன்படுத்தவும்.

  • fold (int): சுற்று மடிக்க வேண்டிய சுற்று கூறுகளின் எண்ணிக்கை. அதன் இயல்புநிலை 20

  • cregbundle (bool): உண்மை என அமைத்தால், கிளாசிக்கல் பதிவுகளை மூட்டை.

  • showindex (bool): உண்மை என அமைத்தால், ஒரு குறியீட்டை வரையவும்.

  • compress (bool): உண்மை என அமைத்தால், சுருக்கப்பட்ட சுற்று வரையவும்.

  • figwidth (int): வெளியீட்டு உருவத்திற்கான அதிகபட்ச அகலம் (அங்குலங்களில்).

  • dpi (int): வெளியீட்டு படத்திற்கு பயன்படுத்த DPI. இயல்புநிலை 150 ஆக உள்ளது.

  • creglinestyle (str): கிளாசிக்கல் பதிவேடுகளுக்கு பயன்படுத்த வேண்டிய வரியின் பாணி. தேர்வுகள் 'solid', 'doublet', அல்லது எந்தவொரு செல்லுபடியாகும் matplotlib linestyle kwarg மதிப்பு. இயல்புநிலை 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 () செயல்பாடாக

ஒரு சுற்று பொருளின் முறையாக இல்லாமல் ஒரு தன்னிறைவான செயல்பாட்டைக் கொண்டு ஒரு சுற்று வரைய விரும்பினால், நீங்கள் நேரடியாக circuit_drawer() செயல்பாட்டைப் பயன்படுத்தலாம், இது பொது நிலையான இடைமுகத்தின் ஒரு பகுதியாகும் qiskit.tools.visualization இலிருந்து. செயல்பாடு circuit.draw() முறைக்கு ஒத்ததாக செயல்படுகிறது, தவிர அது ஒரு சுற்று பொருளில் தேவையான வாதமாக எடுக்கும்.

Note: Qiskit Terra <= 0.7 இல், circuit_drawer() செயல்பாட்டின் இயல்புநிலை நடத்தை லேடெக்ஸ் வெளியீட்டு பின்தளத்தில் பயன்படுத்துவதும், மற்றும் 0.6.x இல் எந்த காரணத்திற்காகவும் latex தோல்வியுற்றால் mpl. வெளியீடு> 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.

[ ]: