Repository: ray-project/ray
File: python/ray/_private/resource_isolation_config.py (Python)

Code before:
            if self.cgroup_path:
                raise ValueError(
                    "cgroup_path cannot be set when resource isolation is not enabled. "
                    "Set enable_resource_isolation to True if you're using ray.init or use the "
                    "--enable-resource-isolation flag if you're using the ray cli."
                )
            if system_reserved_cpu:
                raise ValueError(
                    "system_reserved_cpu cannot be set when resource isolation is not enabled. "
                    "Set enable_resource_isolation to True if you're using ray.init or use the "
                    "--enable-resource-isolation flag if you're using the ray cli."
                )

            if self.system_reserved_memory:
                raise ValueError(
                    "system_reserved_memory cannot be set when resource isolation is not enabled. "
                    "Set enable_resource_isolation to True if you're using ray.init or use the "
                    "--enable-resource-isolation flag if you're using the ray cli."
                )
            return

        if object_store_memory is None:
            raise ValueError(
                "object_store_memory must be resolved before creating a ResourceIsolationConfig."
                "when resource isolation is enabled."
            )

        self.system_reserved_cpu_weight = self._validate_and_get_system_reserved_cpu(
            system_reserved_cpu
        )

        self.system_reserved_memory = self._validate_and_get_system_reserved_memory(
            system_reserved_memory, object_store_memory
        )

        self.cgroup_path = self._validate_and_get_cgroup_path(cgroup_path)

    def is_enabled(self) -> bool:
        return self._resource_isolation_enabled

    def add_system_pids(self, system_pids: str):
        """A comma-separated list of pids to move into the system cgroup."""
        self.system_pids = system_pids

    @staticmethod
    def _validate_and_get_cgroup_path(cgroup_path: Optional[str]) -> str:
        """Returns the ray_constants.DEFAULT_CGROUP_PATH if cgroup_path is not specified.

        Args:
            cgroup_path: The path for the cgroup the raylet should use to enforce
                resource isolation.

Review comment (bug):
This is probably a bug in our code instead of invalid arguments from the user. If that's true, maybe we should ask the user to file an issue. 

```suggestion
        if object_store_memory is None:
            raise ValueError(
                "object_store_memory must be resolved before creating a ResourceIsolationConfig "
                "when resource isolation is enabled."
            )
```

Code after:
                raise ValueError(
                    "cgroup_path cannot be set when resource isolation is not enabled. "
                    "Set enable_resource_isolation to True if you're using ray.init or use the "
                    "--enable-resource-isolation flag if you're using the ray cli."
                )
            if system_reserved_cpu:
                raise ValueError(
                    "system_reserved_cpu cannot be set when resource isolation is not enabled. "
                    "Set enable_resource_isolation to True if you're using ray.init or use the "
                    "--enable-resource-isolation flag if you're using the ray cli."
                )

            if self.system_reserved_memory:
                raise ValueError(
                    "system_reserved_memory cannot be set when resource isolation is not enabled. "
                    "Set enable_resource_isolation to True if you're using ray.init or use the "
                    "--enable-resource-isolation flag if you're using the ray cli."
                )
            return

        if object_store_memory is None:
            raise ValueError(
                "object_store_memory must be resolved before creating a ResourceIsolationConfig "
                "when resource isolation is enabled. This is likely a bug in Ray, "
                "please report it at https://github.com/ray-project/ray/issues/new/choose."
            )

        self.system_reserved_cpu_weight = self._validate_and_get_system_reserved_cpu(
            system_reserved_cpu
        )

        self.system_reserved_memory = self._validate_and_get_system_reserved_memory(
            system_reserved_memory, object_store_memory
        )

        self.cgroup_path = self._validate_and_get_cgroup_path(cgroup_path)

    def is_enabled(self) -> bool:
        return self._resource_isolation_enabled

    def add_system_pids(self, system_pids: str):
        """A comma-separated list of pids to move into the system cgroup."""
        self.system_pids = system_pids

    @staticmethod
    def _validate_and_get_cgroup_path(cgroup_path: Optional[str]) -> str:
        """Returns the ray_constants.DEFAULT_CGROUP_PATH if cgroup_path is not specified.

        Args:
            cgroup_path: The path for the cgroup the raylet should use to enforce
                resource isolation.