# Path: enn/base.py
# class OutputWithPrior(NamedTuple):
# class EpistemicModule(abc.ABC, hk.Module):
# class ApplyFn(typing_extensions.Protocol):
# class InitFn(typing_extensions.Protocol):
# class EpistemicIndexer(typing_extensions.Protocol):
# class EpistemicNetwork:
# class Batch(NamedTuple):
# class LossFn(typing_extensions.Protocol):
# class EpistemicNetworkWithState:
# class LossFnWithState(typing_extensions.Protocol):
#   def preds(self) -> Array:
#   def __call__(self, inputs: Array, index: Index) -> Output:
#   def __call__(self, params: hk.Params, inputs: Array, index: Index) -> Output:
#   def __call__(self, rng_key: RngKey, inputs: Array, index: Index) -> hk.Params:
#   def __call__(self, key: RngKey) -> Index:
#   def __call__(self,
#                enn: EpistemicNetwork,
#                params: hk.Params,
#                batch: Batch,
#                key: RngKey) -> Tuple[Array, LossMetrics]:
#   def __call__(self,
#                enn: EpistemicNetworkWithState,
#                params: hk.Params,
#                state: hk.State,
#                batch: Batch,
#                key: RngKey) -> Tuple[Array, Tuple[hk.State, LossMetrics]]:
# 
# Path: enn/supervised/base.py
# class BaseExperiment(abc.ABC):
#   def train(self, num_batches: int):
#   def predict(
#       self, inputs: base.Array, key: base.RngKey) -> base.Array:
#   def loss(self, batch: base.Batch, key: base.RngKey) -> base.Array:


import functools
import dataclasses
import haiku as hk
import jax
import optax
from typing import Callable, Dict, NamedTuple, Optional, Sequence, Tuple
from acme.utils import loggers
from enn import base
from enn.supervised import base as supervised_base
# 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.
# ============================================================================

"""An SGD experiment with facility for multiple losses."""




class TrainingState(NamedTuple):
  params: hk.Params
  opt_state: optax.OptState


@dataclasses.dataclass
class MultilossTrainer:
  """Specify the training schedule for a given loss/dataset.

  For step=1,2,...:
    If should_train(step):
      Apply one step of loss_fn on a batch = next(dataset).
  """

# Path: enn/base.py
# class OutputWithPrior(NamedTuple):
# class EpistemicModule(abc.ABC, hk.Module):
# class ApplyFn(typing_extensions.Protocol):
# class InitFn(typing_extensions.Protocol):
# class EpistemicIndexer(typing_extensions.Protocol):
# class EpistemicNetwork:
# class Batch(NamedTuple):
# class LossFn(typing_extensions.Protocol):
# class EpistemicNetworkWithState:
# class LossFnWithState(typing_extensions.Protocol):
#   def preds(self) -> Array:
#   def __call__(self, inputs: Array, index: Index) -> Output:
#   def __call__(self, params: hk.Params, inputs: Array, index: Index) -> Output:
#   def __call__(self, rng_key: RngKey, inputs: Array, index: Index) -> hk.Params:
#   def __call__(self, key: RngKey) -> Index:
#   def __call__(self,
#                enn: EpistemicNetwork,
#                params: hk.Params,
#                batch: Batch,
#                key: RngKey) -> Tuple[Array, LossMetrics]:
#   def __call__(self,
#                enn: EpistemicNetworkWithState,
#                params: hk.Params,
#                state: hk.State,
#                batch: Batch,
#                key: RngKey) -> Tuple[Array, Tuple[hk.State, LossMetrics]]:
# 
# Path: enn/supervised/base.py
# class BaseExperiment(abc.ABC):
#   def train(self, num_batches: int):
#   def predict(
#       self, inputs: base.Array, key: base.RngKey) -> base.Array:
#   def loss(self, batch: base.Batch, key: base.RngKey) -> base.Array:


# Path: enn/supervised/multiloss_experiment.py
import functools
import dataclasses
import haiku as hk
import jax
import optax
from typing import Callable, Dict, NamedTuple, Optional, Sequence, Tuple
from acme.utils import loggers
from enn import base
from enn.supervised import base as supervised_base

# 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.
# ============================================================================

"""An SGD experiment with facility for multiple losses."""




class TrainingState(NamedTuple):
  params: hk.Params
  opt_state: optax.OptState


@dataclasses.dataclass
class MultilossTrainer:
  """Specify the training schedule for a given loss/dataset.

  For step=1,2,...:
    If should_train(step):
      Apply one step of loss_fn on a batch = next(dataset).
  """

  loss_fn: base.LossFn  # Loss function