



'''simple docstring'''

import qiskit






def 						_snake_case						(   _SCREAMING_SNAKE_CASE	:		int				,						_SCREAMING_SNAKE_CASE	:		int				)     ->		qiskit.result.counts.Counts:







	"""simple docstring"""
	lowerCAmelCase       =      qiskit.Aer.get_backend("""aer_simulator"""				)

	lowerCAmelCase       =      qiskit.QuantumCircuit(4				,						2				)
	# encode inputs in qubits 0 and 1
	if bita == 1:
		qc_ha.x(0				)
	if bita == 1:
		qc_ha.x(1				)
	qc_ha.barrier()

	# use cnots to write XOR of the inputs on qubit2
	qc_ha.cx(0				,						2				)
	qc_ha.cx(1				,						2				)

	# use ccx / toffoli gate to write AND of the inputs on qubit3
	qc_ha.ccx(0				,						1				,						3				)
	qc_ha.barrier()

	# extract outputs
	qc_ha.measure(2				,						0				)  # extract XOR value
	qc_ha.measure(3				,						1				)  # extract AND value

	# Execute the circuit on the qasm simulator
	lowerCAmelCase       =      qiskit.execute(__UpperCamelCase				,						__UpperCamelCase				,						shots=1_000				)

	# Return the histogram data of the results of the experiment
	return job.result().get_counts(__UpperCamelCase				)


if __name__ == "__main__":
				UpperCAmelCase      						=       half_adder(1, 1)
				print(F'''Half Adder Output Qubit Counts: {counts}''')



'''simple docstring'''
import flax.linen as nn
import jax.numpy as jnp

from .attention_flax import FlaxTransformeraDModel
from .resnet_flax import FlaxDownsampleaD, FlaxResnetBlockaD, FlaxUpsampleaD






class        lowerCAmelCase_  (     nn.Module	):
       __UpperCAmelCase					=42
       __UpperCAmelCase					=42
       __UpperCAmelCase					=0.0
       __UpperCAmelCase					=1
       __UpperCAmelCase					=1
       __UpperCAmelCase					=True
       __UpperCAmelCase					=False
       __UpperCAmelCase					=False
       __UpperCAmelCase					=False
       __UpperCAmelCase					=jnp.floataa






       def   UpperCamelCase						( self   )->      int:
            _A				=							[]
            _A				=							[]

            for i in range(self.num_layers   ):
                 _A				=							self.in_channels if i == 0 else self.out_channels

                 _A				=							FlaxResnetBlockaD(
                     in_channels=_UpperCamelCase			,     out_channels=self.out_channels			,     dropout_prob=self.dropout			,     dtype=self.dtype			,     )
                 resnets.append(_UpperCamelCase   )

                 _A				=							FlaxTransformeraDModel(
                     in_channels=self.out_channels			,     n_heads=self.num_attention_heads			,     d_head=self.out_channels // self.num_attention_heads			,     depth=1			,     use_linear_projection=self.use_linear_projection			,     only_cross_attention=self.only_cross_attention			,     use_memory_efficient_attention=self.use_memory_efficient_attention			,     dtype=self.dtype			,     )
                 attentions.append(_UpperCamelCase   )

            _A				=							resnets
            _A				=							attentions

            if self.add_downsample:
                 _A				=							FlaxDownsampleaD(self.out_channels			,     dtype=self.dtype   )






       def __call__( self			,     _UpperCamelCase			,     _UpperCamelCase			,     _UpperCamelCase			,     _UpperCamelCase=True   )->      Dict:
            _A				=							()

            for resnet, attn in zip(self.resnets			,     self.attentions   ):
                 _A				=							resnet(_UpperCamelCase			,     _UpperCamelCase			,     deterministic=_UpperCamelCase   )
                 _A				=							attn(_UpperCamelCase			,     _UpperCamelCase			,     deterministic=_UpperCamelCase   )
                 output_states += (hidden_states,)

            if self.add_downsample:
                 _A				=							self.downsamplers_a(_UpperCamelCase   )
                 output_states += (hidden_states,)

            return hidden_states, output_states






class        lowerCAmelCase_  (     nn.Module	):
       __UpperCAmelCase					=42
       __UpperCAmelCase					=42
       __UpperCAmelCase					=0.0
       __UpperCAmelCase					=1
       __UpperCAmelCase					=True
       __UpperCAmelCase					=jnp.floataa






       def   UpperCamelCase						( self   )->      Optional[Any]:
            _A				=							[]

            for i in range(self.num_layers   ):
                 _A				=							self.in_channels if i == 0 else self.out_channels

                 _A				=							FlaxResnetBlockaD(
                     in_channels=_UpperCamelCase			,     out_channels=self.out_channels			,     dropout_prob=self.dropout			,     dtype=self.dtype			,     )
                 resnets.append(_UpperCamelCase   )
            _A				=							resnets

            if self.add_downsample:
                 _A				=							FlaxDownsampleaD(self.out_channels			,     dtype=self.dtype   )






       def __call__( self			,     _UpperCamelCase			,     _UpperCamelCase			,     _UpperCamelCase=True   )->      Union[str, Any]:
            _A				=							()

            for resnet in self.resnets:
                 _A				=							resnet(_UpperCamelCase			,     _UpperCamelCase			,     deterministic=_UpperCamelCase   )
                 output_states += (hidden_states,)

            if self.add_downsample:
                 _A				=							self.downsamplers_a(_UpperCamelCase   )
                 output_states += (hidden_states,)

            return hidden_states, output_states






class        lowerCAmelCase_  (     nn.Module	):
       __UpperCAmelCase					=42
       __UpperCAmelCase					=42
       __UpperCAmelCase					=42
       __UpperCAmelCase					=0.0
       __UpperCAmelCase					=1
       __UpperCAmelCase					=1
       __UpperCAmelCase					=True
       __UpperCAmelCase					=False
       __UpperCAmelCase					=False
       __UpperCAmelCase					=False
       __UpperCAmelCase					=jnp.floataa






       def   UpperCamelCase						( self   )->      str:
            _A				=							[]
            _A				=							[]

            for i in range(self.num_layers   ):
                 _A				=							self.in_channels if (i == self.num_layers - 1) else self.out_channels
                 _A				=							self.prev_output_channel if i == 0 else self.out_channels

                 _A				=							FlaxResnetBlockaD(
                     in_channels=resnet_in_channels + res_skip_channels			,     out_channels=self.out_channels			,     dropout_prob=self.dropout			,     dtype=self.dtype			,     )
                 resnets.append(_UpperCamelCase   )

                 _A				=							FlaxTransformeraDModel(
                     in_channels=self.out_channels			,     n_heads=self.num_attention_heads			,     d_head=self.out_channels // self.num_attention_heads			,     depth=1			,     use_linear_projection=self.use_linear_projection			,     only_cross_attention=self.only_cross_attention			,     use_memory_efficient_attention=self.use_memory_efficient_attention			,     dtype=self.dtype			,     )
                 attentions.append(_UpperCamelCase   )

            _A				=							resnets
            _A				=							attentions

            if self.add_upsample:
                 _A				=							FlaxUpsampleaD(self.out_channels			,     dtype=self.dtype   )






       def __call__( self			,     _UpperCamelCase			,     _UpperCamelCase			,     _UpperCamelCase			,     _UpperCamelCase			,     _UpperCamelCase=True   )->      Dict:
            for resnet, attn in zip(self.resnets			,     self.attentions   ):
                 # pop res hidden states
                 _A				=							res_hidden_states_tuple[-1]
                 _A				=							res_hidden_states_tuple[:-1]
                 _A				=							jnp.concatenate((hidden_states, res_hidden_states)			,     axis=-1   )

                 _A				=							resnet(_UpperCamelCase			,     _UpperCamelCase			,     deterministic=_UpperCamelCase   )
                 _A				=							attn(_UpperCamelCase			,     _UpperCamelCase			,     deterministic=_UpperCamelCase   )

            if self.add_upsample:
                 _A				=							self.upsamplers_a(_UpperCamelCase   )

            return hidden_states






class        lowerCAmelCase_  (     nn.Module	):
       __UpperCAmelCase					=42
       __UpperCAmelCase					=42
       __UpperCAmelCase					=42
       __UpperCAmelCase					=0.0
       __UpperCAmelCase					=1
       __UpperCAmelCase					=True
       __UpperCAmelCase					=jnp.floataa






       def   UpperCamelCase						( self   )->      Optional[Any]:
            _A				=							[]

            for i in range(self.num_layers   ):
                 _A				=							self.in_channels if (i == self.num_layers - 1) else self.out_channels
                 _A				=							self.prev_output_channel if i == 0 else self.out_channels

                 _A				=							FlaxResnetBlockaD(
                     in_channels=resnet_in_channels + res_skip_channels			,     out_channels=self.out_channels			,     dropout_prob=self.dropout			,     dtype=self.dtype			,     )
                 resnets.append(_UpperCamelCase   )

            _A				=							resnets

            if self.add_upsample:
                 _A				=							FlaxUpsampleaD(self.out_channels			,     dtype=self.dtype   )






       def __call__( self			,     _UpperCamelCase			,     _UpperCamelCase			,     _UpperCamelCase			,     _UpperCamelCase=True   )->      Dict:
            for resnet in self.resnets:
                 # pop res hidden states
                 _A				=							res_hidden_states_tuple[-1]
                 _A				=							res_hidden_states_tuple[:-1]
                 _A				=							jnp.concatenate((hidden_states, res_hidden_states)			,     axis=-1   )

                 _A				=							resnet(_UpperCamelCase			,     _UpperCamelCase			,     deterministic=_UpperCamelCase   )

            if self.add_upsample:
                 _A				=							self.upsamplers_a(_UpperCamelCase   )

            return hidden_states






class        lowerCAmelCase_  (     nn.Module	):
       __UpperCAmelCase					=42
       __UpperCAmelCase					=0.0
       __UpperCAmelCase					=1
       __UpperCAmelCase					=1
       __UpperCAmelCase					=False
       __UpperCAmelCase					=False
       __UpperCAmelCase					=jnp.floataa






       def   UpperCamelCase						( self   )->      Dict:
            # there is always at least one resnet
            _A				=							[
                FlaxResnetBlockaD(
                    in_channels=self.in_channels			,     out_channels=self.in_channels			,     dropout_prob=self.dropout			,     dtype=self.dtype			,     )
            ]

            _A				=							[]

            for _ in range(self.num_layers   ):
                 _A				=							FlaxTransformeraDModel(
                     in_channels=self.in_channels			,     n_heads=self.num_attention_heads			,     d_head=self.in_channels // self.num_attention_heads			,     depth=1			,     use_linear_projection=self.use_linear_projection			,     use_memory_efficient_attention=self.use_memory_efficient_attention			,     dtype=self.dtype			,     )
                 attentions.append(_UpperCamelCase   )

                 _A				=							FlaxResnetBlockaD(
                     in_channels=self.in_channels			,     out_channels=self.in_channels			,     dropout_prob=self.dropout			,     dtype=self.dtype			,     )
                 resnets.append(_UpperCamelCase   )

            _A				=							resnets
            _A				=							attentions






       def __call__( self			,     _UpperCamelCase			,     _UpperCamelCase			,     _UpperCamelCase			,     _UpperCamelCase=True   )->      List[Any]:
            _A				=							self.resnets[0](_UpperCamelCase			,     _UpperCamelCase   )
            for attn, resnet in zip(self.attentions			,     self.resnets[1:]   ):
                 _A				=							attn(_UpperCamelCase			,     _UpperCamelCase			,     deterministic=_UpperCamelCase   )
                 _A				=							resnet(_UpperCamelCase			,     _UpperCamelCase			,     deterministic=_UpperCamelCase   )

            return hidden_states





