{"record":{"id":"d85ff6210655d5d5","repo":"Lightning-AI/pytorch-lightning","slug":"did-not-find-the-environment-variable-lsb-djob-ra","errorCode":null,"errorMessage":"Did not find the environment variable `LSB_DJOB_RANKFILE`","messagePattern":"Did not find the environment variable `LSB_DJOB_RANKFILE`","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/plugins/environments/lsf.py","lineNumber":164,"sourceCode":"        count: dict[str, int] = {}\n        for host in hosts:\n            if host not in count:\n                count[host] = len(count)\n        return count[socket.gethostname()]\n\n    @staticmethod\n    def _read_hosts() -> list[str]:\n        \"\"\"Read compute hosts that are a part of the compute job.\n\n        LSF uses the Job Step Manager (JSM) to manage job steps. Job steps are executed by the JSM from \"launch\" nodes.\n        Each job is assigned a launch node. This launch node will be the first node in the list contained in\n        ``LSB_DJOB_RANKFILE``.\n\n        \"\"\"\n        var = \"LSB_DJOB_RANKFILE\"\n        rankfile = os.environ.get(var)\n        if rankfile is None:\n            raise ValueError(\"Did not find the environment variable `LSB_DJOB_RANKFILE`\")\n        if not rankfile:\n            raise ValueError(\"The environment variable `LSB_DJOB_RANKFILE` is empty\")\n\n        fs = get_filesystem(rankfile)\n        with fs.open(rankfile, \"r\") as f:\n            ret = [line.strip() for line in f]\n        # remove the launch node (i.e. the first node in LSB_DJOB_RANKFILE) from the list\n        return ret[1:]\n\n    def _get_main_address(self) -> str:\n        \"\"\"A helper for getting the main address.\n\n        The main address is assigned to the first node in the list of nodes used for the job.\n\n        \"\"\"\n        hosts = self._read_hosts()\n        return hosts[0]\n","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/plugins/environments/lsf.py#L146-L182","documentation":"`LSFEnvironment._read_hosts` reads `LSB_DJOB_RANKFILE` (set by LSF's bsub/jsrun to a file listing host allocation order) to compute node rank and the main address. If the variable is not present in the environment, it raises this ValueError.","triggerScenarios":"Running with LSFEnvironment where `_get_node_rank` or `_get_main_address` is called but `LSB_DJOB_RANKFILE` is unset — process not submitted through bsub/jsrun, or a job context where LSF did not export the rankfile variable.","commonSituations":"Manual/interactive runs on LSF clusters outside bsub; scripts in containers that drop LSF env vars; porting LSF launch scripts between clusters where variable export differs.","solutions":["Submit the job through bsub/jsrun so LSF exports `LSB_DJOB_RANKFILE`: `bsub ... jsrun ... python train.py`","For non-LSF execution, switch to a matching cluster environment instead of LSFEnvironment","If manually emulating, export the variable pointing to a host file (each line a hostname)"],"exampleFix":"# before\npython train.py  # LSB_DJOB_RANKFILE unset\n\n# after\nbsub -Is jsrun -n 4 python train.py  # LSF exports LSB_DJOB_RANKFILE","handlingStrategy":"validation","validationCode":"import os\nassert os.environ.get('LSB_DJOB_RANKFILE'), 'submit via bsub/jsrun so LSF exports LSB_DJOB_RANKFILE'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Submit LSF jobs through bsub+jsrun","Ensure containers/wrappers propagate LSB_* environment variables"],"tags":["lsf","bsub","hpc","missing-env-var","distributed"],"backgroundTag":"missing-env-var","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}