Selecting automation scripts using reinforced learning
A system can evaluate multiple candidate scripts. The system receives a problem statement and a sample solution script. The system selects an additional script based on the sample solution script, and compiles a list of candidates including the sample and additional scripts. Then, for each of the candidates, the system simulates execution of the script and scores performance of the script. The system then presents results of the execution.
1 . A method, comprising:
receiving a problem statement describing a problem;
receiving a sample solution script from a user;
selecting, based on the sample solution script, a selected solution script;
compiling a list of candidate scripts, the list including the sample solution script and the selected solution script;
optimizing the candidate scripts by replacing at least one command in a candidate script with an alternative command from a command mapping database, wherein the command mapping database comprises at least one entry for a given command, wherein the at least one entry comprises a timestamp denoting the given command has been searched and a lack of an alternative command for the given command in response to searching for the given command in a predefined resource, wherein the at least one entry having the timestamp prevents a redundant search for the given command in the predefined resource;
identifying execution rules for each of the candidate scripts;
executing each of the candidate scripts in a simulation based on the execution rules;
scoring, based on the simulation and the execution rules, performance of each of the candidate scripts in addressing the problem, resulting in scored candidate scripts; and
presenting the scored candidate scripts;
wherein the simulating includes: defining a state-transition-reward routine; setting a first set of state checkpoints in a first script included within the candidate scripts; replicating a production environment, resulting in a replicated environment; and executing the first script within the replicated environment, the executing including:
executing a command included in the first script;
detecting a first state checkpoint included within the first set of state checkpoints; and
determining, in response to the detecting, a state of the first script, wherein, for the first script, the scoring is based further on a reward associated with a transition defined in the state-transition-reward routine, the transition associated with the state and a previous state, wherein the reward is a negative value applied to the transition, wherein the scoring comprises summing the negative value for occurrences of the transition to result in a final score for the first script, wherein a second script within the candidate scripts has another final score, wherein the state is one of a plurality of states comprising a ready state, a running state, a waiting state, a completed state, a terminated state, a succeeded state, and a failed state such that the reward is according to the transition among the plurality of states, wherein the negative value for the transition to the waiting state is more negative than the negative value for the transition to the running state, the completed state, or the succeeded state, wherein the negative value for the transition to the terminated state is more negative than the negative value for the transition to the waiting state, wherein the negative value for the transition to the failed state is more negative than the negative value for the transition the terminated state.
2 . The method of claim 1 , further comprising:
querying, based on the sample solution script, an external resource on the Internet identified in a knowledge base;
receiving, in response to the query, one or more found scripts; and
evaluating similarity of the one or more found scripts to the sample solution script, wherein:
the selecting is based on the evaluating; and
the selected solution script is included in a set of found scripts of the one or more found scripts.
3 . The method of claim 2 , wherein, for a first found script included in the set of found scripts, the evaluating includes:
comparing the first found script to the sample solution script; and
calculating, based on the comparing, a similarity score for the first found script, wherein the selecting is based further on the similarity score.
4 . The method of claim 2 , wherein the querying is performed via one or more Natural Language Processing (NLP) techniques based further on information included in a knowledge base.
5 . The method of claim 1 , further comprising optimizing the candidate scripts, the optimizing including, for a first script included in the candidate scripts:
extracting a first set of commands of the first script, the first set of commands including a first command;
determining that the first command is listed in an entry included in the command mapping database;
identifying, based on the first command and the entry included in the command mapping database, a first preferable alternative command; and
modifying the first script, the modifying including:
removing the first command from the first script; and
inserting the first preferable alternative command into the first script, resulting in a first optimized script.
6 . The method of claim 5 , wherein the optimizing further includes, for a second script included in the candidate scripts:
extracting a second set of commands of the second script, the second set of commands including a second command;
determining that the second command is not listed in the command mapping database;
searching, based on the determining that the second command is not listed in the command mapping database, an external resource for preferable alternative commands;
identifying, based on the searching, a second preferable alternative command;
updating, based on the second preferable alternative command, the command mapping database; and
modifying the second script, the modifying including:
removing the second command from the second script; and
inserting the second preferable alternative command into the second script, resulting in a second optimized script.
7 . A system comprising:
a memory; and
a central processing unit (CPU) coupled to the memory, the CPU configured to:
receive a problem statement describing a problem;
receive a sample solution script from a user;
select, based on the sample solution script, a selected solution script;
compile a list of candidate scripts, the list including the sample solution script and the selected solution script;
optimizing the candidate scripts by replacing at least one command in a candidate script with an alternative command from a command mapping database, wherein the command mapping database comprises at least one entry for a given command, wherein the at least one entry comprises a timestamp denoting the given command has been searched and a lack of an alternative command for the given command in response to searching for the given command in a predefined resource, wherein the at least one entry having the timestamp prevents a redundant search for the given command in the predefined resource;
identify execution rules of each of the candidate scripts;
executing each of the candidate scripts based on the execution rules;
score, based on the simulation and the execution rules, performance of each of the candidate scripts in addressing the problem, resulting in scored candidate scripts; and
present the scored candidate scripts;
wherein the simulating includes: defining a state-transition-reward routine; setting a first set of state checkpoints in a first script included within the candidate scripts; replicating a production environment, resulting in a replicated environment; and executing the first script within the replicated environment, the executing including:
executing a command included in the first script;
detecting a first state checkpoint included within the first set of state checkpoints; and
determining, in response to the detecting, a state of the first script, wherein, for the first script, the scoring is based further on a reward associated with a transition defined in the state-transition-reward routine, the transition associated with the state and a previous state, wherein the reward is a negative value applied to the transition, wherein the scoring comprises summing the negative value for occurrences of the transition to result in a final score for the first script, wherein a second script within the candidate scripts has another final score, wherein the state is one of a plurality of states comprising a ready state, a running state, a waiting state, a completed state, a terminated state, a succeeded state, and a failed state such that the reward is according to the transition among the plurality of states, wherein the negative value for the transition to the waiting state is more negative than the negative value for the transition to the running state, the completed state, or the succeeded state, wherein the negative value for the transition to the terminated state is more negative than the negative value for the transition to the waiting state, wherein the negative value for the transition to the failed state is more negative than the negative value for the transition the terminated state.
8 . The system of claim 7 , wherein the CPU is further configured to:
query, based on the sample solution script, an external resource on the Internet identified in a knowledge base;
receive, in response to the query, one or more found scripts; and
evaluate similarity of the one or more found scripts to the sample solution script, wherein:
the selecting is based on the evaluating; and
the selected solution script is included in a set of found scripts of the one or more found scripts.
9 . The system of claim 8 , wherein, for a first found script included in the set of found scripts, the evaluating includes:
comparing the first found script to the sample solution script; and
calculating, based on the comparing, a similarity score for the first found script, wherein the selecting is based further on the similarity score.
10 . The system of claim 8 , wherein the querying is performed via one or more Natural Language Processing (NLP) techniques based further on information included in a knowledge base.
11 . The system of claim 7 , wherein the CPU is further configured to optimize the candidate scripts, the optimizing including, for a first script included in the candidate scripts:
extracting a first set of commands of the first script, the first set of commands including a first command;
determining that the first command is listed in an entry included in the command mapping database;
identifying, based on the first command and the entry included in the command mapping database, a first preferable alternative command; and
modifying the first script, the modifying including:
removing the first command from the first script; and
inserting the first preferable alternative command into the first script, resulting in a first optimized script.
12 . The system of claim 11 , wherein the optimizing further includes, for a second script included in the candidate scripts:
extracting a second set of commands of the second script, the second set of commands including a second command;
determining that the second command is not listed in the command mapping database;
searching, based on the determining that the second command is not listed in the command mapping database, an external resource for preferable alternative commands;
identifying, based on the searching, a second preferable alternative command;
updating, based on the second preferable alternative command, the command mapping database; and
modifying the second script, the modifying including:
removing the second command from the second script; and
inserting the second preferable alternative command into the second script, resulting in a second optimized script.
13 . A computer program product, the computer program product comprising a computer readable storage medium having program instructions embodied therewith, the program instructions executable by a computer to cause the computer to:
receive a problem statement describing a problem;
receive a sample solution script from a user;
select, based on the sample solution script, a selected solution script;
compile a list of candidate scripts, the list including the sample solution script and the selected solution script;
optimize the candidate scripts by replacing at least one command in a candidate script with an alternative command from a command mapping database, wherein the command mapping database comprises at least one entry for a given command, wherein the at least one entry comprises a timestamp denoting the given command has been searched and a lack of an alternative command for the given command in response to searching for the given command in a predefined resource, wherein the at least one entry having the timestamp prevents a redundant search for the given command in the predefined resource;
identify execution rules of each of the candidate scripts;
execute each of the candidate scripts in a simulation based on the execution rules;
score, based on the simulation and the execution rules, performance of each of the candidate scripts in addressing the problem, resulting in scored candidate scripts; and
present the scored candidate scripts;
wherein the simulating includes: defining a state-transition-reward routine; setting a first set of state checkpoints in a first script included within the candidate scripts; replicating a production environment, resulting in a replicated environment; and executing the first script within the replicated environment, the executing including:
executing a command included in the first script;
detecting a first state checkpoint included within the first set of state checkpoints; and
determining, in response to the detecting, a state of the first script, wherein, for the first script, the scoring is based further on a reward associated with a transition defined in the state-transition-reward routine, the transition associated with the state and a previous state, wherein the reward is a negative value applied to the transition, wherein the scoring comprises summing the negative value for occurrences of the transition to result in a final score for the first script, wherein a second script within the candidate scripts has another final score, wherein the state is one of a plurality of states comprising a ready state, a running state, a waiting state, a completed state, a terminated state, a succeeded state, and a failed state such that the reward is according to the transition among the plurality of states, wherein the negative value for the transition to the waiting state is more negative than the negative value for the transition to the running state, the completed state, or the succeeded state, wherein the negative value for the transition to the terminated state is more negative than the negative value for the transition to the waiting state, wherein the negative value for the transition to the failed state is more negative than the negative value for the transition the terminated state.
14 . The computer program product of claim 13 , wherein the instructions further cause the computer to:
query, based on the sample solution script, an external resource on the Internet identified in a knowledge base;
receive, in response to the query, one or more found scripts; and
evaluate similarity of the one or more found scripts to the sample solution script, wherein:
the selecting is based on the evaluating; and
the selected solution script is included in a set of found scripts of the one or more found scripts.
15 . The computer program product of claim 14 , wherein, for a first found script included in the set of found scripts, the evaluating includes:
comparing the first found script to the sample solution script; and
calculating, based on the comparing, a similarity score for the first found script, wherein the selecting is based further on the similarity score.
16 . The computer program product of claim 13 , wherein the instructions further cause the computer to optimize the candidate scripts, the optimizing including, for a first script included in the candidate scripts:
extracting a first set of commands of the first script, the first set of commands including a first command;
determining that the first command is listed in an entry included in the command mapping database;
identifying, based on the first command and the entry included in the command mapping database, a first preferable alternative command; and
modifying the first script, the modifying including:
removing the first command from the first script; and
inserting the first preferable alternative command into the first script, resulting in a first optimized script.
17 . The computer program product of claim 16 , wherein the optimizing further includes, for a second script included in the candidate scripts:
extracting a second set of commands of the second script, the second set of commands including a second command;
determining that the second command is not listed in the command mapping database;
searching, based on the determining that the second command is not listed in the command mapping database, an external resource for preferable alternative commands;
identifying, based on the searching, a second preferable alternative command;
updating, based on the second preferable alternative command, the command mapping database; and
modifying the second script, the modifying including:
removing the second command from the second script; and
inserting the second preferable alternative command into the second script, resulting in a second optimized script.