SnakeBridge.Lock (SnakeBridge v0.15.0)

Copy Markdown View Source

Manages snakebridge.lock with runtime identity, hardware info, and library versions.

The lock file captures:

  • Hardware identity (accelerator, CUDA version, CPU features)
  • Platform information (OS, architecture)
  • Python environment (version, packages)
  • Library configurations

Hardware-Aware Lock Files

The lock file includes hardware information to detect compatibility issues:

%{
  "environment" => %{
    "hardware" => %{
      "accelerator" => "cuda",
      "cuda_version" => "12.1",
      "gpu_count" => 2,
      "cpu_features" => ["avx", "avx2"]
    },
    "platform" => %{
      "os" => "linux",
      "arch" => "x86_64"
    }
  }
}

Use SnakeBridge.Lock.Verifier to verify compatibility.

Summary

Functions

Builds the compatibility section with minimum requirements.

Builds the hardware section for the lock file.

Builds the platform section for the lock file.

Deterministic hash from sorted package versions.

Computes the generator hash from generator and adapter source contents.

Gets package metadata for the lockfile.

Checks if the lock was generated with the current generator version.

Functions

build(config)

@spec build(SnakeBridge.Config.t()) :: map()

build_compatibility_section(hardware)

@spec build_compatibility_section(map()) :: map()

Builds the compatibility section with minimum requirements.

build_hardware_section()

@spec build_hardware_section() :: map()

Builds the hardware section for the lock file.

Returns a map with hardware identity including accelerator type, CUDA version if available, GPU count, and CPU features.

build_platform_section()

@spec build_platform_section() :: map()

Builds the platform section for the lock file.

compute_packages_hash(packages)

@spec compute_packages_hash(map()) :: String.t()

Deterministic hash from sorted package versions.

generator_hash()

@spec generator_hash() :: String.t()

Computes the generator hash from generator and adapter source contents.

get_package_metadata(config)

@spec get_package_metadata(SnakeBridge.Config.t()) :: map()

Gets package metadata for the lockfile.

load()

@spec load() :: map() | nil

update(config)

@spec update(SnakeBridge.Config.t()) :: :ok

verify_generator_unchanged?(lock)

@spec verify_generator_unchanged?(map()) :: boolean()

Checks if the lock was generated with the current generator version.

write(lock)

@spec write(map()) :: :ok