Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified scienceworld/scienceworld.jar
Binary file not shown.
11 changes: 11 additions & 0 deletions scripts/reproduce_issue_82.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from scienceworld import ScienceWorldEnv


env = ScienceWorldEnv("1-1")
try:
_, info = env.reset()
for action in info["valid"]:
if action.startswith("open ") and "door" in action:
print(action)
finally:
env.close()
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import language.runtime.runners.{ActionRunner, PredicateRunner}
import language.struct.{DynamicValue, ScopedVariableLUT}
import scienceworld.actions.Action
import scienceworld.objects.agent.Agent
import scienceworld.objects.portal.Portal
import scienceworld.struct.EnvObject
import scienceworld.tasks.goals.{GoalSequence, ObjMonitor}
import util.UniqueTypeID
Expand Down Expand Up @@ -114,7 +115,10 @@ class InputParser(actionRequestDefs:Array[ActionRequestDef]) {
// Step 2A: Populate an array of the unique referents (as strings)
val out = new ArrayBuffer[(String, EnvObject)]()
for (i <- 0 until allObjs.length) {
val referent = uniqueReferents(i)
val referent = allObjs(i) match {
case portal:Portal => portal.getCanonicalReferent(perspectiveContainer)
case _ => uniqueReferents(i)
}
out.append( (referent.toLowerCase(), allObjs(i)) )
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ class Portal (val _isOpen:Boolean, val connectsFrom:EnvObject, val connectsTo:En
return Set(this.name, this.name + " from " + connectsFrom.name + " to " + connectsTo.name, this.name + " from " + connectsTo.name + " to " + connectsFrom.name)
}

def getCanonicalReferent(perspectiveContainer:EnvObject):String = {
val connectsToContainer = this.getConnectsTo(perspectiveContainer)
if (connectsToContainer.isDefined) {
return this.name + " to " + connectsToContainer.get.name
}

return this.name + " from " + connectsFrom.name + " to " + connectsTo.name

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot when would that be used as a canonical referent? Give concrete example from playing ScienceWorld.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no player-facing example. With easy/teleportAction, the all-universe referent LUT computes this fallback for remote doors (for example, door from bathroom to kitchen while the player is in the hallway), but teleport generation accepts only locations. Open/close/move actions use visible doors and therefore always use door to <destination>.

}

override def getDescriptName(overrideName: String): String = {
return "door between " + this.connectsFrom.name + " and " + this.connectsTo.name
}
Expand Down
25 changes: 25 additions & 0 deletions tests/test_scienceworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,31 @@ def test_multiple_instances():
assert obs1_2 == obs2_2


def test_door_actions_use_canonical_referents():
env = ScienceWorldEnv("1-1")
try:
_, info = env.reset()
door_actions = {
action for action in info["valid"]
if action.startswith("open ") and "door" in action
}
assert door_actions == {
"open door to art studio",
"open door to bedroom",
"open door to greenhouse",
"open door to kitchen",
"open door to living room",
"open door to workshop",
}

for action in ("open bedroom door", "open door to bedroom"):
env.reset()
observation, _, _, _ = env.step(action)
assert observation == "The door is now open."
finally:
env.close()


def test_closing_env():
env = ScienceWorldEnv()
env.task_names # Load task names.
Expand Down
Loading