



"""simple docstring"""

import argparse
import json
import os
import sys
import tempfile
import unittest
from argparse import Namespace
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import List, Literal, Optional

import yaml

from transformers import HfArgumentParser, TrainingArguments
from transformers.hf_argparser import make_choice_type_function, string_to_bool


# Since Python 3.10, we can use the builtin `|` operator for Union types
# See PEP 604: https://peps.python.org/pep-0604
a_			   =					sys.version_info >= (3, 10)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Dict=None				,    SCREAMING_SNAKE_CASE__ :  Any=None			):



					"""simple docstring"""





					return field(default_factory=lambda: default				,    metadata=SCREAMING_SNAKE_CASE__			)







@dataclass
class    __lowercase     :







						"""simple docstring"""







						_A		:							int
						_A		:							float
						_A		:							str
						_A		:							bool







@dataclass
class    __lowercase     :







						"""simple docstring"""







						_A		:							int							       =		42
						_A		:							str							       =		field(default="""toto"""					,    metadata={"""help""": """help message"""})







@dataclass
class    __lowercase     :







						"""simple docstring"""







						_A		:							bool							       =		False
						_A		:							bool							       =		True
						_A		:							Optional[bool]							       =		None







class    __lowercase     (					_UpperCAmelCase):







						"""simple docstring"""







						_A		:							int							       =		"""titi"""
						_A		:							str							       =		"""toto"""







class    __lowercase     (					_UpperCAmelCase):







						"""simple docstring"""







						_A		:							int							       =		"""titi"""
						_A		:							Dict							       =		"""toto"""
						_A		:							Tuple							       =		42







@dataclass
class    __lowercase     :







						"""simple docstring"""







						_A		:							BasicEnum							       =		"toto"







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		int 					=					BasicEnum(self.foo       )







@dataclass
class    __lowercase     :







						"""simple docstring"""







						_A		:							MixedTypeEnum							       =		"toto"







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Optional[Any] 					=					MixedTypeEnum(self.foo       )







@dataclass
class    __lowercase     :







						"""simple docstring"""







						_A		:							Optional[int]							       =		None
						_A		:							Optional[float]							       =		field(default=_UpperCAmelCase					,    metadata={"""help""": """help message"""})
						_A		:							Optional[str]							       =		None
						_A		:							Optional[List[str]]							       =		list_field(default=[])
						_A		:							Optional[List[int]]							       =		list_field(default=[])







@dataclass
class    __lowercase     :







						"""simple docstring"""







						_A		:							List[int]							       =		list_field(default=[])
						_A		:							List[int]							       =		list_field(default=[1, 2, 3])
						_A		:							List[str]							       =		list_field(default=["""Hallo""", """Bonjour""", """Hello"""])
						_A		:							List[float]							       =		list_field(default=[0.1, 0.2, 0.3])







@dataclass
class    __lowercase     :







						"""simple docstring"""







						_A		:							List[int]							       =		field()
						_A		:							str							       =		field()
						_A		:							BasicEnum							       =		field()







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		List[Any] 					=					BasicEnum(self.required_enum       )







@dataclass
class    __lowercase     :







						"""simple docstring"""







						_A		:							int
						_A		:							"BasicEnum"							       =		field()
						_A		:							"Optional[bool]"							       =		None
						_A		:							"str"							       =		field(default="""toto"""					,    metadata={"""help""": """help message"""})
						_A		:							"List[str]"							       =		list_field(default=["""Hallo""", """Bonjour""", """Hello"""])


if is_python_no_less_than_3_10:







			@dataclass
			class    __lowercase     :







									"""simple docstring"""







									_A		:							bool							       =		False
									_A		:							bool							       =		True
									_A		:							bool | None							       =		None







			@dataclass
			class    __lowercase     :







									"""simple docstring"""







									_A		:							int | None							       =		None
									_A		:							float | None							       =		field(default=_UpperCAmelCase					,    metadata={"""help""": """help message"""})
									_A		:							str | None							       =		None
									_A		:							list[str] | None							       =		list_field(default=[])
									_A		:							list[int] | None							       =		list_field(default=[])







class    __lowercase     (					unittest.TestCase):







						"""simple docstring"""







						def 						__UpperCamelCase							(self   ,		lowercase__   ,		lowercase__       ):
											self.assertEqual(len(a._actions       )   ,		len(b._actions       )       )
											for x, y in zip(a._actions   ,		b._actions       ):
																snake_case_					:		List[str] 					=					{k: v for k, v in vars(lowercase__       ).items() if k != """container"""}
																snake_case_					:		Optional[Any] 					=					{k: v for k, v in vars(lowercase__       ).items() if k != """container"""}

																# Choices with mixed type have custom function as "type"
																# So we need to compare results directly for equality
																if xx.get("""choices"""   ,		lowercase__       ) and yy.get("""choices"""   ,		lowercase__       ):
																					for expected_choice in yy["choices"] + xx["choices"]:
																										self.assertEqual(xx["""type"""](lowercase__       )   ,		yy["""type"""](lowercase__       )       )
																					del xx["type"], yy["type"]

																self.assertEqual(lowercase__   ,		lowercase__       )







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Any 					=					HfArgumentParser(lowercase__       )

											snake_case_					:		str 					=					argparse.ArgumentParser()
											expected.add_argument("""--foo"""   ,		type=lowercase__   ,		required=lowercase__       )
											expected.add_argument("""--bar"""   ,		type=lowercase__   ,		required=lowercase__       )
											expected.add_argument("""--baz"""   ,		type=lowercase__   ,		required=lowercase__       )
											expected.add_argument("""--flag"""   ,		type=lowercase__   ,		default=lowercase__   ,		const=lowercase__   ,		nargs="""?"""       )
											self.argparsersEqual(lowercase__   ,		lowercase__       )

											snake_case_					:		Union[str, Any] 					=					["""--foo""", """1""", """--baz""", """quux""", """--bar""", """0.5"""]
											((snake_case_)					,			)					:		Union[str, Any] 					=					parser.parse_args_into_dataclasses(lowercase__   ,		look_for_args_file=lowercase__       )
											self.assertFalse(example.flag       )







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		List[str] 					=					HfArgumentParser(lowercase__       )

											snake_case_					:		Union[str, Any] 					=					argparse.ArgumentParser()
											expected.add_argument("""--foo"""   ,		default=42   ,		type=lowercase__       )
											expected.add_argument("""--baz"""   ,		default="""toto"""   ,		type=lowercase__   ,		help="""help message"""       )
											self.argparsersEqual(lowercase__   ,		lowercase__       )







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Union[str, Any] 					=					argparse.ArgumentParser()
											expected.add_argument("""--foo"""   ,		type=lowercase__   ,		default=lowercase__   ,		const=lowercase__   ,		nargs="""?"""       )
											expected.add_argument("""--baz"""   ,		type=lowercase__   ,		default=lowercase__   ,		const=lowercase__   ,		nargs="""?"""       )
											# A boolean no_* argument always has to come after its "default: True" regular counter-part
											# and its default must be set to False
											expected.add_argument("""--no_baz"""   ,		action="""store_false"""   ,		default=lowercase__   ,		dest="""baz"""       )
											expected.add_argument("""--opt"""   ,		type=lowercase__   ,		default=lowercase__       )

											snake_case_					:		int 					=					[WithDefaultBoolExample]
											if is_python_no_less_than_3_10:
																dataclass_types.append(lowercase__       )

											for dataclass_type in dataclass_types:
																snake_case_					:		Any 					=					HfArgumentParser(lowercase__       )
																self.argparsersEqual(lowercase__   ,		lowercase__       )

																snake_case_					:		int 					=					parser.parse_args([]       )
																self.assertEqual(lowercase__   ,		Namespace(foo=lowercase__   ,		baz=lowercase__   ,		opt=lowercase__       )       )

																snake_case_					:		Optional[int] 					=					parser.parse_args(["""--foo""", """--no_baz"""]       )
																self.assertEqual(lowercase__   ,		Namespace(foo=lowercase__   ,		baz=lowercase__   ,		opt=lowercase__       )       )

																snake_case_					:		Optional[Any] 					=					parser.parse_args(["""--foo""", """--baz"""]       )
																self.assertEqual(lowercase__   ,		Namespace(foo=lowercase__   ,		baz=lowercase__   ,		opt=lowercase__       )       )

																snake_case_					:		Optional[Any] 					=					parser.parse_args(["""--foo""", """True""", """--baz""", """True""", """--opt""", """True"""]       )
																self.assertEqual(lowercase__   ,		Namespace(foo=lowercase__   ,		baz=lowercase__   ,		opt=lowercase__       )       )

																snake_case_					:		Union[str, Any] 					=					parser.parse_args(["""--foo""", """False""", """--baz""", """False""", """--opt""", """False"""]       )
																self.assertEqual(lowercase__   ,		Namespace(foo=lowercase__   ,		baz=lowercase__   ,		opt=lowercase__       )       )







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Optional[Any] 					=					HfArgumentParser(lowercase__       )

											snake_case_					:		Any 					=					argparse.ArgumentParser()
											expected.add_argument(
											    """--foo"""   ,		default="""toto"""   ,		choices=["""titi""", """toto""", 42]   ,		type=make_choice_type_function(["""titi""", """toto""", 42]       )   ,		)
											self.argparsersEqual(lowercase__   ,		lowercase__       )

											snake_case_					:		Union[str, Any] 					=					parser.parse_args([]       )
											self.assertEqual(args.foo   ,		"""toto"""       )
											snake_case_					:		Dict 					=					parser.parse_args_into_dataclasses([]       )[0]
											self.assertEqual(enum_ex.foo   ,		MixedTypeEnum.toto       )

											snake_case_					:		Optional[Any] 					=					parser.parse_args(["""--foo""", """titi"""]       )
											self.assertEqual(args.foo   ,		"""titi"""       )
											snake_case_					:		int 					=					parser.parse_args_into_dataclasses(["""--foo""", """titi"""]       )[0]
											self.assertEqual(enum_ex.foo   ,		MixedTypeEnum.titi       )

											snake_case_					:		Any 					=					parser.parse_args(["""--foo""", """42"""]       )
											self.assertEqual(args.foo   ,		42       )
											snake_case_					:		List[Any] 					=					parser.parse_args_into_dataclasses(["""--foo""", """42"""]       )[0]
											self.assertEqual(enum_ex.foo   ,		MixedTypeEnum.fourtytwo       )







						def 						__UpperCamelCase							(self       ):







											@dataclass
											class    __lowercase     :







																	"""simple docstring"""







																	_A		:							Literal["titi", "toto", 42]							       =		"toto"
											snake_case_					:		List[Any] 					=					HfArgumentParser(lowercase__       )

											snake_case_					:		Tuple 					=					argparse.ArgumentParser()
											expected.add_argument(
											    """--foo"""   ,		default="""toto"""   ,		choices=("""titi""", """toto""", 42)   ,		type=make_choice_type_function(["""titi""", """toto""", 42]       )   ,		)
											self.argparsersEqual(lowercase__   ,		lowercase__       )

											snake_case_					:		Tuple 					=					parser.parse_args([]       )
											self.assertEqual(args.foo   ,		"""toto"""       )

											snake_case_					:		Optional[int] 					=					parser.parse_args(["""--foo""", """titi"""]       )
											self.assertEqual(args.foo   ,		"""titi"""       )

											snake_case_					:		List[str] 					=					parser.parse_args(["""--foo""", """42"""]       )
											self.assertEqual(args.foo   ,		42       )







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		str 					=					HfArgumentParser(lowercase__       )

											snake_case_					:		List[str] 					=					argparse.ArgumentParser()
											expected.add_argument("""--foo_int"""   ,		nargs="""+"""   ,		default=[]   ,		type=lowercase__       )
											expected.add_argument("""--bar_int"""   ,		nargs="""+"""   ,		default=[1, 2, 3]   ,		type=lowercase__       )
											expected.add_argument("""--foo_str"""   ,		nargs="""+"""   ,		default=["""Hallo""", """Bonjour""", """Hello"""]   ,		type=lowercase__       )
											expected.add_argument("""--foo_float"""   ,		nargs="""+"""   ,		default=[0.1, 0.2, 0.3]   ,		type=lowercase__       )

											self.argparsersEqual(lowercase__   ,		lowercase__       )

											snake_case_					:		Optional[Any] 					=					parser.parse_args([]       )
											self.assertEqual(
											    lowercase__   ,		Namespace(foo_int=[]   ,		bar_int=[1, 2, 3]   ,		foo_str=["""Hallo""", """Bonjour""", """Hello"""]   ,		foo_float=[0.1, 0.2, 0.3]       )   ,		)

											snake_case_					:		Optional[int] 					=					parser.parse_args("""--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7""".split()       )
											self.assertEqual(lowercase__   ,		Namespace(foo_int=[1]   ,		bar_int=[2, 3]   ,		foo_str=["""a""", """b""", """c"""]   ,		foo_float=[0.1, 0.7]       )       )







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Dict 					=					argparse.ArgumentParser()
											expected.add_argument("""--foo"""   ,		default=lowercase__   ,		type=lowercase__       )
											expected.add_argument("""--bar"""   ,		default=lowercase__   ,		type=lowercase__   ,		help="""help message"""       )
											expected.add_argument("""--baz"""   ,		default=lowercase__   ,		type=lowercase__       )
											expected.add_argument("""--ces"""   ,		nargs="""+"""   ,		default=[]   ,		type=lowercase__       )
											expected.add_argument("""--des"""   ,		nargs="""+"""   ,		default=[]   ,		type=lowercase__       )

											snake_case_					:		int 					=					[OptionalExample]
											if is_python_no_less_than_3_10:
																dataclass_types.append(lowercase__       )

											for dataclass_type in dataclass_types:
																snake_case_					:		Dict 					=					HfArgumentParser(lowercase__       )

																self.argparsersEqual(lowercase__   ,		lowercase__       )

																snake_case_					:		int 					=					parser.parse_args([]       )
																self.assertEqual(lowercase__   ,		Namespace(foo=lowercase__   ,		bar=lowercase__   ,		baz=lowercase__   ,		ces=[]   ,		des=[]       )       )

																snake_case_					:		Optional[int] 					=					parser.parse_args("""--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3""".split()       )
																self.assertEqual(lowercase__   ,		Namespace(foo=12   ,		bar=3.14   ,		baz="""42"""   ,		ces=["""a""", """b""", """c"""]   ,		des=[1, 2, 3]       )       )







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		List[Any] 					=					HfArgumentParser(lowercase__       )

											snake_case_					:		Tuple 					=					argparse.ArgumentParser()
											expected.add_argument("""--required_list"""   ,		nargs="""+"""   ,		type=lowercase__   ,		required=lowercase__       )
											expected.add_argument("""--required_str"""   ,		type=lowercase__   ,		required=lowercase__       )
											expected.add_argument(
											    """--required_enum"""   ,		type=make_choice_type_function(["""titi""", """toto"""]       )   ,		choices=["""titi""", """toto"""]   ,		required=lowercase__   ,		)
											self.argparsersEqual(lowercase__   ,		lowercase__       )







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Union[str, Any] 					=					HfArgumentParser(lowercase__       )

											snake_case_					:		List[str] 					=					argparse.ArgumentParser()
											expected.add_argument("""--foo"""   ,		type=lowercase__   ,		required=lowercase__       )
											expected.add_argument(
											    """--required_enum"""   ,		type=make_choice_type_function(["""titi""", """toto"""]       )   ,		choices=["""titi""", """toto"""]   ,		required=lowercase__   ,		)
											expected.add_argument("""--opt"""   ,		type=lowercase__   ,		default=lowercase__       )
											expected.add_argument("""--baz"""   ,		default="""toto"""   ,		type=lowercase__   ,		help="""help message"""       )
											expected.add_argument("""--foo_str"""   ,		nargs="""+"""   ,		default=["""Hallo""", """Bonjour""", """Hello"""]   ,		type=lowercase__       )
											self.argparsersEqual(lowercase__   ,		lowercase__       )







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		List[str] 					=					HfArgumentParser(lowercase__       )

											snake_case_					:		Tuple 					=					{
											    """foo""": 12,
											    """bar""": 3.14,
											    """baz""": """42""",
											    """flag""": True,
											}

											snake_case_					:		List[Any] 					=					parser.parse_dict(lowercase__       )[0]
											snake_case_					:		Optional[int] 					=					BasicExample(**lowercase__       )
											self.assertEqual(lowercase__   ,		lowercase__       )







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		List[str] 					=					HfArgumentParser(lowercase__       )

											snake_case_					:		Tuple 					=					{
											    """foo""": 12,
											    """bar""": 3.14,
											    """baz""": """42""",
											    """flag""": True,
											    """extra""": 42,
											}

											self.assertRaises(lowercase__   ,		parser.parse_dict   ,		lowercase__   ,		allow_extra_keys=lowercase__       )







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Optional[int] 					=					HfArgumentParser(lowercase__       )

											snake_case_					:		Optional[Any] 					=					{
											    """foo""": 12,
											    """bar""": 3.14,
											    """baz""": """42""",
											    """flag""": True,
											}
											with tempfile.TemporaryDirectory() as tmp_dir:
																snake_case_					:		int 					=					os.path.join(lowercase__   ,		"""temp_json"""       )
																os.mkdir(lowercase__       )
																with open(temp_local_path + """.json"""   ,		"""w+"""       ) as f:
																					json.dump(lowercase__   ,		lowercase__       )
																snake_case_					:		Optional[Any] 					=					parser.parse_yaml_file(Path(temp_local_path + """.json"""       )       )[0]

											snake_case_					:		List[Any] 					=					BasicExample(**lowercase__       )
											self.assertEqual(lowercase__   ,		lowercase__       )







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Optional[Any] 					=					HfArgumentParser(lowercase__       )

											snake_case_					:		int 					=					{
											    """foo""": 12,
											    """bar""": 3.14,
											    """baz""": """42""",
											    """flag""": True,
											}
											with tempfile.TemporaryDirectory() as tmp_dir:
																snake_case_					:		Tuple 					=					os.path.join(lowercase__   ,		"""temp_yaml"""       )
																os.mkdir(lowercase__       )
																with open(temp_local_path + """.yaml"""   ,		"""w+"""       ) as f:
																					yaml.dump(lowercase__   ,		lowercase__       )
																snake_case_					:		Any 					=					parser.parse_yaml_file(Path(temp_local_path + """.yaml"""       )       )[0]
											snake_case_					:		Optional[int] 					=					BasicExample(**lowercase__       )
											self.assertEqual(lowercase__   ,		lowercase__       )







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		int 					=					HfArgumentParser(lowercase__       )
											self.assertIsNotNone(lowercase__       )









"""simple docstring"""

import random







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  int				,    SCREAMING_SNAKE_CASE__ :  float				,    SCREAMING_SNAKE_CASE__ :  bool = False			):



					"""simple docstring"""





					snake_case_					:		dict 					=					{i: [] for i in range(SCREAMING_SNAKE_CASE__			)}

					# if probability is greater or equal than 1, then generate a complete graph
					if probability >= 1:
										return complete_graph(SCREAMING_SNAKE_CASE__			)
					# if probability is lower or equal than 0, then return a graph without edges
					if probability <= 0:
										return graph

					# for each couple of nodes, add an edge from u to v
					# if the number randomly generated is greater than probability probability
					for i in range(SCREAMING_SNAKE_CASE__			):
										for j in range(i + 1				,    SCREAMING_SNAKE_CASE__			):
															if random.random() < probability:
																				graph[i].append(SCREAMING_SNAKE_CASE__			)
																				if not directed:
																									# if the graph is undirected, add an edge in from j to i, either
																									graph[j].append(SCREAMING_SNAKE_CASE__			)
					return graph







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  int			):



					"""simple docstring"""





					return {
					    i: [j for j in range(SCREAMING_SNAKE_CASE__			) if i != j] for i in range(SCREAMING_SNAKE_CASE__			)
					}


if __name__ == "__main__":
			import doctest

			doctest.testmod()




