

"""simple docstring"""




import colorsys
import io

import cva
import matplotlib as mpl
import matplotlib.colors as mplc
import matplotlib.figure as mplfigure
import numpy as np
import torch
from matplotlib.backends.backend_agg import FigureCanvasAgg

from utils import img_tensorize


SCREAMING_SNAKE_CASE_  :      int							=      1000


class 		_A							:





      def __init__(	self     ,    SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__=1.2     ,    SCREAMING_SNAKE_CASE__="g"     ,    SCREAMING_SNAKE_CASE__=0.5     ,    SCREAMING_SNAKE_CASE__="-"     ,    SCREAMING_SNAKE_CASE__="test_out.jpg"     ,    SCREAMING_SNAKE_CASE__=True     ,    SCREAMING_SNAKE_CASE__=False     ,    SCREAMING_SNAKE_CASE__=None     ,    SCREAMING_SNAKE_CASE__=None     ,    SCREAMING_SNAKE_CASE__=0.7     ,    ) ->       Union[str, Any]:
         if isinstance(SCREAMING_SNAKE_CASE__     ,    torch.Tensor		):
            lowerCamelCase__						       =      img.numpy().astype("np.uint8"		)
         if isinstance(SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__		):
            lowerCamelCase__						       =      img_tensorize(SCREAMING_SNAKE_CASE__		)
         assert isinstance(SCREAMING_SNAKE_CASE__     ,    np.ndarray		)

         lowerCamelCase__       ,							lowerCamelCase__						       =      img.shape[1], img.shape[0]
         lowerCamelCase__						       =      mplfigure.Figure(frameon=SCREAMING_SNAKE_CASE__		)
         lowerCamelCase__						       =      fig.get_dpi()
         lowerCamelCase__						       =      (width * scale + 1e-2) / dpi
         lowerCamelCase__						       =      (height * scale + 1e-2) / dpi
         fig.set_size_inches(SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__		)
         lowerCamelCase__						       =      fig.add_axes([0.0, 0.0, 1.0, 1.0]		)
         ax.axis("off"		)
         ax.set_xlim(0.0     ,    SCREAMING_SNAKE_CASE__		)
         ax.set_ylim(SCREAMING_SNAKE_CASE__		)

         lowerCamelCase__						       =      saveas
         lowerCamelCase__						       =      rgb
         lowerCamelCase__						       =      pynb
         lowerCamelCase__						       =      img
         lowerCamelCase__						       =      edgecolor
         lowerCamelCase__						       =      0.5
         lowerCamelCase__						       =      linestyle
         lowerCamelCase__						       =      int(np.sqrt(min(SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__		)		) * scale // 3		)
         lowerCamelCase__						       =      width
         lowerCamelCase__						       =      height
         lowerCamelCase__						       =      scale
         lowerCamelCase__						       =      fig
         lowerCamelCase__						       =      ax
         lowerCamelCase__						       =      pad
         lowerCamelCase__						       =      idaobj
         lowerCamelCase__						       =      idaattr
         lowerCamelCase__						       =      FigureCanvasAgg(SCREAMING_SNAKE_CASE__		)





      def        _lowerCamelCase	(	self     ,    SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__=None		) ->       Optional[int]:
         if color is None:
            lowerCamelCase__						       =      self.edgecolor
         ((lowerCamelCase__)       ,							(lowerCamelCase__)       ,							(lowerCamelCase__)       ,							(lowerCamelCase__))						       =      box
         lowerCamelCase__						       =      xa - xa
         lowerCamelCase__						       =      ya - ya
         self.ax.add_patch(
             mpl.patches.Rectangle(
                 (xa, ya)     ,    SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__     ,    fill=SCREAMING_SNAKE_CASE__     ,    edgecolor=SCREAMING_SNAKE_CASE__     ,    linewidth=self.font_size // 3     ,    alpha=self.alpha     ,    linestyle=self.linestyle     ,    )		)





      def        _lowerCamelCase	(	self     ,    SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__=None     ,    SCREAMING_SNAKE_CASE__=None     ,    SCREAMING_SNAKE_CASE__=None     ,    SCREAMING_SNAKE_CASE__=None		) ->       Any:
         if len(boxes.shape		) > 2:
            lowerCamelCase__						       =      boxes[0]
         if len(obj_ids.shape		) > 1:
            lowerCamelCase__						       =      obj_ids[0]
         if len(obj_scores.shape		) > 1:
            lowerCamelCase__						       =      obj_scores[0]
         if len(attr_ids.shape		) > 1:
            lowerCamelCase__						       =      attr_ids[0]
         if len(attr_scores.shape		) > 1:
            lowerCamelCase__						       =      attr_scores[0]
         if isinstance(SCREAMING_SNAKE_CASE__     ,    torch.Tensor		):
            lowerCamelCase__						       =      boxes.numpy()
         if isinstance(SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__		):
            lowerCamelCase__						       =      np.array(SCREAMING_SNAKE_CASE__		)
         assert isinstance(SCREAMING_SNAKE_CASE__     ,    np.ndarray		)
         lowerCamelCase__						       =      np.prod(boxes[:, 2:] - boxes[:, :2]     ,    axis=1		)
         lowerCamelCase__						       =      np.argsort(-areas		).tolist()
         lowerCamelCase__						       =      boxes[sorted_idxs] if boxes is not None else None
         lowerCamelCase__						       =      obj_ids[sorted_idxs] if obj_ids is not None else None
         lowerCamelCase__						       =      obj_scores[sorted_idxs] if obj_scores is not None else None
         lowerCamelCase__						       =      attr_ids[sorted_idxs] if attr_ids is not None else None
         lowerCamelCase__						       =      attr_scores[sorted_idxs] if attr_scores is not None else None

         lowerCamelCase__						       =      [self._random_color(maximum=1		) for _ in range(len(SCREAMING_SNAKE_CASE__		)		)]
         lowerCamelCase__						       =      [assigned_colors[idx] for idx in sorted_idxs]
         if obj_ids is not None:
            lowerCamelCase__						       =      self._create_text_labels_attr(SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__		)
            for i in range(len(SCREAMING_SNAKE_CASE__		)		):
               lowerCamelCase__						       =      assigned_colors[i]
               self.add_box(boxes[i]     ,    SCREAMING_SNAKE_CASE__		)
               self.draw_labels(labels[i]     ,    boxes[i]     ,    SCREAMING_SNAKE_CASE__		)





      def        _lowerCamelCase	(	self     ,    SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__		) ->       List[Any]:
         lowerCamelCase__       ,							lowerCamelCase__       ,							lowerCamelCase__       ,							lowerCamelCase__						       =      box
         lowerCamelCase__						       =      (xa, ya)
         lowerCamelCase__						       =      (ya - ya) * (xa - xa)
         lowerCamelCase__						       =      _SMALL_OBJ * self.scale
         if instance_area < small or ya - ya < 40 * self.scale:
            if ya >= self.height - 5:
               lowerCamelCase__						       =      (xa, ya)
            else:
               lowerCamelCase__						       =      (xa, ya)

         lowerCamelCase__						       =      (ya - ya) / np.sqrt(self.height * self.width		)
         lowerCamelCase__						       =      self._change_color_brightness(SCREAMING_SNAKE_CASE__     ,    brightness_factor=0.7		)
         lowerCamelCase__						       =      np.clip((height_ratio - 0.02) / 0.08 + 1     ,    1.2     ,    2		)
         font_size *= 0.75 * self.font_size

         self.draw_text(
             text=SCREAMING_SNAKE_CASE__     ,    position=SCREAMING_SNAKE_CASE__     ,    color=SCREAMING_SNAKE_CASE__     ,    )





      def        _lowerCamelCase	(	self     ,    SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__="g"     ,    SCREAMING_SNAKE_CASE__="left"     ,    ) ->       List[Any]:
         lowerCamelCase__						       =      0
         lowerCamelCase__						       =      self.font_size
         lowerCamelCase__						       =      np.maximum(list(mplc.to_rgb(SCREAMING_SNAKE_CASE__		)		)     ,    0.2		)
         lowerCamelCase__						       =      max(0.8     ,    np.max(SCREAMING_SNAKE_CASE__		)		)
         lowerCamelCase__						       =      {
             "facecolor": "black",
             "alpha": self.alpha,
             "pad": self.pad,
             "edgecolor": "none",
         }
         lowerCamelCase__       ,							lowerCamelCase__						       =      position
         self.ax.text(
             SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__     ,    size=font_size * self.scale     ,    family="sans-serif"     ,    bbox=SCREAMING_SNAKE_CASE__     ,    verticalalignment="top"     ,    horizontalalignment=SCREAMING_SNAKE_CASE__     ,    color=SCREAMING_SNAKE_CASE__     ,    zorder=10     ,    rotation=SCREAMING_SNAKE_CASE__     ,    )





      def        _lowerCamelCase	(	self     ,    SCREAMING_SNAKE_CASE__=None		) ->       Any:
         if saveas is None:
            lowerCamelCase__						       =      self.saveas
         if saveas.lower().endswith(".jpg"		) or saveas.lower().endswith(".png"		):
            cva.imwrite(
                SCREAMING_SNAKE_CASE__     ,    self._get_buffer()[:, :, ::-1]     ,    )
         else:
            self.fig.savefig(SCREAMING_SNAKE_CASE__		)





      def        _lowerCamelCase	(	self     ,    SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__		) ->       int:
         lowerCamelCase__						       =      [self.idaobj[i] for i in classes]
         lowerCamelCase__						       =      [self.idaattr[i] for i in attr_classes]
         lowerCamelCase__						       =      [
             f'{label} {score:.2f} {attr} {attr_score:.2f}'
             for label, score, attr, attr_score in zip(SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__		)
         ]
         return labels





      def        _lowerCamelCase	(	self     ,    SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__		) ->       str:
         lowerCamelCase__						       =      [self.idaobj[i] for i in classes]
         if scores is not None:
            if labels is None:
               lowerCamelCase__						       =      ["{:.0f}%".format(s * 100		) for s in scores]
            else:
               lowerCamelCase__						       =      ["{} {:.0f}%".format(SCREAMING_SNAKE_CASE__     ,    s * 100		) for li, s in zip(SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__		)]
         return labels





      def        _lowerCamelCase	(	self     ,    SCREAMING_SNAKE_CASE__=255		) ->       List[str]:
         lowerCamelCase__						       =      np.random.randint(0     ,    len(_COLORS		)		)
         lowerCamelCase__						       =      _COLORS[idx] * maximum
         if not self.rgb:
            lowerCamelCase__						       =      ret[::-1]
         return ret





      def        _lowerCamelCase	(	self		) ->       List[str]:
         if not self.pynb:
            lowerCamelCase__       ,							lowerCamelCase__						       =      self.canvas.print_to_buffer()
            if (width, height) != (self.width, self.height):
               lowerCamelCase__						       =      cva.resize(self.img     ,    (width, height)		)
            else:
               lowerCamelCase__						       =      self.img
         else:
            lowerCamelCase__						       =      io.BytesIO()  # works for cairo backend
            self.canvas.print_rgba(SCREAMING_SNAKE_CASE__		)
            lowerCamelCase__       ,							lowerCamelCase__						       =      self.width, self.height
            lowerCamelCase__						       =      buf.getvalue()
            lowerCamelCase__						       =      self.img

         lowerCamelCase__						       =      np.frombuffer(SCREAMING_SNAKE_CASE__     ,    dtype="uint8"		)
         lowerCamelCase__						       =      buffer.reshape(SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__     ,    4		)
         lowerCamelCase__       ,							lowerCamelCase__						       =      np.split(SCREAMING_SNAKE_CASE__     ,    [3]     ,    axis=2		)

         try:
            import numexpr as ne  # fuse them with numexpr

            lowerCamelCase__						       =      ne.evaluate("img * (1 - alpha / 255.0) + rgb * (alpha / 255.0)"		)
         except ImportError:
            lowerCamelCase__						       =      alpha.astype("float32"		) / 2_55.0
            lowerCamelCase__						       =      img * (1 - alpha) + rgb * alpha

         return visualized_image.astype("uint8"		)





      def        _lowerCamelCase	(	self     ,    SCREAMING_SNAKE_CASE__     ,    SCREAMING_SNAKE_CASE__		) ->       Optional[int]:
         assert brightness_factor >= -1.0 and brightness_factor <= 1.0
         lowerCamelCase__						       =      mplc.to_rgb(SCREAMING_SNAKE_CASE__		)
         lowerCamelCase__						       =      colorsys.rgb_to_hls(*mplc.to_rgb(SCREAMING_SNAKE_CASE__		)		)
         lowerCamelCase__						       =      polygon_color[1] + (brightness_factor * polygon_color[1])
         lowerCamelCase__						       =      0.0 if modified_lightness < 0.0 else modified_lightness
         lowerCamelCase__						       =      1.0 if modified_lightness > 1.0 else modified_lightness
         lowerCamelCase__						       =      colorsys.hls_to_rgb(polygon_color[0]     ,    SCREAMING_SNAKE_CASE__     ,    polygon_color[2]		)
         return modified_color






SCREAMING_SNAKE_CASE_  :      Optional[int]							=      (
    np.array(
        [
            0.0_0_0,
            0.4_4_7,
            0.7_4_1,
            0.8_5_0,
            0.3_2_5,
            0.0_9_8,
            0.9_2_9,
            0.6_9_4,
            0.1_2_5,
            0.4_9_4,
            0.1_8_4,
            0.5_5_6,
            0.4_6_6,
            0.6_7_4,
            0.1_8_8,
            0.3_0_1,
            0.7_4_5,
            0.9_3_3,
            0.6_3_5,
            0.0_7_8,
            0.1_8_4,
            0.3_0_0,
            0.3_0_0,
            0.3_0_0,
            0.6_0_0,
            0.6_0_0,
            0.6_0_0,
            1.0_0_0,
            0.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.5_0_0,
            0.0_0_0,
            0.7_4_9,
            0.7_4_9,
            0.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.6_6_7,
            0.0_0_0,
            1.0_0_0,
            0.3_3_3,
            0.3_3_3,
            0.0_0_0,
            0.3_3_3,
            0.6_6_7,
            0.0_0_0,
            0.3_3_3,
            1.0_0_0,
            0.0_0_0,
            0.6_6_7,
            0.3_3_3,
            0.0_0_0,
            0.6_6_7,
            0.6_6_7,
            0.0_0_0,
            0.6_6_7,
            1.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.3_3_3,
            0.0_0_0,
            1.0_0_0,
            0.6_6_7,
            0.0_0_0,
            1.0_0_0,
            1.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.3_3_3,
            0.5_0_0,
            0.0_0_0,
            0.6_6_7,
            0.5_0_0,
            0.0_0_0,
            1.0_0_0,
            0.5_0_0,
            0.3_3_3,
            0.0_0_0,
            0.5_0_0,
            0.3_3_3,
            0.3_3_3,
            0.5_0_0,
            0.3_3_3,
            0.6_6_7,
            0.5_0_0,
            0.3_3_3,
            1.0_0_0,
            0.5_0_0,
            0.6_6_7,
            0.0_0_0,
            0.5_0_0,
            0.6_6_7,
            0.3_3_3,
            0.5_0_0,
            0.6_6_7,
            0.6_6_7,
            0.5_0_0,
            0.6_6_7,
            1.0_0_0,
            0.5_0_0,
            1.0_0_0,
            0.0_0_0,
            0.5_0_0,
            1.0_0_0,
            0.3_3_3,
            0.5_0_0,
            1.0_0_0,
            0.6_6_7,
            0.5_0_0,
            1.0_0_0,
            1.0_0_0,
            0.5_0_0,
            0.0_0_0,
            0.3_3_3,
            1.0_0_0,
            0.0_0_0,
            0.6_6_7,
            1.0_0_0,
            0.0_0_0,
            1.0_0_0,
            1.0_0_0,
            0.3_3_3,
            0.0_0_0,
            1.0_0_0,
            0.3_3_3,
            0.3_3_3,
            1.0_0_0,
            0.3_3_3,
            0.6_6_7,
            1.0_0_0,
            0.3_3_3,
            1.0_0_0,
            1.0_0_0,
            0.6_6_7,
            0.0_0_0,
            1.0_0_0,
            0.6_6_7,
            0.3_3_3,
            1.0_0_0,
            0.6_6_7,
            0.6_6_7,
            1.0_0_0,
            0.6_6_7,
            1.0_0_0,
            1.0_0_0,
            1.0_0_0,
            0.0_0_0,
            1.0_0_0,
            1.0_0_0,
            0.3_3_3,
            1.0_0_0,
            1.0_0_0,
            0.6_6_7,
            1.0_0_0,
            0.3_3_3,
            0.0_0_0,
            0.0_0_0,
            0.5_0_0,
            0.0_0_0,
            0.0_0_0,
            0.6_6_7,
            0.0_0_0,
            0.0_0_0,
            0.8_3_3,
            0.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.1_6_7,
            0.0_0_0,
            0.0_0_0,
            0.3_3_3,
            0.0_0_0,
            0.0_0_0,
            0.5_0_0,
            0.0_0_0,
            0.0_0_0,
            0.6_6_7,
            0.0_0_0,
            0.0_0_0,
            0.8_3_3,
            0.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.1_6_7,
            0.0_0_0,
            0.0_0_0,
            0.3_3_3,
            0.0_0_0,
            0.0_0_0,
            0.5_0_0,
            0.0_0_0,
            0.0_0_0,
            0.6_6_7,
            0.0_0_0,
            0.0_0_0,
            0.8_3_3,
            0.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.1_4_3,
            0.1_4_3,
            0.1_4_3,
            0.8_5_7,
            0.8_5_7,
            0.8_5_7,
            1.0_0_0,
            1.0_0_0,
            1.0_0_0,
        ]
    )
    .astype(np.floataa)
    .reshape(-1, 3)
)







"""simple docstring"""




import math

import qiskit
from qiskit import Aer, ClassicalRegister, QuantumCircuit, QuantumRegister, execute



def 						UpperCAmelCase__ (					A__ = 1						,     A__ = 1 )   ->   qiskit.result.counts.Counts:




   """simple docstring"""
   if isinstance(A__						,     A__ ) or isinstance(A__						,     A__ ):
      raise TypeError("inputs must be integers." )
   if (bit_a < 0) or (bit_a < 0):
      raise ValueError("inputs must be positive." )
   if (math.floor(A__ ) != bit_a) or (math.floor(A__ ) != bit_a):
      raise ValueError("inputs must be exact integers." )
   if (bit_a > 1) or (bit_a > 1):
      raise ValueError("inputs must be less or equal to 1." )

   # build registers
   lowerCamelCase__						       =      QuantumRegister(2						,     "qr" )
   lowerCamelCase__						       =      ClassicalRegister(2						,     "cr" )

   lowerCamelCase__						       =      QuantumCircuit(A__						,     A__ )

   # entanglement the qubits
   quantum_circuit.h(1 )
   quantum_circuit.cx(1						,     0 )

   # send the information
   lowerCamelCase__						       =      str(A__ ) + str(A__ )

   if c_information == "11":
      quantum_circuit.x(1 )
      quantum_circuit.z(1 )
   elif c_information == "10":
      quantum_circuit.z(1 )
   elif c_information == "01":
      quantum_circuit.x(1 )
   else:
      quantum_circuit.i(1 )

   # unentangled the circuit
   quantum_circuit.cx(1						,     0 )
   quantum_circuit.h(1 )

   # measure the circuit
   quantum_circuit.measure(A__						,     A__ )

   lowerCamelCase__						       =      Aer.get_backend("aer_simulator" )
   lowerCamelCase__						       =      execute(A__						,     A__						,     shots=1000 )

   return job.result().get_counts(A__ )


if __name__ == "__main__":
     print(F'''Counts for classical state send: {superdense_coding(1,1)}''')




