



"""simple docstring"""







import numpy as np
import qiskit
from qiskit import Aer, ClassicalRegister, QuantumCircuit, QuantumRegister, execute

def 							UpperCamelCase_       (       lowerCAmelCase__ :							float = np.pi / 2       ,  lowerCAmelCase__ :							float = np.pi / 2       ,  lowerCAmelCase__ :							float = np.pi / 2		)		->  qiskit.result.counts.Counts:

  """simple docstring"""




  lowerCAmelCase_  :							Optional[Any]								=					QuantumRegister(3       ,  'qr'		)  # Define the number of quantum bits
  lowerCAmelCase_  :							Dict								=					ClassicalRegister(1       ,  'cr'		)  # Define the number of classical bits

  lowerCAmelCase_  :							List[str]								=					QuantumCircuit(lowerCAmelCase__       ,  lowerCAmelCase__		)  # Define the quantum circuit.

  # Build the circuit
  quantum_circuit.u(lowerCAmelCase__       ,  lowerCAmelCase__       ,  lowerCAmelCase__       ,  0		)  # Quantum State to teleport
  quantum_circuit.h(1		)  # add hadamard gate
  quantum_circuit.cx(
      1       ,  2		)  # add control gate with qubit 1 as control and 2 as target.
  quantum_circuit.cx(0       ,  1		)
  quantum_circuit.h(0		)
  quantum_circuit.cz(0       ,  2		)  # add control z gate.
  quantum_circuit.cx(1       ,  2		)

  quantum_circuit.measure([2]       ,  [0]		)  # measure the qubit.

  # Simulate the circuit using qasm simulator
  lowerCAmelCase_  :							int								=					Aer.get_backend('aer_simulator'		)
  lowerCAmelCase_  :							List[str]								=					execute(lowerCAmelCase__       ,  lowerCAmelCase__       ,  shots=1000		)

  return job.result().get_counts(lowerCAmelCase__		)


if __name__ == "__main__":
     print(
         """Total count for teleported state is: """
         f'{quantum_teleportation(np.pi/2, np.pi/2, np.pi/2)}'
     )










"""simple docstring"""







import os
from dataclasses import replace

import jax
import wandb
from bigbird_flax import Args, DataCollator, FlaxBigBirdForNaturalQuestions, Trainer, build_tx, train_step, val_step
from datasets import load_dataset
from flax import jax_utils

from transformers import BigBirdTokenizerFast


if __name__ == "__main__":
     print("""#################### AVAILABLE DEVICES ####################""")
     print(jax.devices())
     print("""###########################################################""")

     # setup for wandb sweep
     lowercase__						:							Any        =      Args()
     lowercase__						:							List[Any]        =      wandb.init(project="""bigbird-natural-questions""", config=args.__dict__)
     lowercase__						:							List[Any]        =      dict(logger.config)
     del wandb_args["batch_size"]
     lowercase__						:							List[str]        =      replace(args, **wandb_args)
     lowercase__						:							Any        =      args.base_dir + """-""" + wandb.run.id
     lowercase__						:							Tuple        =      replace(args, base_dir=base_dir)
     print(args)

     lowercase__						:							Optional[Any]        =      load_dataset("""json""", data_files=args.tr_data_path)["""train"""]
     lowercase__						:							Union[str, Any]        =      load_dataset("""json""", data_files=args.val_data_path)["""train"""]

     # drop extra batch for now
     lowercase__						:							Tuple        =      range(len(tr_dataset) - len(tr_dataset) % args.batch_size)
     lowercase__						:							Tuple        =      tr_dataset.shuffle().select(indices)
     lowercase__						:							Optional[int]        =      range(len(val_dataset) - len(val_dataset) % args.batch_size)
     lowercase__						:							str        =      val_dataset.shuffle().select(indices)

     if os.environ.get("""TRAIN_ON_SMALL""", """false""") == "true":
          lowercase__						:							Optional[int]        =      tr_dataset.shuffle().select(range(8_0_0_0_0))
          lowercase__						:							Any        =      val_dataset.shuffle().select(range(8_0_0_0))

     print(tr_dataset)
     print(val_dataset)

     lowercase__						:							Any        =      FlaxBigBirdForNaturalQuestions.from_pretrained(
         args.model_id, block_size=args.block_size, num_random_blocks=args.num_random_blocks
     )
     lowercase__						:							int        =      BigBirdTokenizerFast.from_pretrained(args.model_id)
     lowercase__						:							Union[str, Any]        =      DataCollator(pad_id=tokenizer.pad_token_id, max_length=4_0_9_6)

     lowercase__						:							List[Any]        =      {
         """lr""": args.lr,
         """init_lr""": args.init_lr,
         """warmup_steps""": args.warmup_steps,
         """num_train_steps""": args.max_epochs * (len(tr_dataset) // args.batch_size),
         """weight_decay""": args.weight_decay,
     }
     lowercase__       ,	lowercase__						:							str        =      build_tx(**tx_args)

     lowercase__						:							List[Any]        =      Trainer(
         args=args,
         data_collator=data_collator,
         model_save_fn=model.save_pretrained,
         train_step_fn=train_step,
         val_step_fn=val_step,
         logger=logger,
         scheduler_fn=lr,
     )

     lowercase__						:							Dict        =      None
     lowercase__						:							Optional[int]        =      trainer.create_state(model, tx, num_train_steps=tx_args["""num_train_steps"""], ckpt_dir=ckpt_dir)
     try:
          trainer.train(state, tr_dataset, val_dataset)
     except KeyboardInterrupt:
          print("""Oooops; TRAINING STOPPED UNFORTUNATELY""")

     print("""SAVING WEIGHTS IN `final-weights`""")
     lowercase__						:							Any        =      jax_utils.unreplicate(state.params)
     model.save_pretrained(os.path.join(args.base_dir, """final-weights"""), params=params)





