Skip to content

Commit 4559c72

Browse files
nwhite365insrc-copybara[bot]
authored andcommitted
SDK update
GitOrigin-RevId: 3d02fd338b00d5f8f26dc17428d6571cbce412d5
1 parent 6aa5352 commit 4559c72

File tree

5 files changed

+194
-2
lines changed

5 files changed

+194
-2
lines changed

intrinsic/solutions/deployments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"padding-left: var(--jp-code-padding);"
6262
)
6363

64-
_WORLD_ID = "world"
64+
6565

6666

6767
class Solution:

intrinsic/solutions/execution.py

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
from intrinsic.solutions import provided
5555
from intrinsic.solutions import simulation as simulation_mod
5656
from intrinsic.solutions import utils
57+
from intrinsic.solutions import worlds # pylint: disable=line-too-long
5758
from intrinsic.solutions.internal import actions
5859
from intrinsic.solutions.internal import blackboard as blackboard_internal
5960
from intrinsic.util.grpc import error_handling
@@ -691,6 +692,9 @@ def run_async(
691692
simulation_mode: Optional["Executive.SimulationMode"] = None,
692693
embed_skill_traces: bool = False,
693694

695+
start_from_world_state: worlds.EditWorldId | None = None,
696+
697+
694698
keep_blackboard: bool = False,
695699

696700
):
@@ -727,6 +731,21 @@ def run_async(
727731
to these nodes and run from there. Only one of recover_from_nodes or
728732
start_node can be set.
729733
734+
735+
start_from_world_state: Optional parameter to specify what starting world
736+
state to run the operation from. If an EditWorldId is set, the execute
737+
belief world and simulation world will be reset to the specified world
738+
before running the operation. Otherwise, the operation will be run in
739+
the current world state as-is.
740+
741+
Specifying `worlds.EditWorldId.INITIAL` resets the world state to the
742+
state of the Initial editing world before running the operation.
743+
744+
Specifying `worlds.EditWorldId.BELIEF` keeps the execute belief world in
745+
its current state, but the simulation world state is first reset to
746+
match the execute world.
747+
748+
730749
Raises:
731750
solutions_errors.UnavailableError: On executive service not reachable.
732751
grpc.RpcError: On any other gRPC error.
@@ -744,6 +763,7 @@ def run_async(
744763

745764
simulation_mode=simulation_mode,
746765
embed_skill_traces=embed_skill_traces,
766+
start_from_world_state=start_from_world_state, # pylint: disable=line-too-long
747767

748768
keep_blackboard=keep_blackboard,
749769

@@ -765,6 +785,9 @@ def run(
765785
simulation_mode: Optional["Executive.SimulationMode"] = None,
766786
embed_skill_traces: bool = False,
767787

788+
start_from_world_state: worlds.EditWorldId | None = None,
789+
790+
768791
keep_blackboard: bool = False,
769792

770793
):
@@ -804,6 +827,21 @@ def run(
804827
to these nodes and run from there. Only one of recover_from_nodes or
805828
start_node can be set.
806829
830+
831+
start_from_world_state: Optional parameter to specify what starting world
832+
state to run the operation from. If an EditWorldId is set, the execute
833+
belief world and simulation world will be reset to the specified world
834+
before running the operation. Otherwise, the operation will be run in
835+
the current world state as-is.
836+
837+
Specifying `worlds.EditWorldId.INITIAL` resets the world state to the
838+
state of the Initial editing world before running the operation.
839+
840+
Specifying `worlds.EditWorldId.BELIEF` keeps the execute belief world in
841+
its current state, but the simulation world state is first reset to
842+
match the execute world.
843+
844+
807845
Raises:
808846
ExecutionFailedError: On unexpected state of the executive during plan
809847
execution.
@@ -827,6 +865,7 @@ def run(
827865

828866
simulation_mode=simulation_mode,
829867
embed_skill_traces=embed_skill_traces,
868+
start_from_world_state=start_from_world_state, # pylint: disable=line-too-long
830869

831870
keep_blackboard=keep_blackboard,
832871

@@ -869,6 +908,7 @@ def _run(
869908

870909
recover_from_nodes: list[bt.NodeInTreeType] | None,
871910

911+
start_from_world_state: worlds.EditWorldId | None, # pylint: disable=line-too-long
872912

873913
keep_blackboard: bool = False,
874914

@@ -903,14 +943,29 @@ def _run(
903943
to these nodes and run from there. Only one of recover_from_nodes or
904944
start_node can be set.
905945
946+
947+
start_from_world_state: Optional parameter to specify what starting world
948+
state to run the operation from. If an EditWorldId is set, the execute
949+
belief world and simulation world will be reset to the specified world
950+
before running the operation. Otherwise, the operation will be run in
951+
the current world state as-is.
952+
953+
Specifying `worlds.EditWorldId.INITIAL` resets the world state to the
954+
state of the Initial editing world before running the operation.
955+
956+
Specifying `worlds.EditWorldId.BELIEF` keeps the execute belief world in
957+
its current state, but the simulation world state is first reset to
958+
match the execute world.
959+
960+
906961
Raises:
907962
ExecutionFailedError: On unexpected state of the executive during plan
908963
execution.
909964
solutions_errors.UnavailableError: On executive service not reachable.
910965
grpc.RpcError: On any other gRPC error.
911966
OperationNotFoundError: if no operation is currently active.
912967
"""
913-
self._reset_simulation_if_needed(silence_outputs)
968+
914969

915970

916971
if recover_from_nodes and start_node is not None:
@@ -950,6 +1005,7 @@ def _run(
9501005
embed_skill_traces=embed_skill_traces,
9511006
parameters=None,
9521007
resources=None,
1008+
start_from_world_state=start_from_world_state, # pylint: disable=line-too-long
9531009
)
9541010
return
9551011

@@ -999,6 +1055,7 @@ def get_node_identifier_for_node_in_tree(
9991055
simulation_mode=simulation_mode,
10001056
embed_skill_traces=embed_skill_traces,
10011057
silence_outputs=silence_outputs,
1058+
start_from_world_state=start_from_world_state, # pylint: disable=line-too-long
10021059
)
10031060

10041061
# pylint: enable=g-doc-args
@@ -1131,6 +1188,7 @@ def start(
11311188

11321189
simulation_mode: Optional["Executive.SimulationMode"] = None,
11331190
embed_skill_traces: bool = False,
1191+
start_from_world_state: worlds.EditWorldId | None = None, # pylint: disable=line-too-long
11341192
) -> None:
11351193
"""Starts the currently loaded plan.
11361194
@@ -1155,6 +1213,21 @@ def start(
11551213
recover_from_nodes: List of nodes to recover from. Execution will forward
11561214
to these nodes and run from there.
11571215
1216+
1217+
start_from_world_state: Optional parameter to specify what starting world
1218+
state to start the operation from. If an EditWorldId is set, the execute
1219+
belief world and simulation world will be reset to the specified world
1220+
before starting the operation. Otherwise, the operation will be started
1221+
in the current world state as-is.
1222+
1223+
Specifying `worlds.EditWorldId.INITIAL` resets the world state to the
1224+
state of the Initial editing world before starting the operation.
1225+
1226+
Specifying `worlds.EditWorldId.BELIEF` keeps the execute belief world in
1227+
its current state, but the simulation world state is first reset to
1228+
match the execute world.
1229+
1230+
11581231
Raises:
11591232
solutions_errors.UnavailableError: On executive service not reachable.
11601233
grpc.RpcError: On any other gRPC error.
@@ -1190,6 +1263,7 @@ def start(
11901263

11911264
simulation_mode=simulation_mode,
11921265
embed_skill_traces=embed_skill_traces,
1266+
start_from_world_state=start_from_world_state, # pylint: disable=line-too-long
11931267
)
11941268

11951269
if blocking:
@@ -1453,6 +1527,7 @@ def _start_with_retry(
14531527

14541528
simulation_mode: Optional["Executive.SimulationMode"] = None,
14551529
embed_skill_traces: bool = False,
1530+
start_from_world_state: worlds.EditWorldId | None = None, # pylint: disable=line-too-long
14561531
) -> None:
14571532
"""Starts the executive and handles errors."""
14581533
if self._operation is None:
@@ -1492,6 +1567,10 @@ def _start_with_retry(
14921567
if resources is not None:
14931568
for reference, handle in resources.items():
14941569
request.resources[reference] = handle
1570+
1571+
if start_from_world_state is not None:
1572+
request.scene_id = start_from_world_state
1573+
14951574
self._operation.update_from_proto(self._stub.StartOperation(request))
14961575

14971576
@error_handling.retry_on_grpc_unavailable

intrinsic/solutions/execution_test.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from intrinsic.solutions import execution
3131
from intrinsic.solutions import provided
3232
from intrinsic.solutions import simulation as simulation_mod
33+
from intrinsic.solutions import worlds # pylint: disable=line-too-long
3334
from intrinsic.solutions.internal import behavior_call
3435
from intrinsic.solutions.testing import compare
3536
from intrinsic.solutions.testing import test_skill_params_pb2
@@ -103,6 +104,7 @@ def _create_operation_proto(
103104
bt_proto: behavior_tree_pb2.BehaviorTree = behavior_tree_pb2.BehaviorTree(),
104105
name: str = _OPERATION_NAME,
105106
response: run_response_pb2.RunResponse | None = None,
107+
scene_id: str = '', # pylint: disable=line-too-long
106108
):
107109
metadata = run_metadata_pb2.RunMetadata(operation_state=state)
108110
metadata.behavior_tree.CopyFrom(bt_proto)
@@ -113,6 +115,10 @@ def _create_operation_proto(
113115
run_metadata_pb2.RunMetadata.CANCELED,
114116
]:
115117
done = True
118+
119+
if scene_id:
120+
metadata.scene_id = scene_id
121+
116122
return operations_pb2.Operation(
117123
name=name,
118124
done=done,
@@ -161,9 +167,11 @@ def _setup_create_operation(self, setup_empty_list_operations: bool = True):
161167

162168
def _setup_start_operation(
163169
self,
170+
scene_id: str = '', # pylint: disable=line-too-long
164171
):
165172
start_response = self._create_operation_proto(
166173
state=run_metadata_pb2.RunMetadata.RUNNING,
174+
scene_id=scene_id, # pylint: disable=line-too-long
167175
)
168176
self._executive_service_stub.StartOperation.return_value = start_response
169177

@@ -438,6 +446,41 @@ def test_run_async_works_on_behavior_tree_node(self):
438446
create_request
439447
)
440448

449+
450+
@parameterized.named_parameters(
451+
dict(
452+
testcase_name='initial_world_id',
453+
edit_world_id=worlds.EditWorldId.INITIAL,
454+
),
455+
dict(
456+
testcase_name='execute_world_id',
457+
edit_world_id=worlds.EditWorldId.BELIEF,
458+
),
459+
)
460+
def test_run_async_sets_scene_id(self, edit_world_id):
461+
"""Tests if executive.run_async(start_from_world_state) propagates the world id."""
462+
self._create_operation()
463+
response = self._create_operation_proto(
464+
state=run_metadata_pb2.RunMetadata.RUNNING,
465+
scene_id=edit_world_id,
466+
)
467+
self._executive_service_stub.StartOperation.return_value = response
468+
469+
self._executive.run_async(start_from_world_state=edit_world_id)
470+
471+
start_request = executive_service_pb2.StartOperationRequest(
472+
name=_OPERATION_NAME
473+
)
474+
start_request.skill_trace_handling = (
475+
run_metadata_pb2.RunMetadata.TracingInfo.SKILL_TRACES_LINK
476+
)
477+
start_request.scene_id = edit_world_id
478+
self._executive_service_stub.StartOperation.assert_called_once_with(
479+
start_request
480+
)
481+
482+
483+
441484
@parameterized.named_parameters(
442485
dict(
443486
testcase_name='operation_state',
@@ -939,6 +982,44 @@ def test_run_recovery_nodes_by_object_works(self):
939982

940983

941984

985+
986+
@parameterized.named_parameters(
987+
dict(
988+
testcase_name='initial_world_id',
989+
edit_world_id=worlds.EditWorldId.INITIAL,
990+
),
991+
dict(
992+
testcase_name='execute_world_id',
993+
edit_world_id=worlds.EditWorldId.BELIEF,
994+
),
995+
)
996+
def test_run_sets_scene_id(self, edit_world_id):
997+
"""Tests if executive.run(start_from_world_state) propagates the world id."""
998+
self._setup_create_operation()
999+
self._setup_start_operation(scene_id=edit_world_id)
1000+
self._setup_get_operation_sequence([
1001+
run_metadata_pb2.RunMetadata.RUNNING,
1002+
run_metadata_pb2.RunMetadata.RUNNING,
1003+
run_metadata_pb2.RunMetadata.SUCCEEDED,
1004+
run_metadata_pb2.RunMetadata.SUCCEEDED,
1005+
])
1006+
1007+
my_action = behavior_call.Action(skill_id='my_action')
1008+
self._executive.run(my_action, start_from_world_state=edit_world_id)
1009+
1010+
start_request = executive_service_pb2.StartOperationRequest(
1011+
name=_OPERATION_NAME
1012+
)
1013+
start_request.skill_trace_handling = (
1014+
run_metadata_pb2.RunMetadata.TracingInfo.SKILL_TRACES_LINK
1015+
)
1016+
start_request.scene_id = edit_world_id
1017+
self._executive_service_stub.StartOperation.assert_called_once_with(
1018+
start_request
1019+
)
1020+
1021+
1022+
9421023
def test_has_operation_true(self):
9431024
"""Tests if executive.has_operation returns true for an operation loaded."""
9441025
response = operations_pb2.ListOperationsResponse()

intrinsic/solutions/simulation.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
"""Provides functionality to interact with a running simulation.
44
5+
Deprecated. See migration note in `reset()` method below. # pylint: disable=line-too-long
56
67
Typical usage example:
78
from intrinsic.executive.jupyter.workcell import intrinsic
@@ -12,6 +13,7 @@
1213
simulation.reset()
1314
"""
1415

16+
import warnings # pylint: disable=line-too-long
1517

1618
import grpc
1719

@@ -71,8 +73,25 @@ def _call_simulation_service_reset(
7173
def reset(self) -> None:
7274
"""Resets the simulation world to its initial state.
7375
76+
77+
Deprecated: To reset the simulation world before running a process, set the
78+
`start_from_world_state` parameter in `Solution.executive.run()` instead.
79+
See execution.py for more details.
80+
81+
7482
Also makes sure that all affected components such as ICON are in a working
7583
state.
7684
"""
85+
86+
warnings.warn(
87+
'Simulation.reset() is deprecated. To reset the simulation'
88+
' world before running a process, set the `start_from_world_state'
89+
' parameter in `solution.executive.run()` instead. See docstring for'
90+
' `solution.executive.run()` for more details.',
91+
DeprecationWarning,
92+
stacklevel=2,
93+
)
94+
95+
7796
request = simulation_service_pb2.ResetSimulationRequest()
7897
self._call_simulation_service_reset(request)

0 commit comments

Comments
 (0)