"""simple docstring"""






# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import torch

from accelerate import PartialState
from accelerate.utils.operations import broadcast, gather, gather_object, pad_across_processes, reduce



def   a_						(					lowerCamelCase       ):
				return (torch.arange(state.num_processes       ) + 1.0 + (state.num_processes * state.process_index)).to(state.device       )



def   a_						(					lowerCamelCase       ):
				UpperCAmelCase__             =							create_tensor(lowerCamelCase       )
				UpperCAmelCase__             =							gather(lowerCamelCase       )
				assert gathered_tensor.tolist() == list(range(1					,			state.num_processes**2 + 1       )       )



def   a_						(					lowerCamelCase       ):
				UpperCAmelCase__             =							[state.process_index]
				UpperCAmelCase__             =							gather_object(lowerCamelCase       )
				assert len(lowerCamelCase       ) == state.num_processes, f'''{gathered_obj}, {len(lowerCamelCase       )} != {state.num_processes}'''
				assert gathered_obj == list(range(state.num_processes       )       ), f'''{gathered_obj} != {list(range(state.num_processes       )       )}'''



def   a_						(					lowerCamelCase       ):
				UpperCAmelCase__             =							create_tensor(lowerCamelCase       )
				UpperCAmelCase__             =							broadcast(lowerCamelCase       )
				assert broadcasted_tensor.shape == torch.Size([state.num_processes]       )
				assert broadcasted_tensor.tolist() == list(range(1					,			state.num_processes + 1       )       )



def   a_						(					lowerCamelCase       ):
				# We need to pad the tensor with one more element if we are the main process
				# to ensure that we can pad
				if state.is_main_process:
								UpperCAmelCase__             =							torch.arange(state.num_processes + 1       ).to(state.device       )
				else:
								UpperCAmelCase__             =							torch.arange(state.num_processes       ).to(state.device       )
				UpperCAmelCase__             =							pad_across_processes(lowerCamelCase       )
				assert padded_tensor.shape == torch.Size([state.num_processes + 1]       )
				if not state.is_main_process:
								assert padded_tensor.tolist() == list(range(0					,			state.num_processes       )       ) + [0]



def   a_						(					lowerCamelCase       ):
				# For now runs on only two processes
				if state.num_processes != 2:
								return
				UpperCAmelCase__             =							create_tensor(lowerCamelCase       )
				UpperCAmelCase__             =							reduce(lowerCamelCase					,			'sum'       )
				UpperCAmelCase__             =							torch.tensor([4.0, 6]       ).to(state.device       )
				assert torch.allclose(lowerCamelCase					,			lowerCamelCase       ), f'''{reduced_tensor} != {truth_tensor}'''



def   a_						(					lowerCamelCase       ):
				# For now runs on only two processes
				if state.num_processes != 2:
								return
				UpperCAmelCase__             =							create_tensor(lowerCamelCase       )
				UpperCAmelCase__             =							reduce(lowerCamelCase					,			'mean'       )
				UpperCAmelCase__             =							torch.tensor([2.0, 3]       ).to(state.device       )
				assert torch.allclose(lowerCamelCase					,			lowerCamelCase       ), f'''{reduced_tensor} != {truth_tensor}'''



def   a_						(					lowerCamelCase       ):
				# For xla_spawn (TPUs)
				main()



def   a_						(					):
				UpperCAmelCase__             =							PartialState()
				state.print(f'''State: {state}'''       )
				state.print('testing gather'       )
				test_gather(lowerCamelCase       )
				state.print('testing gather_object'       )
				test_gather_object(lowerCamelCase       )
				state.print('testing broadcast'       )
				test_broadcast(lowerCamelCase       )
				state.print('testing pad_across_processes'       )
				test_pad_across_processes(lowerCamelCase       )
				state.print('testing reduce_sum'       )
				test_reduce_sum(lowerCamelCase       )
				state.print('testing reduce_mean'       )
				test_reduce_mean(lowerCamelCase       )


if __name__ == "__main__":
						main()




"""simple docstring"""






import requests
from bsa import BeautifulSoup



def   a_						(					lowerCamelCase					,			lowerCamelCase       ):
				UpperCAmelCase__             =							BeautifulSoup(requests.get(lowerCamelCase					,			params=lowerCamelCase       ).content					,			'html.parser'       )
				UpperCAmelCase__             =							soup.find('div'					,			attrs={'class': 'gs_ri'}       )
				UpperCAmelCase__             =							div.find('div'					,			attrs={'class': 'gs_fl'}       ).find_all('a'       )
				return anchors[2].get_text()


if __name__ == "__main__":
						lowerCAmelCase__  :  Optional[int]						     =	{
						    'title': (
						        'Precisely geometry controlled microsupercapacitors for ultrahigh areal '
						        'capacitance, volumetric capacitance, and energy density'
						    ),
						    'journal': 'Chem. Mater.',
						    'volume': 30,
						    'pages': '3979-3990',
						    'year': 2_018,
						    'hl': 'en',
						}
						print(get_citation('https://scholar.google.com/scholar_lookup', params=params))



