sweagent.run.batch_instances.SimpleBatchInstance

Bases: BaseModel

A simple way to configure a single instance in a batch of instances that all use similar deployment configurations. We added traj_id to support multiple rollouts per instance.

Source code in SWE-agent/sweagent/run/batch_instances.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
class SimpleBatchInstance(BaseModel):
    """A simple way to configure a single instance in a batch of instances that all
    use similar deployment configurations.
    We added traj_id to support multiple rollouts per instance.
    """
    global_step: int = -1
    repo_type : str
    """Type of the repository. Can be 'github', 'local', or '' (empty string for pre-existing)."""
    ds : Any
    """One item from the dataset."""
    image_name: str
    problem_statement: str
    instance_id: str
    """Unique identifier of the instance. Used for logging and environment naming."""
    traj_id: str
    """Unique identifier of the trajectory. Necessary when multiple rollouts are performed per instance."""
    repo_name: str = ""
    """Specifies the repository name to use.
    For `github` repo_type, this is the git folder name.
    For `local` repo_type, this is the local path to the repo.
    For pre-existing repo_type, this is the name of the pre-existing repo. 
    """
    base_commit: str = "HEAD"
    """Used to reset repo."""
    extra_fields: dict[str, Any] = Field(default_factory=dict)
    """Any additional data to be added to the instance.
    This data will be available when formatting prompt templates.
    """

    # Ignore instead of allow because they should be added as `extra_fields`
    model_config = ConfigDict(extra="ignore")

    def to_full_batch_instance(self, deployment: DeploymentConfig) -> BatchInstance:
        """Merge the deployment options into the `SimpleBatchInstance` object to get a full `BatchInstance`.
        We use our GithubRepoRetryConfig instead of GithubRepoConfig.
        """
        # Very important: Make a copy of the deployment config because it will be shared among instances!!!
        deployment = deployment.model_copy(deep=True)

        if "issue_images" in self.extra_fields:
            problem_statement = SWEBenchMultimodalProblemStatement(
                text=self.problem_statement,
                issue_images=self.extra_fields.pop("issue_images"),
                id=self.instance_id,
                extra_fields=self.extra_fields,
            )
        else:
            problem_statement = TextProblemStatement(
                text=self.problem_statement, id=self.traj_id, extra_fields=self.extra_fields
            )

        if not self.repo_name:
            repo = None

        if self.repo_type == "github":
            repo = GithubRepoRetryConfig(git_folder=self.repo_name, base_commit=self.base_commit,github_url=self.ds['repo'])
        elif self.repo_type == "local":
            repo = LocalRepoConfig(path=Path(self.repo_name), base_commit=self.base_commit)
        else:
            repo = PreExistingRepoConfig(repo_name=self.repo_name, base_commit=self.base_commit)
        if isinstance(deployment, LocalDeploymentConfig):
            if self.image_name:
                msg = "Local deployment does not support image_name"
                raise ValueError(msg)
            return BatchInstance(
                ds=self.ds,
                env=EnvironmentConfig(deployment=deployment, repo=repo), problem_statement=problem_statement
            )
        if isinstance(deployment, DummyDeploymentConfig):
            return BatchInstance(
                ds=self.ds,
                env=EnvironmentConfig(deployment=deployment, repo=repo), problem_statement=problem_statement
            )

        deployment.image = self.image_name  # type: ignore

        if isinstance(deployment, DockerDeploymentConfig) and deployment.python_standalone_dir is None:
            # Note: you can disable this by setting python_standalone_dir to ""
            # deployment.python_standalone_dir = "/root"  # type: ignore
            pass
        return BatchInstance(
            ds=self.ds,
            env=EnvironmentConfig(deployment=deployment, repo=repo), problem_statement=problem_statement
        )


    @model_validator(mode="before")
    @classmethod
    def handle_legacy_id(cls, data):
        # Handling compatibility with swe-agent <= 1.0.1
        if isinstance(data, dict):
            if "id" in data and "instance_id" not in data:
                data["instance_id"] = data["id"]
                data.pop("id")
        return data

    # todo: Maybe populate extra fields?
    @classmethod
    def from_swe_bench(cls, instance: dict[str, Any]) -> Self:
        """Convert instances from the classical SWE-bench dataset to the `SimpleBatchInstance` format.

        Attributes:
            instance: A dictionary representing a single instance from the SWE-bench dataset.
        """
        iid = instance["instance_id"]
        image_name = instance.get("image_name", None)
        if image_name is None:
            # Docker doesn't allow double underscore, so we replace them with a magic token
            id_docker_compatible = iid.replace("__", "_1776_")
            image_name = f"docker.io/swebench/sweb.eval.x86_64.{id_docker_compatible}:latest".lower()
            iid_image_name=f"docker.io/swebench/sweb.eval.x86_64.{id_docker_compatible}".lower()
            instance['image_name']=iid_image_name
        extra_fields = {}
        if "image_assets" in instance:
            issue_images = json.loads(instance["image_assets"])["problem_statement"]
            extra_fields["issue_images"] = issue_images

        return cls(
            repo_type=instance.get("repo_type",'github'),
            ds=instance,
            image_name=image_name,
            problem_statement=instance["problem_statement"],
            instance_id=iid,
            traj_id=instance.get("traj_id", iid),
            repo_name="testbed",
            base_commit=instance.get("base_commit",'main'),
            extra_fields=extra_fields,
        )

base_commit class-attribute instance-attribute

base_commit = 'HEAD'

Used to reset repo.

ds instance-attribute

ds

One item from the dataset.

extra_fields class-attribute instance-attribute

extra_fields = Field(default_factory=dict)

Any additional data to be added to the instance. This data will be available when formatting prompt templates.

instance_id instance-attribute

instance_id

Unique identifier of the instance. Used for logging and environment naming.

repo_name class-attribute instance-attribute

repo_name = ''

Specifies the repository name to use. For github repo_type, this is the git folder name. For local repo_type, this is the local path to the repo. For pre-existing repo_type, this is the name of the pre-existing repo.

repo_type instance-attribute

repo_type

Type of the repository. Can be 'github', 'local', or '' (empty string for pre-existing).

traj_id instance-attribute

traj_id

Unique identifier of the trajectory. Necessary when multiple rollouts are performed per instance.

from_swe_bench classmethod

from_swe_bench(instance)

Convert instances from the classical SWE-bench dataset to the SimpleBatchInstance format.

Attributes:
  • instance

    A dictionary representing a single instance from the SWE-bench dataset.

Source code in SWE-agent/sweagent/run/batch_instances.py
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
@classmethod
def from_swe_bench(cls, instance: dict[str, Any]) -> Self:
    """Convert instances from the classical SWE-bench dataset to the `SimpleBatchInstance` format.

    Attributes:
        instance: A dictionary representing a single instance from the SWE-bench dataset.
    """
    iid = instance["instance_id"]
    image_name = instance.get("image_name", None)
    if image_name is None:
        # Docker doesn't allow double underscore, so we replace them with a magic token
        id_docker_compatible = iid.replace("__", "_1776_")
        image_name = f"docker.io/swebench/sweb.eval.x86_64.{id_docker_compatible}:latest".lower()
        iid_image_name=f"docker.io/swebench/sweb.eval.x86_64.{id_docker_compatible}".lower()
        instance['image_name']=iid_image_name
    extra_fields = {}
    if "image_assets" in instance:
        issue_images = json.loads(instance["image_assets"])["problem_statement"]
        extra_fields["issue_images"] = issue_images

    return cls(
        repo_type=instance.get("repo_type",'github'),
        ds=instance,
        image_name=image_name,
        problem_statement=instance["problem_statement"],
        instance_id=iid,
        traj_id=instance.get("traj_id", iid),
        repo_name="testbed",
        base_commit=instance.get("base_commit",'main'),
        extra_fields=extra_fields,
    )

to_full_batch_instance

to_full_batch_instance(deployment)

Merge the deployment options into the SimpleBatchInstance object to get a full BatchInstance. We use our GithubRepoRetryConfig instead of GithubRepoConfig.

Source code in SWE-agent/sweagent/run/batch_instances.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
def to_full_batch_instance(self, deployment: DeploymentConfig) -> BatchInstance:
    """Merge the deployment options into the `SimpleBatchInstance` object to get a full `BatchInstance`.
    We use our GithubRepoRetryConfig instead of GithubRepoConfig.
    """
    # Very important: Make a copy of the deployment config because it will be shared among instances!!!
    deployment = deployment.model_copy(deep=True)

    if "issue_images" in self.extra_fields:
        problem_statement = SWEBenchMultimodalProblemStatement(
            text=self.problem_statement,
            issue_images=self.extra_fields.pop("issue_images"),
            id=self.instance_id,
            extra_fields=self.extra_fields,
        )
    else:
        problem_statement = TextProblemStatement(
            text=self.problem_statement, id=self.traj_id, extra_fields=self.extra_fields
        )

    if not self.repo_name:
        repo = None

    if self.repo_type == "github":
        repo = GithubRepoRetryConfig(git_folder=self.repo_name, base_commit=self.base_commit,github_url=self.ds['repo'])
    elif self.repo_type == "local":
        repo = LocalRepoConfig(path=Path(self.repo_name), base_commit=self.base_commit)
    else:
        repo = PreExistingRepoConfig(repo_name=self.repo_name, base_commit=self.base_commit)
    if isinstance(deployment, LocalDeploymentConfig):
        if self.image_name:
            msg = "Local deployment does not support image_name"
            raise ValueError(msg)
        return BatchInstance(
            ds=self.ds,
            env=EnvironmentConfig(deployment=deployment, repo=repo), problem_statement=problem_statement
        )
    if isinstance(deployment, DummyDeploymentConfig):
        return BatchInstance(
            ds=self.ds,
            env=EnvironmentConfig(deployment=deployment, repo=repo), problem_statement=problem_statement
        )

    deployment.image = self.image_name  # type: ignore

    if isinstance(deployment, DockerDeploymentConfig) and deployment.python_standalone_dir is None:
        # Note: you can disable this by setting python_standalone_dir to ""
        # deployment.python_standalone_dir = "/root"  # type: ignore
        pass
    return BatchInstance(
        ds=self.ds,
        env=EnvironmentConfig(deployment=deployment, repo=repo), problem_statement=problem_statement
    )

sweagent.run.batch_instances.SWEBenchInstances

Bases: BaseModel, AbstractInstanceSource

Load instances from SWE-bench.

Source code in SWE-agent/sweagent/run/batch_instances.py
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
class SWEBenchInstances(BaseModel, AbstractInstanceSource):
    """Load instances from SWE-bench."""
    repo_type: str = 'github'
    """Type of repository to use. Options include 'github', 'local', and 'preexisting'."""
    database: str="/home/zeta/ais_default_code_config_repo_507090/datasets"
    """Path to the local SWE-bench database."""
    start: int =0
    """Start index of instances to load."""
    end: int =500
    """End index of instances to load."""
    subset: Literal["lite", "verified", "full", "multimodal", "multilingual"] = "lite"
    """Subset of swe-bench to use"""

    # IMPORTANT: Do not call this `path`, because then if people do not specify instance.type,
    # it might be resolved to ExpertInstancesFromFile or something like that.
    # path_override: str | Path | None = None
    # """Allow to specify a different huggingface dataset name or path to a huggingface
    # dataset. This will override the automatic path set by `subset`.
    # """
    model_patch_file: str =None
    """Path to a json file containing model patches for the instances. Used for 
    MiniSandbox evaluation with patches."""

    split: str='test'

    deployment: DeploymentConfig = Field(
        default_factory=lambda: SandboxDeploymentConfig(),
    )


    type: Literal["swe_bench"] = "swe_bench"
    """Discriminator for (de)serialization/CLI. Do not change."""

    filter: str = ".*"
    """Regular expression to filter the instances by instance id."""
    slice: str = ""
    """Select only a slice of the instances (after filtering by `filter`).
    Possible values are stop or start:stop or start:stop:step.
    (i.e., it behaves exactly like python's list slicing `list[slice]`).
    """
    shuffle: bool = False
    """Shuffle the instances (before filtering and slicing)."""

    evaluate: bool = False
    """Run sb-cli to evaluate"""

    def _get_dataset_path(self) -> str:
        # if self.path_override is not None:
        #     return str(self.path_override)
        # dataset_mapping = {
        #     "full": "princeton-nlp/SWE-Bench",
        #     "verified": f"/home/zeta/ais_default_code_config_repo_507090/datasets/SWE-bench_Verified/data",
        #     "lite": "princeton-nlp/SWE-Bench_Lite",
        #     "multimodal": "princeton-nlp/SWE-Bench_Multimodal",
        #     "multilingual": "swe-bench/SWE-Bench_Multilingual",
        # }

        # if self.subset not in dataset_mapping:
        #     msg = f"Unsupported subset: {self.subset}"
        #     raise ValueError(msg)

        return self.database
    def get_instance_configs_ds(self,dataset) -> list[BatchInstance]:
        pass
    def get_instance_configs(self) -> list[BatchInstance]:
        """Load instances from SWE-bench dataset. This function is used for run_batch.py"""
        from datasets import load_dataset

        ds: list[dict[str, Any]] = load_dataset(self._get_dataset_path(), split=self.split).shuffle(42).select(range(self.start,self.end))  # type: ignore


        """
        test patches is json like below:
            {
        "sympy__sympy-19954": {
            "reward": null,
            "test_out": null,
            "p2p": null,
            "f2p": null,
            "model_name_or_path": "out-qwen2.5-3Bcoder-docker5k",
            "instance_id": "sympy__sympy-19954",
            "model_patch": "diff --git a/reproduce_error.py b/reproduce_error.py\nnew file mode 100644\nindex 0000000000..52decb4042\n--- /dev/null\n+++ b/reproduce_error.py\n@@ -0,0 +1,11 @@\n+from sympy.combinatorics import DihedralGroup, Permutation\n+\n+G = DihedralGroup(18)\n+\n+S2 = G.sylow_subgroup(p=2)\n+print(\"S2 order:\", S2.order())\n+\n+# Try with a larger group\n+G2 = DihedralGroup(2*25)\n+S2_large = G2.sylow_subgroup(p=2)\n+print(\"S2_large order:\", S2_large.order())\n\\ No newline at end of file\ndiff --git a/sympy/combinatorics/perm_groups.py b/sympy/combinatorics/perm_groups.py\nindex de94ddabb4..ddc9c06ad5 100644\n--- a/sympy/combinatorics/perm_groups.py\n+++ b/sympy/combinatorics/perm_groups.py\n@@ -2200,6 +2200,9 @@ def _number_blocks(blocks):\n                         # i-th block system is not minimal\n                         del num_blocks[i], blocks[i]\n                         to_remove.append(rep_blocks[i])\n+                        # After deletion, we need to adjust the indices\n+                        # because we removed elements from both lists\n+                        break\n                     elif len(r) < len(rep) and r.issubset(rep):\n                         # the system being checked is not minimal\n                         minimal = False\n"
        },
        "django__django-13821": {
            "reward": null,
            "test_out": null,
            "p2p": null,
            "f2p": null,
            "model_name_or_path": "out-qwen2.5-3Bcoder-docker5k",
            "instance_id": "django__django-13821",
            "model_patch": ""
        },
        """

        import json
        if self.model_patch_file is not None:
            new_ds=[]
            with open(self.model_patch_file,'r') as f:
                test_patches = json.load(f)
            for i in range(len(ds)):
                instance_id = ds[i]['instance_id']
                d={}
                for key in ds[i]:
                    d[key]=ds[i][key]

                if instance_id in test_patches:
                    d['patch'] = test_patches[instance_id]['model_patch']
                else:
                    d['patch'] = ''
                new_ds.append(d)
            ds=new_ds

        instances = [
            SimpleBatchInstance.from_swe_bench({**instance, 'repo_type': self.repo_type}).to_full_batch_instance(self.deployment) for instance in ds
        ]
        return _filter_batch_items(instances, filter_=self.filter, slice_=self.slice, shuffle=self.shuffle)

    @property
    def id(self) -> str:
        return f"swe_bench_{self.subset}_{self.split}"

database class-attribute instance-attribute

database = '/home/zeta/ais_default_code_config_repo_507090/datasets'

Path to the local SWE-bench database.

end class-attribute instance-attribute

end = 500

End index of instances to load.

evaluate class-attribute instance-attribute

evaluate = False

Run sb-cli to evaluate

filter class-attribute instance-attribute

filter = '.*'

Regular expression to filter the instances by instance id.

model_patch_file class-attribute instance-attribute

model_patch_file = None

Path to a json file containing model patches for the instances. Used for MiniSandbox evaluation with patches.

repo_type class-attribute instance-attribute

repo_type = 'github'

Type of repository to use. Options include 'github', 'local', and 'preexisting'.

shuffle class-attribute instance-attribute

shuffle = False

Shuffle the instances (before filtering and slicing).

slice class-attribute instance-attribute

slice = ''

Select only a slice of the instances (after filtering by filter). Possible values are stop or start:stop or start:stop:step. (i.e., it behaves exactly like python's list slicing list[slice]).

start class-attribute instance-attribute

start = 0

Start index of instances to load.

subset class-attribute instance-attribute

subset = 'lite'

Subset of swe-bench to use

type class-attribute instance-attribute

type = 'swe_bench'

Discriminator for (de)serialization/CLI. Do not change.

get_instance_configs

get_instance_configs()

Load instances from SWE-bench dataset. This function is used for run_batch.py

Source code in SWE-agent/sweagent/run/batch_instances.py
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
def get_instance_configs(self) -> list[BatchInstance]:
    """Load instances from SWE-bench dataset. This function is used for run_batch.py"""
    from datasets import load_dataset

    ds: list[dict[str, Any]] = load_dataset(self._get_dataset_path(), split=self.split).shuffle(42).select(range(self.start,self.end))  # type: ignore


    """
    test patches is json like below:
        {
    "sympy__sympy-19954": {
        "reward": null,
        "test_out": null,
        "p2p": null,
        "f2p": null,
        "model_name_or_path": "out-qwen2.5-3Bcoder-docker5k",
        "instance_id": "sympy__sympy-19954",
        "model_patch": "diff --git a/reproduce_error.py b/reproduce_error.py\nnew file mode 100644\nindex 0000000000..52decb4042\n--- /dev/null\n+++ b/reproduce_error.py\n@@ -0,0 +1,11 @@\n+from sympy.combinatorics import DihedralGroup, Permutation\n+\n+G = DihedralGroup(18)\n+\n+S2 = G.sylow_subgroup(p=2)\n+print(\"S2 order:\", S2.order())\n+\n+# Try with a larger group\n+G2 = DihedralGroup(2*25)\n+S2_large = G2.sylow_subgroup(p=2)\n+print(\"S2_large order:\", S2_large.order())\n\\ No newline at end of file\ndiff --git a/sympy/combinatorics/perm_groups.py b/sympy/combinatorics/perm_groups.py\nindex de94ddabb4..ddc9c06ad5 100644\n--- a/sympy/combinatorics/perm_groups.py\n+++ b/sympy/combinatorics/perm_groups.py\n@@ -2200,6 +2200,9 @@ def _number_blocks(blocks):\n                         # i-th block system is not minimal\n                         del num_blocks[i], blocks[i]\n                         to_remove.append(rep_blocks[i])\n+                        # After deletion, we need to adjust the indices\n+                        # because we removed elements from both lists\n+                        break\n                     elif len(r) < len(rep) and r.issubset(rep):\n                         # the system being checked is not minimal\n                         minimal = False\n"
    },
    "django__django-13821": {
        "reward": null,
        "test_out": null,
        "p2p": null,
        "f2p": null,
        "model_name_or_path": "out-qwen2.5-3Bcoder-docker5k",
        "instance_id": "django__django-13821",
        "model_patch": ""
    },
    """

    import json
    if self.model_patch_file is not None:
        new_ds=[]
        with open(self.model_patch_file,'r') as f:
            test_patches = json.load(f)
        for i in range(len(ds)):
            instance_id = ds[i]['instance_id']
            d={}
            for key in ds[i]:
                d[key]=ds[i][key]

            if instance_id in test_patches:
                d['patch'] = test_patches[instance_id]['model_patch']
            else:
                d['patch'] = ''
            new_ds.append(d)
        ds=new_ds

    instances = [
        SimpleBatchInstance.from_swe_bench({**instance, 'repo_type': self.repo_type}).to_full_batch_instance(self.deployment) for instance in ds
    ]
    return _filter_batch_items(instances, filter_=self.filter, slice_=self.slice, shuffle=self.shuffle)

sweagent.run.batch_instances.SWESmithInstances

Bases: BaseModel, AbstractInstanceSource

Load instances from SWE-smith.

Source code in SWE-agent/sweagent/run/batch_instances.py
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
class SWESmithInstances(BaseModel, AbstractInstanceSource):
    """Load instances from SWE-smith."""


    repo_type: str = 'github'
    """Type of the repository. Can be 'github', 'local', or anything else for pre-existing repositories.
    If the repo_type is 'github', we will use git fetch to get the code from the specified repo and base_commit in the instance config.
    If the repo_type is 'local', we do not support yet
    If the repo_type is anything else (e.g., 'preexisting'), we will assume that the code is already present in the deployment and do not perform any operations. The instance config should still specify the repo_name and base_commit for resetting the repo to the correct state.
    """
    load_from_disk: bool=False
    """Whether to load the dataset from local disk using `load_from_disk`."""
    num_rollouts_per_instance: int=-1
    """Number of rollouts to perform per instance. If >1, the instances will be duplicated accordingly."""
    start: int=0
    """Start index of instances to load."""
    end: int=500
    """End index of instances to load."""
    path: str
    """Name or path of the dataset."""
    split: str
    """Split of the dataset to load."""
    deployment: DeploymentConfig = Field(
        default_factory=lambda: SandboxDeploymentConfig(),
    )


    filter: str = ".*"
    """Regular expression to filter the instances by instance id."""
    slice: str = ""
    """Select only a slice of the instances (after filtering by `filter`).
    Possible values are stop or start:stop or start:stop:step.
    (i.e., it behaves exactly like python's list slicing `list[slice]`).
    """
    shuffle: bool = False
    """Shuffle the instances (before filtering and slicing)."""

    type: Literal["swesmith"] = "swesmith"
    """Discriminator for (de)serialization/CLI. Do not change."""
    def get_instance_configs_ds(self,dataset) -> list[BatchInstance]:
        pass
    def get_instance_configs(self) -> list[BatchInstance]:
        """Load instances from SWE-smith dataset. This function is used for run_batch.py
        It duplicates instances if num_rollouts_per_instance>1.
        """
        num_rollouts_per_instance = self.num_rollouts_per_instance
        def convert_instance_dict(instance_dict) -> dict[str, Any]:
            instance_dict['repo_type'] = self.repo_type
            instance_dict["id"] = instance_dict["instance_id"]
            # todo: The base_commit is currently incorrect
            instance_dict["traj_id"] = instance_dict.get("traj_id", instance_dict["instance_id"])
            instance_dict["base_commit"] = instance_dict["id"] if "base_commit" not in instance_dict else instance_dict["base_commit"]
            instance_dict["problem_statement"] = instance_dict.get("problem_statement", "")
            instance_dict["repo_name"] = "testbed"
            instance_dict["extra_fields"] = {"fail_to_pass": instance_dict["FAIL_TO_PASS"]}
            instance_dict['ds']=instance_dict
            return instance_dict
        from datasets import load_dataset,load_from_disk

        if self.load_from_disk:
            if self.start<self.end:
                instance_dicts=load_from_disk(self.path).shuffle(42)
                instance_dicts=instance_dicts.select(range(self.start,self.end))
            else:
                instance_dicts=load_from_disk(self.path).shuffle(42)
                data_len = len(instance_dicts)
                instance_dicts=instance_dicts.select(range(self.start,data_len))
        else:
            if self.start<self.end:
                instance_dicts= load_dataset(self.path, split=self.split).shuffle(42)
                instance_dicts=instance_dicts.select(range(self.start,self.end))
            else:
                instance_dicts= load_dataset(self.path, split=self.split).shuffle(42)
                data_len = len(instance_dicts)
                instance_dicts=instance_dicts.select(range(self.start,data_len))

        if self.num_rollouts_per_instance>1:
            new_instance_dicts = []
            import copy
            import tqdm
            for instance in tqdm.tqdm(instance_dicts, desc="Duplicating instances"):
                for i in range(self.num_rollouts_per_instance):
                    new_instance = copy.deepcopy(instance)
                    new_instance["base_commit"] = instance['instance_id'] if 'base_commit' not in instance else instance['base_commit']
                    new_instance['traj_id'] = f"{instance['instance_id']}_{i}"

                    new_instance_dicts.append(new_instance)
            instance_dicts=new_instance_dicts

        instances = [
            SimpleBatchInstance.model_validate(convert_instance_dict(instance_dict)).to_full_batch_instance(
                self.deployment
            )
            for instance_dict in instance_dicts
        ]
        return _filter_batch_items(instances, filter_=self.filter, slice_=self.slice, shuffle=self.shuffle)

    @property
    def id(self) -> str:
        return "swesmith"

end class-attribute instance-attribute

end = 500

End index of instances to load.

filter class-attribute instance-attribute

filter = '.*'

Regular expression to filter the instances by instance id.

load_from_disk class-attribute instance-attribute

load_from_disk = False

Whether to load the dataset from local disk using load_from_disk.

num_rollouts_per_instance class-attribute instance-attribute

num_rollouts_per_instance = -1

Number of rollouts to perform per instance. If >1, the instances will be duplicated accordingly.

path instance-attribute

path

Name or path of the dataset.

repo_type class-attribute instance-attribute

repo_type = 'github'

Type of the repository. Can be 'github', 'local', or anything else for pre-existing repositories. If the repo_type is 'github', we will use git fetch to get the code from the specified repo and base_commit in the instance config. If the repo_type is 'local', we do not support yet If the repo_type is anything else (e.g., 'preexisting'), we will assume that the code is already present in the deployment and do not perform any operations. The instance config should still specify the repo_name and base_commit for resetting the repo to the correct state.

shuffle class-attribute instance-attribute

shuffle = False

Shuffle the instances (before filtering and slicing).

slice class-attribute instance-attribute

slice = ''

Select only a slice of the instances (after filtering by filter). Possible values are stop or start:stop or start:stop:step. (i.e., it behaves exactly like python's list slicing list[slice]).

split instance-attribute

split

Split of the dataset to load.

start class-attribute instance-attribute

start = 0

Start index of instances to load.

type class-attribute instance-attribute

type = 'swesmith'

Discriminator for (de)serialization/CLI. Do not change.

get_instance_configs

get_instance_configs()

Load instances from SWE-smith dataset. This function is used for run_batch.py It duplicates instances if num_rollouts_per_instance>1.

Source code in SWE-agent/sweagent/run/batch_instances.py
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
def get_instance_configs(self) -> list[BatchInstance]:
    """Load instances from SWE-smith dataset. This function is used for run_batch.py
    It duplicates instances if num_rollouts_per_instance>1.
    """
    num_rollouts_per_instance = self.num_rollouts_per_instance
    def convert_instance_dict(instance_dict) -> dict[str, Any]:
        instance_dict['repo_type'] = self.repo_type
        instance_dict["id"] = instance_dict["instance_id"]
        # todo: The base_commit is currently incorrect
        instance_dict["traj_id"] = instance_dict.get("traj_id", instance_dict["instance_id"])
        instance_dict["base_commit"] = instance_dict["id"] if "base_commit" not in instance_dict else instance_dict["base_commit"]
        instance_dict["problem_statement"] = instance_dict.get("problem_statement", "")
        instance_dict["repo_name"] = "testbed"
        instance_dict["extra_fields"] = {"fail_to_pass": instance_dict["FAIL_TO_PASS"]}
        instance_dict['ds']=instance_dict
        return instance_dict
    from datasets import load_dataset,load_from_disk

    if self.load_from_disk:
        if self.start<self.end:
            instance_dicts=load_from_disk(self.path).shuffle(42)
            instance_dicts=instance_dicts.select(range(self.start,self.end))
        else:
            instance_dicts=load_from_disk(self.path).shuffle(42)
            data_len = len(instance_dicts)
            instance_dicts=instance_dicts.select(range(self.start,data_len))
    else:
        if self.start<self.end:
            instance_dicts= load_dataset(self.path, split=self.split).shuffle(42)
            instance_dicts=instance_dicts.select(range(self.start,self.end))
        else:
            instance_dicts= load_dataset(self.path, split=self.split).shuffle(42)
            data_len = len(instance_dicts)
            instance_dicts=instance_dicts.select(range(self.start,data_len))

    if self.num_rollouts_per_instance>1:
        new_instance_dicts = []
        import copy
        import tqdm
        for instance in tqdm.tqdm(instance_dicts, desc="Duplicating instances"):
            for i in range(self.num_rollouts_per_instance):
                new_instance = copy.deepcopy(instance)
                new_instance["base_commit"] = instance['instance_id'] if 'base_commit' not in instance else instance['base_commit']
                new_instance['traj_id'] = f"{instance['instance_id']}_{i}"

                new_instance_dicts.append(new_instance)
        instance_dicts=new_instance_dicts

    instances = [
        SimpleBatchInstance.model_validate(convert_instance_dict(instance_dict)).to_full_batch_instance(
            self.deployment
        )
        for instance_dict in instance_dicts
    ]
    return _filter_batch_items(instances, filter_=self.filter, slice_=self.slice, shuffle=self.shuffle)

sweagent.run.batch_instances.SkyRLInstances

Bases: BaseModel, AbstractInstanceSource

Load instances from RL data (smith format).

Source code in SWE-agent/sweagent/run/batch_instances.py
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
class SkyRLInstances(BaseModel, AbstractInstanceSource):
    """Load instances from RL data (smith format)."""

    # dataset: Optional[List[Dict[str, Any]]]
    repo_type: str = 'github'
    """Type of the repository. Can be 'github', 'local', or '' (empty string for pre-existing)."""
    path: str
    """Name or path of the dataset."""
    split: str
    """Split of the dataset to load."""
    deployment: DeploymentConfig = Field(
        default_factory=lambda: SandboxDeploymentConfig(),
    )


    filter: str = ".*"
    """Regular expression to filter the instances by instance id."""
    slice: str = ""
    """Select only a slice of the instances (after filtering by `filter`).
    Possible values are stop or start:stop or start:stop:step.
    (i.e., it behaves exactly like python's list slicing `list[slice]`).
    """
    shuffle: bool = False
    """Shuffle the instances (before filtering and slicing)."""

    type: Literal["skyrl"] = "skyrl"
    """Discriminator for (de)serialization/CLI. Do not change."""

    def get_instance_configs(self) -> list[BatchInstance]:

        def convert_instance_dict(instance_dict) -> dict[str, Any]:
            instance_dict['repo_type'] = self.repo_type
            instance_dict["id"] = instance_dict["instance_id"]
            # todo: The base_commit is currently incorrect
            instance_dict["traj_id"] = instance_dict.get("traj_id", instance_dict["instance_id"])
            instance_dict["base_commit"] = instance_dict["id"] if "base_commit" not in instance_dict else instance_dict["base_commit"]
            instance_dict["problem_statement"] = instance_dict.get("problem_statement", "")
            instance_dict["repo_name"] = "testbed"
            instance_dict["extra_fields"] = {"fail_to_pass": instance_dict["FAIL_TO_PASS"]}
            instance_dict['ds']=instance_dict
            return instance_dict
        # asset self has dataset
        assert hasattr(self,'dataset'),"SkyRLInstances requires dataset attribute"
        instance_dicts = self.dataset 

        instances = [
            SimpleBatchInstance.model_validate(convert_instance_dict(instance_dict)).to_full_batch_instance(
                self.deployment
            )
            for instance_dict in instance_dicts
        ]

        return _filter_batch_items(instances, filter_=self.filter, slice_=self.slice, shuffle=self.shuffle)


    def get_instance_configs_ds(self,dataset) -> list[BatchInstance]:
        """Load instances from RL data (smith format). This function is used for SkyRL"""

        def convert_instance_dict(instance_dict) -> dict[str, Any]:
            instance_dict['repo_type'] = self.repo_type
            instance_dict["id"] = instance_dict["instance_id"]
            # todo: The base_commit is currently incorrect
            instance_dict["traj_id"] = instance_dict.get("traj_id", instance_dict["instance_id"])
            instance_dict["base_commit"] = instance_dict["id"] if "base_commit" not in instance_dict else instance_dict["base_commit"]
            instance_dict["problem_statement"] = instance_dict.get("problem_statement", "")
            instance_dict["repo_name"] = "testbed"
            instance_dict["extra_fields"] = {"fail_to_pass": instance_dict["FAIL_TO_PASS"]}
            instance_dict['ds']=instance_dict
            return instance_dict

        instance_dicts = dataset

        instances = [
            SimpleBatchInstance.model_validate(convert_instance_dict(instance_dict)).to_full_batch_instance(
                self.deployment
            )
            for instance_dict in instance_dicts
        ]
        return _filter_batch_items(instances, filter_=self.filter, slice_=self.slice, shuffle=self.shuffle)

    @property
    def id(self) -> str:
        return "skyrl"

filter class-attribute instance-attribute

filter = '.*'

Regular expression to filter the instances by instance id.

path instance-attribute

path

Name or path of the dataset.

repo_type class-attribute instance-attribute

repo_type = 'github'

Type of the repository. Can be 'github', 'local', or '' (empty string for pre-existing).

shuffle class-attribute instance-attribute

shuffle = False

Shuffle the instances (before filtering and slicing).

slice class-attribute instance-attribute

slice = ''

Select only a slice of the instances (after filtering by filter). Possible values are stop or start:stop or start:stop:step. (i.e., it behaves exactly like python's list slicing list[slice]).

split instance-attribute

split

Split of the dataset to load.

type class-attribute instance-attribute

type = 'skyrl'

Discriminator for (de)serialization/CLI. Do not change.

get_instance_configs_ds

get_instance_configs_ds(dataset)

Load instances from RL data (smith format). This function is used for SkyRL

Source code in SWE-agent/sweagent/run/batch_instances.py
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
def get_instance_configs_ds(self,dataset) -> list[BatchInstance]:
    """Load instances from RL data (smith format). This function is used for SkyRL"""

    def convert_instance_dict(instance_dict) -> dict[str, Any]:
        instance_dict['repo_type'] = self.repo_type
        instance_dict["id"] = instance_dict["instance_id"]
        # todo: The base_commit is currently incorrect
        instance_dict["traj_id"] = instance_dict.get("traj_id", instance_dict["instance_id"])
        instance_dict["base_commit"] = instance_dict["id"] if "base_commit" not in instance_dict else instance_dict["base_commit"]
        instance_dict["problem_statement"] = instance_dict.get("problem_statement", "")
        instance_dict["repo_name"] = "testbed"
        instance_dict["extra_fields"] = {"fail_to_pass": instance_dict["FAIL_TO_PASS"]}
        instance_dict['ds']=instance_dict
        return instance_dict

    instance_dicts = dataset

    instances = [
        SimpleBatchInstance.model_validate(convert_instance_dict(instance_dict)).to_full_batch_instance(
            self.deployment
        )
        for instance_dict in instance_dicts
    ]
    return _filter_batch_items(instances, filter_=self.filter, slice_=self.slice, shuffle=self.shuffle)