






"""simple docstring"""






import subprocess
import sys

from transformers import BertConfig, BertModel, BertTokenizer, pipeline
from transformers.testing_utils import TestCasePlus, require_torch

class 							lowerCAmelCase__       (    UpperCAmelCase__				):






      '''simple docstring'''

      @require_torch
      def _SCREAMING_SNAKE_CASE				(		self  :						Optional[Any]):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	'''
from transformers import BertConfig, BertModel, BertTokenizer, pipeline
        '''

          SCREAMING_SNAKE_CASE_   :						Dict							=	'''
mname = "hf-internal-testing/tiny-random-bert"
BertConfig.from_pretrained(mname)
BertModel.from_pretrained(mname)
BertTokenizer.from_pretrained(mname)
pipe = pipeline(task="fill-mask", model=mname)
print("success")
        '''

          SCREAMING_SNAKE_CASE_   :						List[str]							=	'''
import socket
def offline_socket(*args, **kwargs): raise RuntimeError("Offline mode is enabled, we shouldn\'t access internet")
socket.socket = offline_socket
        '''

          # Force fetching the files so that we can use the cache
          SCREAMING_SNAKE_CASE_   :						Union[str, Any]							=	'''hf-internal-testing/tiny-random-bert'''
          BertConfig.from_pretrained(lowercase_)
          BertModel.from_pretrained(lowercase_)
          BertTokenizer.from_pretrained(lowercase_)
          pipeline(task='''fill-mask'''		,			model=lowercase_)

          # baseline - just load from_pretrained with normal network
          SCREAMING_SNAKE_CASE_   :						List[str]							=	[sys.executable, '''-c''', '''\n'''.join([load, run, mock])]

          # should succeed
          SCREAMING_SNAKE_CASE_   :						List[str]							=	self.get_env()
          # should succeed as TRANSFORMERS_OFFLINE=1 tells it to use local files
          SCREAMING_SNAKE_CASE_   :						Any							=	'''1'''
          SCREAMING_SNAKE_CASE_   :						Any							=	subprocess.run(lowercase_		,			env=lowercase_		,			check=lowercase_		,			capture_output=lowercase_)
          self.assertEqual(result.returncode		,			0		,			result.stderr)
          self.assertIn('''success'''		,			result.stdout.decode())
      @require_torch
      def _SCREAMING_SNAKE_CASE				(		self  :						Any):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						int							=	'''
from transformers import BertConfig, BertModel, BertTokenizer, pipeline
        '''

          SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	'''
mname = "hf-internal-testing/tiny-random-bert"
BertConfig.from_pretrained(mname)
BertModel.from_pretrained(mname)
BertTokenizer.from_pretrained(mname)
pipe = pipeline(task="fill-mask", model=mname)
print("success")
        '''

          SCREAMING_SNAKE_CASE_   :						Any							=	'''
import socket
def offline_socket(*args, **kwargs): raise socket.error("Faking flaky internet")
socket.socket = offline_socket
        '''

          # Force fetching the files so that we can use the cache
          SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	'''hf-internal-testing/tiny-random-bert'''
          BertConfig.from_pretrained(lowercase_)
          BertModel.from_pretrained(lowercase_)
          BertTokenizer.from_pretrained(lowercase_)
          pipeline(task='''fill-mask'''		,			model=lowercase_)

          # baseline - just load from_pretrained with normal network
          SCREAMING_SNAKE_CASE_   :						str							=	[sys.executable, '''-c''', '''\n'''.join([load, run, mock])]

          # should succeed
          SCREAMING_SNAKE_CASE_   :						str							=	self.get_env()
          SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	subprocess.run(lowercase_		,			env=lowercase_		,			check=lowercase_		,			capture_output=lowercase_)
          self.assertEqual(result.returncode		,			0		,			result.stderr)
          self.assertIn('''success'''		,			result.stdout.decode())
      @require_torch
      def _SCREAMING_SNAKE_CASE				(		self  :						Dict):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						Any							=	'''
from transformers import BertConfig, BertModel, BertTokenizer
        '''

          SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	'''
mname = "hf-internal-testing/tiny-random-bert-sharded"
BertConfig.from_pretrained(mname)
BertModel.from_pretrained(mname)
print("success")
        '''

          SCREAMING_SNAKE_CASE_   :						Tuple							=	'''
import socket
def offline_socket(*args, **kwargs): raise ValueError("Offline mode is enabled")
socket.socket = offline_socket
        '''

          # baseline - just load from_pretrained with normal network
          SCREAMING_SNAKE_CASE_   :						Optional[int]							=	[sys.executable, '''-c''', '''\n'''.join([load, run])]

          # should succeed
          SCREAMING_SNAKE_CASE_   :						Union[str, Any]							=	self.get_env()
          SCREAMING_SNAKE_CASE_   :						Tuple							=	subprocess.run(lowercase_		,			env=lowercase_		,			check=lowercase_		,			capture_output=lowercase_)
          self.assertEqual(result.returncode		,			0		,			result.stderr)
          self.assertIn('''success'''		,			result.stdout.decode())

          # next emulate no network
          SCREAMING_SNAKE_CASE_   :						List[Any]							=	[sys.executable, '''-c''', '''\n'''.join([load, mock, run])]

          # Doesn't fail anymore since the model is in the cache due to other tests, so commenting this.
          # env["TRANSFORMERS_OFFLINE"] = "0"
          # result = subprocess.run(cmd, env=env, check=False, capture_output=True)
          # self.assertEqual(result.returncode, 1, result.stderr)

          # should succeed as TRANSFORMERS_OFFLINE=1 tells it to use local files
          SCREAMING_SNAKE_CASE_   :						Tuple							=	'''1'''
          SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	subprocess.run(lowercase_		,			env=lowercase_		,			check=lowercase_		,			capture_output=lowercase_)
          self.assertEqual(result.returncode		,			0		,			result.stderr)
          self.assertIn('''success'''		,			result.stdout.decode())
      @require_torch
      def _SCREAMING_SNAKE_CASE				(		self  :						int):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						int							=	'''
from transformers import pipeline
        '''
          SCREAMING_SNAKE_CASE_   :						List[str]							=	'''
mname = "hf-internal-testing/tiny-random-bert"
pipe = pipeline(model=mname)
        '''

          SCREAMING_SNAKE_CASE_   :						Optional[int]							=	'''
import socket
def offline_socket(*args, **kwargs): raise socket.error("Offline mode is enabled")
socket.socket = offline_socket
        '''
          SCREAMING_SNAKE_CASE_   :						Optional[int]							=	self.get_env()
          SCREAMING_SNAKE_CASE_   :						str							=	'''1'''
          SCREAMING_SNAKE_CASE_   :						Any							=	[sys.executable, '''-c''', '''\n'''.join([load, mock, run])]
          SCREAMING_SNAKE_CASE_   :						Tuple							=	subprocess.run(lowercase_		,			env=lowercase_		,			check=lowercase_		,			capture_output=lowercase_)
          self.assertEqual(result.returncode		,			1		,			result.stderr)
          self.assertIn(
              '''You cannot infer task automatically within `pipeline` when using offline mode'''		,			result.stderr.decode().replace('''\n'''		,			'''''')		,			)



      @require_torch
      def _SCREAMING_SNAKE_CASE				(		self  :						int):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						str							=	'''
from transformers import AutoModel
        '''
          SCREAMING_SNAKE_CASE_   :						Tuple							=	'''
mname = "hf-internal-testing/test_dynamic_model"
AutoModel.from_pretrained(mname, trust_remote_code=True)
print("success")
        '''

          # baseline - just load from_pretrained with normal network
          SCREAMING_SNAKE_CASE_   :						Union[str, Any]							=	[sys.executable, '''-c''', '''\n'''.join([load, run])]

          # should succeed
          SCREAMING_SNAKE_CASE_   :						List[Any]							=	self.get_env()
          SCREAMING_SNAKE_CASE_   :						List[Any]							=	subprocess.run(lowercase_		,			env=lowercase_		,			check=lowercase_		,			capture_output=lowercase_)
          self.assertEqual(result.returncode		,			0		,			result.stderr)
          self.assertIn('''success'''		,			result.stdout.decode())

          # should succeed as TRANSFORMERS_OFFLINE=1 tells it to use local files
          SCREAMING_SNAKE_CASE_   :						List[str]							=	'''1'''
          SCREAMING_SNAKE_CASE_   :						List[Any]							=	subprocess.run(lowercase_		,			env=lowercase_		,			check=lowercase_		,			capture_output=lowercase_)
          self.assertEqual(result.returncode		,			0		,			result.stderr)
          self.assertIn('''success'''		,			result.stdout.decode())










"""simple docstring"""






from __future__ import annotations

from numpy import array, cos, cross, floataa, radians, sin
from numpy.typing import NDArray



def       _A    (__a					,       __a					,       __a = False							)				-> list[float]:
    """simple docstring"""






    if radian_mode:
        return [magnitude * cos(__a							), magnitude * sin(__a							)]
    return [magnitude * cos(radians(__a							)							), magnitude * sin(radians(__a							)							)]



def       _A    (__a					,       __a					,       __a = 10**-1							)				-> bool:
    """simple docstring"""






    SCREAMING_SNAKE_CASE_   :						NDArray[floataa]							=	cross(__a					,       __a							)
    SCREAMING_SNAKE_CASE_   :						float							=	sum(__a							)
    return abs(__a							) < eps


if __name__ == "__main__":
  # Test to check if it works
  UpperCAmelCase_     :				Union[str, Any]         =				array(
      [
          polar_force(7_1_8.4, 180 - 30),
          polar_force(8_7_9.5_4, 45),
          polar_force(100, -90),
      ]
  )

  UpperCAmelCase_     :				NDArray[floataa]         =				array([[0, 0], [0, 0], [0, 0]])

  assert in_static_equilibrium(forces, location)

  # Problem 1 in image_data/2D_problems.jpg
  UpperCAmelCase_     :				Union[str, Any]         =				array(
      [
          polar_force(30 * 9.8_1, 15),
          polar_force(215, 180 - 45),
          polar_force(264, 90 - 30),
      ]
  )

  UpperCAmelCase_     :				Optional[int]         =				array([[0, 0], [0, 0], [0, 0]])

  assert in_static_equilibrium(forces, location)

  # Problem in image_data/2D_problems_1.jpg
  UpperCAmelCase_     :				List[str]         =				array([[0, -2000], [0, -1200], [0, 15600], [0, -12400]])

  UpperCAmelCase_     :				Any         =				array([[0, 0], [6, 0], [10, 0], [12, 0]])

  assert in_static_equilibrium(forces, location)

  import doctest

  doctest.testmod()


