GoogleCloudPlatform / PerfKitBenchmarker

PerfKit Benchmarker (PKB) contains a set of benchmarks to measure and compare cloud offerings. The benchmarks use default settings to reflect what most users will see. PerfKit Benchmarker is licensed under the Apache 2 license terms. Please make sure to read, understand and agree to the terms of the LICENSE and CONTRIBUTING files before proceeding.
https://googlecloudplatform.github.io/PerfKitBenchmarker/
Apache License 2.0
1.91k stars 512 forks source link

Add more type annotations in PKB #5236

Open jellyfishcake opened 1 month ago

jellyfishcake commented 1 month ago

Add more type annotations to almost any file in PKB. Python is by default untyped, but optional type annotations add clarity & help detect errors.

Some files like https://github.com/GoogleCloudPlatform/PerfKitBenchmarker/blob/master/perfkitbenchmarker/providers/gcp/vertex_ai.py already have type annotations. Many have some annotations but are also missing some.

See https://docs.python.org/3/library/typing.html for more information & examples of type annotations.

After adding type annotations, use pytype to check if annotations are correct or break anything. See here for install instructions:

https://github.com/google/pytype

But the short version is

pip install pytype pytype _file.py

will output if the file has any errors after adding the type annotations

Some classes could also use attribute lists like:

class VertexAiModelSpec(managed_ai_model_spec.BaseManagedAiModelSpec): """Spec for a Vertex AI model.

Attributes: env_vars: Environment variables set on the node. serving_container_command: Command run on container to start the model. serving_container_args: The arguments passed to container create. """

def init(): self.container_image_uri: str self.model_bucket_suffix: str self.serving_container_command: list[str]

ronaksingh27 commented 1 month ago

@jellyfishcake Could you please assign me this issue? I'd also appreciate any insights or suggestions on where I should start

jellyfishcake commented 1 month ago

@jellyfishcake Could you please assign me this issue? I'd also appreciate any insights or suggestions on where I should start

Assigned. I just start with the /linux_benchmark files or /linux_packages files.

ronaksingh27 commented 1 month ago

@jellyfishcake I am currently working on adding type annotations for the aerospike_benchmarks.py file in the Linux benchmarks. However, I am having difficulty with the type annotation for user_config. Could you please assist me with this?

ronaksingh27 commented 1 month ago

@jellyfishcake How do i build the intuition that this parameter would have this type annotation ?

ronaksingh27 commented 1 month ago

@jellyfishcake How do i build the intuition that this parameter would have this type annotation ? @jellyfishcake I did find that certain files already have thefunction with the type annotationslike

cuda_memcpy_benchmark.py already had , so i applied them to aerospike_benchmark.py , is that all right ?

ronaksingh27 commented 1 month ago

@jellyfishcake I am currently working on adding type annotations for the aerospike_benchmarks.py file in the Linux benchmarks. However, I am having difficulty with the type annotation for user_config. Could you please assist me with this?

well i got this from the same cuda_memcpy_benchamark.py file :)

ronaksingh27 commented 1 month ago

@jellyfishcake I had the file aerospike_benchmark.py updated and raised the Pull Request , could please provide feedback, Thanks for the response earlier for suggesting where to start from , it helped a lot