How to use hasstate method in pyatom

Best Python code snippet using pyatom_python

unknown_no_occup.py

Source:unknown_no_occup.py Github

copy

Full Screen

1from stripstream.pddl.objects import EasyType as Type, EasyParameter as Param2from stripstream.pddl.logic.predicates import EasyPredicate as Predicate3from stripstream.pddl.operators import Action, Axiom4from stripstream.pddl.logic.connectives import And, Not5from stripstream.algorithms.incremental.incremental_planner import incremental_planner6from stripstream.algorithms.search.fast_downward import get_fast_downward7from stripstream.pddl.utils import convert_plan, rename_easy8from stripstream.pddl.problem import STRIPStreamProblem9from stripstream.pddl.examples.belief.problems import *10from stripstream.pddl.logic.predicates import Function11from stripstream.pddl.logic.operations import Initialize, Cost12from stripstream.algorithms.plan import plan_cost13from stripstream.pddl.logic.quantifiers import Exists, ForAll14from stripstream.pddl.logic.atoms import Equal15from stripstream.pddl.examples.belief.utils import *16from toyTest import glob, makeOperators, Bd, ObjState, ObjLoc17import toyTest18OPERATOR_MAP = {19 'find': make_look,20 'inspect_loc': make_look_clear,21 'inspect_state': make_look_state,22 'transport': make_transport,23 'wash': make_wash,24 'paint': make_paint,25 'dry': make_dry,26}27COST_SCALE = 1028OBJ, LOC, STATE = Type(), Type(), Type()29At = Predicate(OBJ, LOC)30HasState = Predicate(OBJ, STATE)31Clear = Predicate(LOC)32Safe = Predicate(OBJ, LOC)33IsDryer = Predicate(LOC)34IsPainter = Predicate(LOC)35IsWasher = Predicate(LOC)36UnsureLoc = Predicate(OBJ) # NOTE - can also just make these objects37UnsureState = Predicate(OBJ)38UnsureClear = Predicate(LOC)39NotAtLoc = Predicate(OBJ, LOC)40FindCost = Function('find_cost', [OBJ, LOC])41InspectStateCost = Function('inspect_state_cost', [OBJ, STATE])42O, O2, L1, L2, S = Param(OBJ), Param(OBJ), Param(LOC), Param(LOC), Param(STATE)43rename_easy(locals())44actions = [45 Action(name='find', parameters=[O, L1], # Policy to find the object or an inspection?46 condition=And(UnsureLoc(O), Not(NotAtLoc(O, L1))),47 effect=And(At(O, L1), Not(UnsureLoc(O)), Cost(FindCost(O, L1)))), # TODO - can even adjust the cost of these to bias search towards more likely48 Action(name='inspect_state', parameters=[O, L1, S],49 condition=And(UnsureState(O), At(O, L1)), # Probably should know where it is before you worry about its state50 #condition=And(UnsureState(O), Not(UnsureLoc(O))), # Probably should know where it is before you worry about its state51 effect=And(HasState(O, S), Not(UnsureState(O)), Cost(InspectStateCost(O, S)))), # TODO - should I factor loc in the cost?52 Action(name='transport', parameters=[O, L1, L2], # NOTE - Leslie and Tomas call this Move53 #condition=And(At(O, L1)),54 condition=And(At(O, L1), Clear(L2)),55 effect=And(At(O, L2), Not(At(O, L1))),56 cost=COST_SCALE*1),57 Action(name='wash', parameters=[O, L1, S],58 condition=And(At(O, L1), HasState(O, S), IsWasher(L1)),59 effect=And(HasState(O, clean), Not(HasState(O, S))),60 cost=COST_SCALE*1),61 Action(name='paint', parameters=[O, L1],62 condition=And(At(O, L1), HasState(O, clean), IsPainter(L1)),63 effect=And(HasState(O, wet), Not(HasState(O, clean))),64 cost=COST_SCALE*1),65 Action(name='dry', parameters=[O, L1],66 condition=And(At(O, L1), HasState(O, wet), IsDryer(L1)),67 effect=And(HasState(O, dry), Not(HasState(O, wet))),68 cost=COST_SCALE*1),69 Axiom(effect=Clear(L2), condition=ForAll([O2], Safe(O2, L2))),70 Axiom(effect=Safe(O, L1), condition=Exists([L2], And(At(O, L2), Not(Equal(L1, L2))))), # NOTE - automatically includes UnsureLoc71]72# TODO - do I need lower confidence bound that the object isn't there to prevent it from doing nothing or impossible things?73LOC_CONFIDENCE = .9574STATE_CONFIDENCE = LOC_CONFIDENCE75CLEAR_CONFIDENCE = STATE_CONFIDENCE76MIN_CONFIDENCE = .001 # TODO - how does this work in continuous domains?77MIN_P = 1e-678def observable_problem(belief, goal, costs=True): # NOTE - costs is really important here79 #objects = belief.objLoc.keys()80 locations = belief.occupancies.keys()81 states = [dirty, clean, dry, wet]82 initial_atoms = []83 occupied = set()84 for obj in belief.objLoc.keys():85 dist = belief.objLocDist(obj)86 loc, p = dist.computeMPE() # TODO - concentration inequalities for Gaussian87 if p >= LOC_CONFIDENCE:88 initial_atoms.append(At(obj, loc))89 occupied.add(loc)90 else:91 initial_atoms.append(UnsureLoc(obj))92 for loc in locations:93 p = dist.prob(loc)94 cost = int(COST_SCALE*1./max(p, MIN_P)) if costs else COST_SCALE*1 # TODO - set to infinity if too large (equivalent to blocking)95 initial_atoms.append(Initialize(FindCost(OBJ(obj), LOC(loc)), cost))96 #if p < MIN_CONFIDENCE:97 # initial_atoms.append(NotAtLoc(obj, loc))98 for obj in belief.objState.keys():99 dist = belief.objState[obj]100 state, p = dist.computeMPE()101 if p >= STATE_CONFIDENCE:102 initial_atoms.append(HasState(obj, state))103 else:104 initial_atoms.append(UnsureState(obj))105 for state in states:106 p = dist.prob(state)107 cost = int(COST_SCALE*1./max(p, MIN_P)) if costs else COST_SCALE*1108 initial_atoms.append(Initialize(InspectStateCost(OBJ(obj), STATE(state)), cost))109 #if p < MIN_CONFIDENCE:110 # initial_atoms.append(NotHasState(obj, loc))111 for loc in belief.occupancies.keys():112 if loc == 'washer':113 initial_atoms.append(IsWasher(loc))114 elif loc == 'painter':115 initial_atoms.append(IsPainter(loc))116 elif loc == 'dryer':117 initial_atoms.append(IsDryer(loc))118 goal_literals = []119 for fluent in goal.fluents:120 if isinstance(fluent, Bd):121 literal, arg, prob = fluent.args122 if isinstance(literal, ObjLoc):123 goal_literals.append(At(literal.args[0], literal.value))124 elif isinstance(literal, ObjState):125 goal_literals.append(HasState(literal.args[0], arg))126 elif isinstance(literal, toyTest.Clear):127 goal_literals.append(Clear(literal.args[0]))128 else:129 raise NotImplementedError(literal)130 else:131 raise NotImplementedError(fluent)132 return STRIPStreamProblem(initial_atoms, goal_literals, actions, [], [])133##################################################134def unknown_policy(operators, goal, max_cost=10000):135 def fn(belief):136 problem = observable_problem(belief, goal)137 #print problem138 # NOTE - the cost sensitivity starts to factor into this...139 # NOTE - max cost prevents extremely large cost actions140 search = get_fast_downward('astar', verbose=False, max_cost=max_cost) # dijkstra | astar | wastar1 | wastar2 | wastar3 | eager | lazy141 plan, universe = incremental_planner(problem, search=search, frequency=1)142 cost = plan_cost(universe, plan)143 plan = convert_plan(plan)144 print 'Plan:', plan145 print 'Cost:', cost146 print 'Length:', len(plan)147 if plan is None or not plan:148 return None149 action, params = plan[0]150 print 'Action:', action, params151 print152 return OPERATOR_MAP[action.name](operators, *params)153 return fn154##################################################155#operator.__dict__.keys() = ['configurationCache', 'prim', 'conditionOnPreconds', 'delayBinding', 'results', 'cost', 'instanceCost',156# 'subPlans', 'functions', 'sideEffects', 'rebindPenalty', 'concreteAbstractionLevel', 'argsToPrint', 'parent',157# 'abstractionLevel', 'args', 'metaOperator', 'preconditions', 'closedLoopPrim', 'ignorableArgs', 'name',158# 'f', 'specialRegress', 'num']159def run_unknown():160 problem_fn = test8 # test0 | test1 | test8161 env, start, goal = problem_fn()162 global operatorDict163 operatorDict = makeOperators(glob.failProbs)164 print165 for name, operator in operatorDict.iteritems():166 print 'Name:', name167 print 'Args:', [arg for i, arg in enumerate(operator.args) if i not in operator.ignorableArgs]168 print 'Pre:', operator.preconditions169 print 'Eff:', operator.results170 print 'Side Eff:', operator.sideEffects171 print operator.__dict__172 print173 problem = observable_problem(start.details, goal)174 print problem175 search = get_fast_downward('eager') # dijkstra | astar | wastar1 | wastar2 | wastar3 | eager | lazy176 plan, _ = incremental_planner(problem, search=search, frequency=1)...

Full Screen

Full Screen

observable_2.py

Source:observable_2.py Github

copy

Full Screen

1from stripstream.pddl.objects import EasyType as Type, EasyParameter as Param2from stripstream.pddl.logic.predicates import EasyPredicate as Predicate3from stripstream.pddl.operators import Action4from stripstream.pddl.logic.connectives import And, Not5from stripstream.algorithms.incremental.incremental_planner import incremental_planner6from stripstream.algorithms.search.fast_downward import get_fast_downward7from stripstream.pddl.utils import convert_plan, rename_easy8from stripstream.pddl.problem import STRIPStreamProblem9from stripstream.pddl.examples.belief.problems import *10from stripstream.pddl.examples.belief.utils import *11from stripstream.pddl.examples.belief.unknown import OPERATOR_MAP12from toyTest import glob, makeOperators, Bd, ObjState, ObjLoc13OBJ, LOC, STATE = Type(), Type(), Type()14At = Predicate(OBJ, LOC)15HasState = Predicate(OBJ, STATE)16Clear = Predicate(LOC)17IsDryer = Predicate(LOC)18IsPainter = Predicate(LOC)19IsWasher = Predicate(LOC)20O, L1, L2, S = Param(OBJ), Param(LOC), Param(LOC), Param(STATE)21actions = [22 Action(name='transport', parameters=[O, L1, L2],23 condition=And(At(O, L1), Clear(L2)),24 effect=And(At(O, L2), Clear(L1), Not(At(O, L1)), Not(Clear(L2)))), # NOTE - Leslie and Tomas call this Move25 Action(name='wash', parameters=[O, L1, S],26 condition=And(At(O, L1), HasState(O, S), IsWasher(L1)),27 effect=And(HasState(O, clean), Not(HasState(O, S)))),28 Action(name='paint', parameters=[O, L1],29 condition=And(At(O, L1), HasState(O, clean), IsPainter(L1)),30 effect=And(HasState(O, wet), Not(HasState(O, clean)))),31 Action(name='dry', parameters=[O, L1],32 condition=And(At(O, L1), HasState(O, wet), IsDryer(L1)),33 effect=And(HasState(O, dry), Not(HasState(O, wet)))),34]35rename_easy(locals())36##################################################37def make_goal_literals(goal):38 goal_literals = []39 for fluent in goal.fluents:40 if isinstance(fluent, Bd):41 literal, arg, prob = fluent.args42 if isinstance(literal, ObjLoc):43 goal_literals.append(At(literal.args[0], literal.value))44 elif isinstance(literal, ObjState):45 goal_literals.append(HasState(literal.args[0], arg))46 else:47 raise NotImplementedError(literal)48 else:49 raise NotImplementedError(fluent)50 return goal_literals51def make_initial_atoms(locations, states, occupancies):52 initial_atoms = []53 initial_atoms += [At(*pair) for pair in locations.iteritems()]54 initial_atoms += [HasState(*pair) for pair in states.iteritems()]55 initial_atoms += [Clear(loc) for loc, occ in occupancies.iteritems() if not occ]56 for loc in occupancies:57 if loc == 'washer':58 initial_atoms.append(IsWasher(loc))59 if loc == 'painter':60 initial_atoms.append(IsPainter(loc))61 if loc == 'dryer':62 initial_atoms.append(IsDryer(loc))63 return initial_atoms64def make_problem((l, s, o), goal):65 initial_atoms = make_initial_atoms(l, s, o)66 goal_literals = make_goal_literals(goal)67 return STRIPStreamProblem(initial_atoms, goal_literals, actions, [], []) # TODO - constants?68"""69def observable_problem(env, start, goal):70 locations = start.details.occupancies.keys()71 initial_atoms = []72 constants = []73 occupied = set()74 for obj in env.objects:75 for attr in env.objects[obj]:76 if attr in STATES:77 initial_atoms.append(HasState(obj, attr))78 elif attr in locations:79 initial_atoms.append(At(obj, attr))80 occupied.add(attr)81 else:82 raise NotImplementedError(attr)83 for loc in locations:84 if loc not in occupied:85 initial_atoms.append(Clear(loc))86 constants.append(LOC(loc))87 if loc == 'washer':88 initial_atoms.append(IsWasher(loc))89 if loc == 'painter':90 initial_atoms.append(IsPainter(loc))91 if loc == 'dryer':92 initial_atoms.append(IsDryer(loc))93 return STRIPStreamProblem(initial_atoms, make_goal(goal), actions, [], constants)94"""95##################################################96def observable_policy(operators, goal):97 def fn(belief):98 problem = make_problem(maximum_likelihood_obs(belief), goal)99 #problem = make_problem(sample_obs(belief), goal)100 #problem = make_problem(sample_consistent_obs(belief), goal)101 #print problem102 search = get_fast_downward('astar', verbose=False) # dijkstra | astar | wastar1 | wastar2 | wastar3 | eager | lazy103 plan, universe = incremental_planner(problem, search=search, frequency=1)104 plan = convert_plan(plan)105 print 'Plan:', plan106 print 'Length:', len(plan)107 if plan is None or not plan:108 return None109 action, params = plan[0]110 print 'Action:', action, params111 print112 return OPERATOR_MAP[action.name](operators, *params)113 return fn114##################################################115#operator.__dict__.keys() = ['configurationCache', 'prim', 'conditionOnPreconds', 'delayBinding', 'results', 'cost', 'instanceCost',116# 'subPlans', 'functions', 'sideEffects', 'rebindPenalty', 'concreteAbstractionLevel', 'argsToPrint', 'parent',117# 'abstractionLevel', 'args', 'metaOperator', 'preconditions', 'closedLoopPrim', 'ignorableArgs', 'name',118# 'f', 'specialRegress', 'num']119def run_observable_2():120 problem_fn = test0 # test0 | test1 | test8121 env, start, goal = problem_fn()122 global operatorDict123 operatorDict = makeOperators(glob.failProbs)124 print125 for name, operator in operatorDict.iteritems():126 print 'Name:', name127 print 'Args:', [arg for i, arg in enumerate(operator.args) if i not in operator.ignorableArgs]128 print 'Pre:', operator.preconditions129 print 'Eff:', operator.results130 print 'Side Eff:', operator.sideEffects131 print132 #problem = make_problem(convert_start(env, start), goal)133 #problem = make_problem(maximum_likelihood_obs(start.details), goal)134 #problem = make_problem(sample_obs(start.details), goal)135 problem = make_problem(sample_consistent_obs(start.details), goal)136 print problem137 search = get_fast_downward('eager') # dijkstra | astar | wastar1 | wastar2 | wastar3 | eager | lazy138 plan, _ = incremental_planner(problem, search=search, frequency=1)...

Full Screen

Full Screen

observable_no_occup_2.py

Source:observable_no_occup_2.py Github

copy

Full Screen

1from stripstream.pddl.objects import EasyType as Type, EasyParameter as Param2from stripstream.pddl.logic.predicates import EasyPredicate as Predicate3from stripstream.pddl.operators import Action, Axiom4from stripstream.pddl.logic.connectives import And, Not5from stripstream.algorithms.incremental.incremental_planner import incremental_planner6from stripstream.algorithms.search.fast_downward import get_fast_downward7from stripstream.pddl.utils import convert_plan, rename_easy8from stripstream.pddl.problem import STRIPStreamProblem9from stripstream.pddl.examples.belief.problems import *10from stripstream.pddl.examples.belief.utils import *11from stripstream.pddl.examples.belief.unknown import OPERATOR_MAP12from stripstream.pddl.logic.quantifiers import Exists, ForAll13from stripstream.pddl.logic.atoms import Equal14from toyTest import glob, makeOperators, Bd, ObjState, ObjLoc15OBJ, LOC, STATE = Type(), Type(), Type()16At = Predicate(OBJ, LOC)17HasState = Predicate(OBJ, STATE)18Clear = Predicate(LOC)19Safe = Predicate(OBJ, LOC)20IsDryer = Predicate(LOC)21IsPainter = Predicate(LOC)22IsWasher = Predicate(LOC)23O, O2, L1, L2, S = Param(OBJ), Param(OBJ), Param(LOC), Param(LOC), Param(STATE)24actions = [25 Action(name='transport', parameters=[O, L1, L2],26 condition=And(At(O, L1), Clear(L2)),27 effect=And(At(O, L2), Not(At(O, L1)))), # NOTE - Leslie and Tomas call this Move28 Action(name='wash', parameters=[O, L1, S],29 condition=And(At(O, L1), HasState(O, S), IsWasher(L1)),30 effect=And(HasState(O, clean), Not(HasState(O, S)))),31 Action(name='paint', parameters=[O, L1],32 condition=And(At(O, L1), HasState(O, clean), IsPainter(L1)),33 effect=And(HasState(O, wet), Not(HasState(O, clean)))),34 Action(name='dry', parameters=[O, L1],35 condition=And(At(O, L1), HasState(O, wet), IsDryer(L1)),36 effect=And(HasState(O, dry), Not(HasState(O, wet)))),37 Axiom(effect=Clear(L2), condition=ForAll([O2], Safe(O2, L2))),38 Axiom(effect=Safe(O, L1), condition=Exists([L2], And(At(O, L2), Not(Equal(L1, L2))))),39]40rename_easy(locals())41##################################################42def make_goal_literals(goal):43 goal_literals = []44 for fluent in goal.fluents:45 if isinstance(fluent, Bd):46 literal, arg, prob = fluent.args47 if isinstance(literal, ObjLoc):48 goal_literals.append(At(literal.args[0], literal.value))49 elif isinstance(literal, ObjState):50 goal_literals.append(HasState(literal.args[0], arg))51 else:52 raise NotImplementedError(literal)53 else:54 raise NotImplementedError(fluent)55 return goal_literals56def make_initial_atoms(locations, states, occupancies):57 initial_atoms = []58 initial_atoms += [At(*pair) for pair in locations.iteritems()]59 initial_atoms += [HasState(*pair) for pair in states.iteritems()]60 for loc in occupancies:61 if loc == 'washer':62 initial_atoms.append(IsWasher(loc))63 if loc == 'painter':64 initial_atoms.append(IsPainter(loc))65 if loc == 'dryer':66 initial_atoms.append(IsDryer(loc))67 return initial_atoms68def make_problem((l, s, o), goal):69 initial_atoms = make_initial_atoms(l, s, o)70 goal_literals = make_goal_literals(goal)71 constants = map(LOC, o)72 return STRIPStreamProblem(initial_atoms, goal_literals, actions, [], constants)73##################################################74def observable_policy(operators, goal):75 def fn(belief):76 problem = make_problem(maximum_likelihood_obs(belief), goal)77 #problem = make_problem(sample_obs(belief), goal)78 #problem = make_problem(sample_consistent_obs(belief), goal)79 #print problem80 search = get_fast_downward('astar', verbose=False) # dijkstra | astar | wastar1 | wastar2 | wastar3 | eager | lazy81 plan, universe = incremental_planner(problem, search=search, frequency=1)82 plan = convert_plan(plan)83 print 'Plan:', plan84 print 'Length:', len(plan)85 if plan is None or not plan:86 return None87 action, params = plan[0]88 print 'Action:', action, params89 print90 return OPERATOR_MAP[action.name](operators, *params)91 return fn92##################################################93#operator.__dict__.keys() = ['configurationCache', 'prim', 'conditionOnPreconds', 'delayBinding', 'results', 'cost', 'instanceCost',94# 'subPlans', 'functions', 'sideEffects', 'rebindPenalty', 'concreteAbstractionLevel', 'argsToPrint', 'parent',95# 'abstractionLevel', 'args', 'metaOperator', 'preconditions', 'closedLoopPrim', 'ignorableArgs', 'name',96# 'f', 'specialRegress', 'num']97def run_observable_2():98 problem_fn = test8 # test0 | test1 | test899 env, start, goal = problem_fn()100 print101 print convert_start(env, start)102 print convert_goal(goal)103 #operators = makeOperators(glob.failProbs)104 #for name, operator in operators.iteritems():105 # print 'Name:', name106 # print 'Args:', [arg for i, arg in enumerate(operator.args) if i not in operator.ignorableArgs]107 # print 'Pre:', operator.preconditions108 # print 'Eff:', operator.results109 # print 'Side Eff:', operator.sideEffects110 # print111 #problem = make_problem(convert_start(env, start), goal)112 problem = make_problem(maximum_likelihood_obs(start.details), goal)113 #problem = make_problem(sample_obs(start.details), goal)114 #problem = make_problem(sample_consistent_obs(start.details), goal)115 print problem116 search = get_fast_downward('dijkstra') # dijkstra | astar | wastar1 | wastar2 | wastar3 | eager | lazy117 plan, _ = incremental_planner(problem, search=search, frequency=1)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyatom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful