def generate_runs(self):
        c = self.config
        # Create output directory
        if self.target_dir:
            out_dir = os.path.join(self.target_dir, c.parallel.name)
        else:
            out_dir = c.parallel.name
        os.makedirs(out_dir)
        os.makedirs(os.path.join(out_dir, 'Runs'))
        os.makedirs(os.path.join(out_dir, 'Logs'))
        iterations = self.generate_iterations()
        # Save relevant settings in out_dir,
        # to figure out what all the numbers mean!
        os.makedirs(os.path.join(out_dir, 'Output'))
        iterations.to_csv(os.path.join(out_dir, 'Output', 'iterations.csv'))
        parallel_f = os.path.join(out_dir, 'Output', 'parallel_settings.yaml')
        c.parallel.to_yaml(parallel_f)

        # Decide whether to generate a single or multiple submission files
        # If different iterations ask for different resources, multiple
        # files are necessary
        c.set_key('parallel.style', 'array')  # Try setting 'array' as default
        # Flatten list of iteration keys, check if parallel.resources defined
        # anywhere in the list, if so, replace 'array' with 'single', since
        # we need each iteration's run script to be able to set its resources
        iteration_keys = [d.keys_nested() for d in c.parallel.iterations]
        for i in itertools.chain.from_iterable(iteration_keys):
            if i in 'parallel.resources':
                c.set_key('parallel.style', 'single')
                break

        #
        # COMBINE ALL MODEL CONFIG INTO ONE FILE AND WRITE IT TO `out_dir`
        #
        data_path_adj = c.get_key('parallel.data_path_adjustment', None)
        o = core.get_model_config(c, self.config_file,
                                  adjust_data_path=data_path_adj,
                                  insert_defaults=False)
        unified_config_file = os.path.join(out_dir, 'Runs', 'model.yaml')
        o.to_yaml(os.path.join(unified_config_file))
        c.model = 'model.yaml'
        # Always make sure we are saving outputs from iterations!
        c.set_key('output.save', True)

        #
        # SET UP SUBMISSION SCRIPT FOR ARRAY RUNS
        #
        if c.parallel.style == 'array':
            # Write array submission script
            submit_file = os.path.join(out_dir, self.f_submit.format('array'))
            with open(submit_file, 'w') as f:
                self._write_submit(f, n_iter=len(iterations))
            os.chmod(submit_file, 0o755)

        #
        # SET UP RUN SCRIPT AND SUBMISSION SCRIPTS FOR SINGLE RUNS
        #
        run_file = os.path.join(out_dir, self.f_run)
        with open(run_file, 'w') as f:
            f.write('#!/bin/sh\n')
            f.write('case "$1" in\n\n')
        for iter_id, iter_row in iterations.iterrows():
            index_str = '{:0>4d}'.format(iter_id)
            iter_c = self._get_iteration_config(c, index_str, iter_row)
            settings_file = 'settings_{}.yaml'.format(index_str)

            # Write run script entry
            with open(os.path.join(out_dir, self.f_run), 'a') as f:
                f.write('{}) '.format(iter_id))
                if c.get_key('parallel.pre_run', default=False):
                    self._write_additional_lines(f, c.parallel.pre_run)
                self._write_modelcommands(f, settings_file)
                if c.get_key('parallel.post_run', default=False):
                    self._write_additional_lines(f, c.parallel.post_run,
                                                 formats={'id': iter_id})
                f.write(';;\n\n')

            # If style is single, also write a single submission script
            if c.parallel.style == 'single':
                # Write model run script
                submit_file = os.path.join(out_dir,
                                           self.f_submit.format(index_str))
                with open(submit_file, 'w') as f:
                    self._write_submit(f, n_iter=iter_id, config=iter_c)
                os.chmod(submit_file, 0o755)

            # Write configuration object to YAML file
            del iter_c.parallel  # parallel settings not needed in each file
            iter_c.to_yaml(os.path.join(out_dir, 'Runs', settings_file))

        # Final tasks after going through all iterations
        with open(run_file, 'a') as f:
            f.write('esac\n')
        os.chmod(run_file, 0o755)
dataset/ETHPy150Open calliope-project/calliope/calliope/parallel.py/Parallelizer.generate_runs/swapped operands of `in`