




import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device


if is_torch_available():
 import torch

 from transformers import XLMProphetNetForConditionalGeneration, XLMProphetNetTokenizer

@require_torch
class        _lowerCamelCase  (	unittest.TestCase      ):

      """simple docstring"""

      @slow
      def 					snake_case		(   self    :       Any ):
          __UpperCamelCase     						=  XLMProphetNetForConditionalGeneration.from_pretrained('''microsoft/xprophetnet-large-wiki100-cased''' )
          model.to(__snake_case )

          # encoder-decoder outputs
          __UpperCamelCase     						=  torch.tensor([[17, 96208, 103471, 2]] ).to(__snake_case )
          __UpperCamelCase     						=  torch.tensor(
              [[2, 250, 9953, 34, 69489, 1620, 32, 118424, 624, 210, 105, 2913, 1032, 351]] ).to(__snake_case )
          __UpperCamelCase     						=  model(
              input_ids=__snake_case       ,				attention_mask=__snake_case       ,				encoder_outputs=__snake_case       ,				decoder_input_ids=__snake_case )
          __UpperCamelCase     						=  output[0]
          __UpperCamelCase     						=  torch.Size((1, 14, 250012) )
          self.assertEqual(output_predited_logis.shape       ,				__snake_case )
          __UpperCamelCase     						=  torch.tensor(
              [[[-6.39_86, -8.23_91, 12.51_89], [-6.32_89, -8.08_64, 12.62_11], [-6.24_18, -8.04_45, 12.79_68]]] ).to(__snake_case )
          self.assertTrue(torch.allclose(output_predited_logis[:, :3, :3]       ,				__snake_case       ,				atol=1E-4 ) )

          # encoder outputs
          __UpperCamelCase     						=  model.prophetnet.encoder(__snake_case )[0]
          __UpperCamelCase     						=  torch.tensor(
              [[[-1.42_60, -0.76_28, 0.84_53], [-1.47_19, -0.13_91, 0.78_07], [-1.76_78, 0.01_14, 0.46_46]]] ).to(__snake_case )
          __UpperCamelCase     						=  torch.Size((1, 4, 1024) )
          self.assertEqual(encoder_outputs.shape       ,				__snake_case )
          self.assertTrue(torch.allclose(encoder_outputs[:, :3, :3]       ,				__snake_case       ,				atol=1E-4 ) )

          # decoder outputs
          __UpperCamelCase     						=  model.prophetnet.decoder(
              __snake_case       ,				encoder_hidden_states=__snake_case       ,				)
          __UpperCamelCase     						=  decoder_outputs[1].view(1       ,				model.config.ngram       ,				14       ,				-1 )
          __UpperCamelCase     						=  model.lm_head(__snake_case )
          __UpperCamelCase     						=  predicting_streams_logits[:, 0]
          self.assertTrue(torch.allclose(next_first_stream_logits[:, :3, :3]       ,				__snake_case       ,				atol=1E-4 ) )







      @slow
      def 					snake_case		(   self    :       str ):
          __UpperCamelCase     						=  XLMProphetNetForConditionalGeneration.from_pretrained(
              '''microsoft/xprophetnet-large-wiki100-cased-xglue-ntg''' )
          model.to(__snake_case )

          __UpperCamelCase     						=  torch.tensor([[17, 96208, 103471, 2]] ).to(__snake_case )
          __UpperCamelCase     						=  torch.tensor(
              [[2, 250, 9953, 34, 69489, 1620, 32, 118424, 624, 210, 105, 2913, 1032, 351]] ).to(__snake_case )
          __UpperCamelCase     						=  model(
              input_ids=__snake_case       ,				attention_mask=__snake_case       ,				encoder_outputs=__snake_case       ,				decoder_input_ids=__snake_case )
          __UpperCamelCase     						=  output[0]
          __UpperCamelCase     						=  torch.Size((1, 14, 250012) )
          self.assertEqual(output_predited_logis.shape       ,				__snake_case )
          # compare the actual values for a slice.
          __UpperCamelCase     						=  torch.tensor(
              [[[-9.22_53, -9.71_73, -6.35_29], [-7.67_01, -9.01_45, -1.93_82], [-8.01_95, -7.00_04, -0.15_23]]] ).to(__snake_case )

          self.assertTrue(torch.allclose(output_predited_logis[:, :3, :3]       ,				__snake_case       ,				atol=1E-4 ) )







      @slow
      def 					snake_case		(   self    :       List[str] ):
          __UpperCamelCase     						=  XLMProphetNetForConditionalGeneration.from_pretrained(
              '''microsoft/xprophetnet-large-wiki100-cased-xglue-ntg''' )
          model.to(__snake_case )
          __UpperCamelCase     						=  512

          __UpperCamelCase     						=  XLMProphetNetTokenizer.from_pretrained('''microsoft/xprophetnet-large-wiki100-cased-xglue-ntg''' )

          __UpperCamelCase     						=  (
              '''Microsoft Corporation intends to officially end free support for the Windows 7 operating system after'''
              ''' January 14, 2020, according to the official portal of the organization. From that day, users of this'''
              ''' system will not be able to receive security updates, which could make their computers vulnerable to'''
              ''' cyber attacks.'''
          )
          __UpperCamelCase     						=  (
              '''орпорация Microsoft намерена официально прекратить бесплатную поддержку операционной системы Windows 7'''
              ''' после 14 января 2020 года, сообщается на официальном портале организации . С указанного дня пользователи'''
              ''' этой системы не смогут получать обновления безопасности, из-за чего их компьютеры могут стать уязвимыми'''
              ''' к кибератакам.'''
          )
          __UpperCamelCase     						=  (
              '''根据该组织的官方门户网站，微软公司打算在2020年1月14日之后正式终止对Windows 7操作系统的免费支持。从那时起，该系统的用户将无法接收安全更新，这可能会使他们的计算机容易受到网络攻击。'''
          )

          __UpperCamelCase     						=  tokenizer(
              [EN_SENTENCE, RU_SENTENCE, ZH_SENTENCE]       ,				padding=__snake_case       ,				max_length=255       ,				return_tensors='''pt''' ).input_ids
          __UpperCamelCase     						=  input_ids.to(__snake_case )

          __UpperCamelCase     						=  model.generate(
              __snake_case       ,				num_beams=10       ,				length_penalty=1.0       ,				no_repeat_ngram_size=3       ,				early_stopping=__snake_case )
          __UpperCamelCase     						=  [tokenizer.decode(__snake_case       ,				skip_special_tokens=__snake_case ) for g in summary_ids]
          __UpperCamelCase     						=  '''Microsoft to end Windows 7 free support after January 14, 2020'''
          __UpperCamelCase     						=  '''Microsoft намерена прекратить бесплатную поддержку Windows 7 после 14 января 2020 года'''
          __UpperCamelCase     						=  '''微软打算终止对Windows 7操作系统的免费支持'''
          self.assertListEqual(
              [EXPECTED_TITLE_EN, EXPECTED_TITLE_RU, EXPECTED_TITLE_ZH]       ,				__snake_case       ,				)

          __UpperCamelCase     						=  model.generate(
              __snake_case       ,				num_beams=1       ,				length_penalty=1.0       ,				no_repeat_ngram_size=3       ,				early_stopping=__snake_case )
          __UpperCamelCase     						=  [
              tokenizer.convert_ids_to_tokens(__snake_case       ,				skip_special_tokens=__snake_case ) for g in summary_ids_beama
          ]
          __UpperCamelCase     						=  '''▁Microsoft ▁to ▁end ▁free ▁support ▁for ▁Windows ▁7'''.split(''' ''' )
          __UpperCamelCase     						=  '''▁Microsoft ▁намерен а ▁прекрати ть ▁бес плат ную ▁поддержку ▁Windows ▁7 ▁после ▁14 ▁января ▁2020 ▁года'''.split(
              ''' ''' )
          __UpperCamelCase     						=  '''微软 公司 打算 终止 对 Windows ▁7 操作 系统的 免费 支持'''.split(''' ''' )
          self.assertListEqual(
              [EXPECTED_TITLE_EN_BEAM1_TOK, EXPECTED_TITLE_RU_BEAM1_TOK, EXPECTED_TITLE_ZH_BEAM1_TOK]       ,				__snake_case       ,				)












import math

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




def 					SCREAMING_SNAKE_CASE	(       __UpperCamelCase			:						int = 1       ,     __UpperCamelCase			:						int = 1      )  ->							qiskit.result.counts.Counts:
    if isinstance(__UpperCamelCase       ,     __UpperCamelCase      ) or isinstance(__UpperCamelCase       ,     __UpperCamelCase      ):
        raise TypeError('''inputs must be integers.'''      )
    if (bit_a < 0) or (bit_a < 0):
        raise ValueError('''inputs must be positive.'''      )
    if (math.floor(__UpperCamelCase      ) != bit_a) or (math.floor(__UpperCamelCase      ) != 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
    UpperCAmelCase_							 =     QuantumRegister(2       ,     '''qr'''      )
    UpperCAmelCase_							 =     ClassicalRegister(2       ,     '''cr'''      )

    UpperCAmelCase_							 =     QuantumCircuit(__UpperCamelCase       ,     __UpperCamelCase      )

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

    # send the information
    UpperCAmelCase_							 =     str(__UpperCamelCase      ) + str(__UpperCamelCase      )

    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(__UpperCamelCase       ,     __UpperCamelCase      )

    UpperCAmelCase_							 =     Aer.get_backend('''aer_simulator'''      )
    UpperCAmelCase_							 =     execute(__UpperCamelCase       ,     __UpperCamelCase       ,     shots=1000      )

    return job.result().get_counts(__UpperCamelCase      )


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





