Following this instruction :
1. Strictly adhere to PEP-8 standards, ensuring code is clean, well-structured, and follows Python's style guide for readability.
2. Use appropriate modules like `typing` for type hints, ensuring code clarity, maintainability, and leveraging Python's standard libraries effectively.
3. Focus on time, space, robustness, scalability; write optimized, efficient code that can handle large datasets and scale seamlessly.
4. Implement comprehensive error handling, catching exceptions gracefully, providing meaningful error messages, and ensuring code robustness under unexpected conditions.
5. Ensure the developer agent writes advanced, maintainable Python code, balancing performance and readability while adhering to best practices.


TASK : we have develop very algorithm from starch using torch module below develop all attack logic from scratch,  

Note : below user data given
#==========================================
from torchvision import transforms
import torch

from rldata import datapipeline,DatasetConfig
from rlmodel import ImageClassificationPipeline,ModelSource
from rlmetrics import MetricsCalculator
#dataset
config=DatasetConfig(
    dataset_path="zh-plus/tiny-imagenet",
    split_config={"train": 0.8, "test": 0.2},
    columns=["image","label"],
    num_samples=1000,
    seed=42,
    kwargs={"cache_dir": "./data_test",} 
)


trans = transforms.Compose([
    transforms.Lambda(lambda img: img.convert("RGB")),  # Convert to RGB first
    transforms.Resize((224, 224)),
    transforms.ToTensor(), 
    transforms.Normalize(mean=[0.485, 0.456, 0.406],  # Use three values for three channels
                       std=[0.229, 0.224, 0.225])
])

train_loader, test_loader=datapipeline(config=config,
             transforms_fn=trans,
             target_column="image",
             label_column="label")


model_pipeline=ImageClassificationPipeline(
    model_name_or_path="google/vit-base-patch16-224",
    model_source=ModelSource.TRANSFORMERS.value,

)
model=model_pipeline.model # loading model
def print_metrics(metrics: Dict[str, Any]):
    for metric, value in metrics.items():
        if isinstance(value, torch.Tensor):
            if value.numel() == 1:
                print(f"{metric}: {value.item()}")
            else:
                print(f"{metric}: {value.cpu().numpy()}")
        elif isinstance(value, float):
            print(f"{metric}: {value}")
        else:
            # Handle other possible types (e.g., None should have been removed)
            print(f"{metric}: {value}")
for batch in train_dataloader:
    images, labels = batch["images"], batch["labels"]
    model_output = model(images)  
    metrics_calc_multi = MetricsCalculator(preds=model_output.logits , labels=labels, num_classes=1000)
    metrics_multi = metrics_calc_multi.get_all_metrics()
    print("\nMulti-Class Classification Metrics:")
    print_metrics(metrics_multi)
#===========================================================================

now we have devlop below api  from starch (devlop below api in a single .py file)

str: 
adversarical:
label:

list_attack: List[str] = [
        'AdversarialPatch',
        'AutoProjectedGradientDescent',
        'AutoConjugateGradient', 
        'CompositeAdversarialAttackPyTorch',
        'CarliniL2Method',
        'CarliniLInfMethod',
        'DeepFool',
        'ElasticNet',
        'FastGradientMethod',
        'BasicIterativeMethod',
        'MomentumIterativeMethod',
        'NewtonFool',
        'PixelAttack',
        'ProjectedGradientDescent',
        'ProjectedGradientDescentPyTorch',
        'SpatialTransformation',
        'SquareAttack',
        'UniversalPerturbation',
        'Wasserstein',
        'ZooAttack',
    ]


I'll explain the key mathematical equations for each attack:

1. AdversarialPatch
```
patch_application = (1 - M) ⊙ x + M ⊙ p
where:
M = mask matrix
x = original image
p = adversarial patch
⊙ = element-wise multiplication
```

2. AutoProjectedGradientDescent (APGD)
```
x_{t+1} = Π(x_t - α_t∇L(x_t))
where:
Π = projection onto feasible set
α_t = step size at iteration t
L = loss function
```

3. AutoConjugateGradient
```
d_k = -∇f(x_k) + β_k d_{k-1}
x_{k+1} = x_k + α_k d_k
where:
β_k = Fletcher-Reeves formula
α_k = line search parameter
```

4. CarliniL2Method (C&W L2)
```
minimize ||δ||_2 + c⋅f(x+δ)
subject to x+δ ∈ [0,1]^n
where:
δ = perturbation
c = constant
f = objective function
```

5. CarliniLInfMethod
```
minimize ||δ||_∞ + c⋅f(x+δ)
subject to x+δ ∈ [0,1]^n
```

6. DeepFool
```
x_{i+1} = x_i + r_i
r_i = -(f(x_i)/||∇f(x_i)||_2^2)∇f(x_i)
where:
f = classifier function
r_i = perturbation at step i
```

7. ElasticNet
```
minimize ||δ||_2^2 + β||δ||_1 + c⋅f(x+δ)
subject to x+δ ∈ [0,1]^n
where:
β = L1 regularization parameter
```

8. FastGradientMethod (FGSM)
```
x_adv = x + ε⋅sign(∇_x J(θ,x,y))
where:
ε = perturbation magnitude
J = loss function
```

9. BasicIterativeMethod (BIM)
```
x_{t+1} = clip_ε(x_t + α⋅sign(∇_x J(θ,x_t,y)))
where:
α = step size
clip_ε = epsilon-neighborhood clipping
```

10. MomentumIterativeMethod
```
g_{t+1} = μ⋅g_t + ∇_x J(θ,x_t,y)/||∇_x J(θ,x_t,y)||_1
x_{t+1} = x_t + α⋅sign(g_{t+1})
where:
μ = momentum parameter
```

11. NewtonFool
```
x_{k+1} = x_k - (f(x_k)/||∇f(x_k)||_2^2)∇f(x_k)
```

12. PixelAttack
```
x_adv[i,j] = x[i,j] + δ[i,j]
where δ modifies limited pixels
```

13. ProjectedGradientDescent (PGD)
```
x_{t+1} = Π_ε(x_t + α⋅sign(∇_x J(θ,x_t,y)))
where:
Π_ε = projection onto ε-ball
```

14. SpatialTransformation
```
x_adv = T(x; θ)
where:
T = spatial transformation function
θ = transformation parameters
```

15. SquareAttack
```
x_adv = x + random_square_perturbation
subject to ||x_adv - x||_∞ ≤ ε
```

16. UniversalPerturbation
```
v = Σ δ_i
x_adv = x + v
subject to ||v||_p ≤ ε
where:
δ_i = individual perturbations
```

17. Wasserstein
```
minimize W(P_x, P_x_adv)
subject to ||x_adv - x||_p ≤ ε
where:
W = Wasserstein distance
P = probability distributions
```

18. ZooAttack
```
∇f(x) ≈ [f(x+hei) - f(x-hei)]/2h
x_{t+1} = x_t - η_t∇f(x_t)
where:
h = small constant
ei = standard basis vector
```

These equations represent the core mathematical principles behind each attack. Each method has additional implementation details and variations, but these are the fundamental formulations.