{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.SageMaker.Types.CheckpointConfig
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.SageMaker.Types.CheckpointConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Contains information about the output location for managed spot training
-- checkpoint data.
--
-- /See:/ 'newCheckpointConfig' smart constructor.
data CheckpointConfig = CheckpointConfig'
  { -- | (Optional) The local directory where checkpoints are written. The
    -- default directory is @\/opt\/ml\/checkpoints\/@.
    CheckpointConfig -> Maybe Text
localPath :: Prelude.Maybe Prelude.Text,
    -- | Identifies the S3 path where you want SageMaker to store checkpoints.
    -- For example, @s3:\/\/bucket-name\/key-name-prefix@.
    CheckpointConfig -> Text
s3Uri :: Prelude.Text
  }
  deriving (CheckpointConfig -> CheckpointConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CheckpointConfig -> CheckpointConfig -> Bool
$c/= :: CheckpointConfig -> CheckpointConfig -> Bool
== :: CheckpointConfig -> CheckpointConfig -> Bool
$c== :: CheckpointConfig -> CheckpointConfig -> Bool
Prelude.Eq, ReadPrec [CheckpointConfig]
ReadPrec CheckpointConfig
Int -> ReadS CheckpointConfig
ReadS [CheckpointConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CheckpointConfig]
$creadListPrec :: ReadPrec [CheckpointConfig]
readPrec :: ReadPrec CheckpointConfig
$creadPrec :: ReadPrec CheckpointConfig
readList :: ReadS [CheckpointConfig]
$creadList :: ReadS [CheckpointConfig]
readsPrec :: Int -> ReadS CheckpointConfig
$creadsPrec :: Int -> ReadS CheckpointConfig
Prelude.Read, Int -> CheckpointConfig -> ShowS
[CheckpointConfig] -> ShowS
CheckpointConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CheckpointConfig] -> ShowS
$cshowList :: [CheckpointConfig] -> ShowS
show :: CheckpointConfig -> String
$cshow :: CheckpointConfig -> String
showsPrec :: Int -> CheckpointConfig -> ShowS
$cshowsPrec :: Int -> CheckpointConfig -> ShowS
Prelude.Show, forall x. Rep CheckpointConfig x -> CheckpointConfig
forall x. CheckpointConfig -> Rep CheckpointConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CheckpointConfig x -> CheckpointConfig
$cfrom :: forall x. CheckpointConfig -> Rep CheckpointConfig x
Prelude.Generic)

-- |
-- Create a value of 'CheckpointConfig' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'localPath', 'checkpointConfig_localPath' - (Optional) The local directory where checkpoints are written. The
-- default directory is @\/opt\/ml\/checkpoints\/@.
--
-- 's3Uri', 'checkpointConfig_s3Uri' - Identifies the S3 path where you want SageMaker to store checkpoints.
-- For example, @s3:\/\/bucket-name\/key-name-prefix@.
newCheckpointConfig ::
  -- | 's3Uri'
  Prelude.Text ->
  CheckpointConfig
newCheckpointConfig :: Text -> CheckpointConfig
newCheckpointConfig Text
pS3Uri_ =
  CheckpointConfig'
    { $sel:localPath:CheckpointConfig' :: Maybe Text
localPath = forall a. Maybe a
Prelude.Nothing,
      $sel:s3Uri:CheckpointConfig' :: Text
s3Uri = Text
pS3Uri_
    }

-- | (Optional) The local directory where checkpoints are written. The
-- default directory is @\/opt\/ml\/checkpoints\/@.
checkpointConfig_localPath :: Lens.Lens' CheckpointConfig (Prelude.Maybe Prelude.Text)
checkpointConfig_localPath :: Lens' CheckpointConfig (Maybe Text)
checkpointConfig_localPath = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CheckpointConfig' {Maybe Text
localPath :: Maybe Text
$sel:localPath:CheckpointConfig' :: CheckpointConfig -> Maybe Text
localPath} -> Maybe Text
localPath) (\s :: CheckpointConfig
s@CheckpointConfig' {} Maybe Text
a -> CheckpointConfig
s {$sel:localPath:CheckpointConfig' :: Maybe Text
localPath = Maybe Text
a} :: CheckpointConfig)

-- | Identifies the S3 path where you want SageMaker to store checkpoints.
-- For example, @s3:\/\/bucket-name\/key-name-prefix@.
checkpointConfig_s3Uri :: Lens.Lens' CheckpointConfig Prelude.Text
checkpointConfig_s3Uri :: Lens' CheckpointConfig Text
checkpointConfig_s3Uri = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CheckpointConfig' {Text
s3Uri :: Text
$sel:s3Uri:CheckpointConfig' :: CheckpointConfig -> Text
s3Uri} -> Text
s3Uri) (\s :: CheckpointConfig
s@CheckpointConfig' {} Text
a -> CheckpointConfig
s {$sel:s3Uri:CheckpointConfig' :: Text
s3Uri = Text
a} :: CheckpointConfig)

instance Data.FromJSON CheckpointConfig where
  parseJSON :: Value -> Parser CheckpointConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CheckpointConfig"
      ( \Object
x ->
          Maybe Text -> Text -> CheckpointConfig
CheckpointConfig'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"LocalPath")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"S3Uri")
      )

instance Prelude.Hashable CheckpointConfig where
  hashWithSalt :: Int -> CheckpointConfig -> Int
hashWithSalt Int
_salt CheckpointConfig' {Maybe Text
Text
s3Uri :: Text
localPath :: Maybe Text
$sel:s3Uri:CheckpointConfig' :: CheckpointConfig -> Text
$sel:localPath:CheckpointConfig' :: CheckpointConfig -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
localPath
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
s3Uri

instance Prelude.NFData CheckpointConfig where
  rnf :: CheckpointConfig -> ()
rnf CheckpointConfig' {Maybe Text
Text
s3Uri :: Text
localPath :: Maybe Text
$sel:s3Uri:CheckpointConfig' :: CheckpointConfig -> Text
$sel:localPath:CheckpointConfig' :: CheckpointConfig -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
localPath
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
s3Uri

instance Data.ToJSON CheckpointConfig where
  toJSON :: CheckpointConfig -> Value
toJSON CheckpointConfig' {Maybe Text
Text
s3Uri :: Text
localPath :: Maybe Text
$sel:s3Uri:CheckpointConfig' :: CheckpointConfig -> Text
$sel:localPath:CheckpointConfig' :: CheckpointConfig -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"LocalPath" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
localPath,
            forall a. a -> Maybe a
Prelude.Just (Key
"S3Uri" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
s3Uri)
          ]
      )