To apply TransMap to your own Python program, you need to prepare the following files (you can look at the example at data/transmap/tests/evalex/real/py_js_codex0err/_playgound
).
You need to prepare these two files at least:
source.py
: The Python program to be translated.target_tmpl.js
: The JavaScript program template used for generating the translationtarget.js
.
NOTE: If you put the tests in source.py
and target_tmpl.js
: as _playground
does, you don't need to modify source_test.py
and target_test.py
and you can ignore these two files.
-
First go to the
_playground folder
mentioned above. -
Open
source.py
. There are multiple segments in the file. -
Put some Python code in
my_second_segment
. For example,
##### Segment BEGIN my_second_segment
def accumulate_list(ls):
return []
acc_list = []
acc = 0
for x in ls:
acc += x
acc_list.append(acc)
return acc_list
##### Segment END
- Then, add test code on line 48:
assert_iter_almost_equal(accumulate_list([1, 2, 3, 4, 5]), [1, 3, 6, 10, 15])
- Then, open
target_tmpl.js
and add the same test on line 48:
assertIterAlmostEqual(accumulate_list([1, 2, 3, 4, 5]), [1, 3, 6, 10, 15]);
-
Open a shell under
data/transmap/cases/
. Check the content ofopenai.key
. It should be a valid OpenAI API key. If not, please refer toAdditional Requirements 2
inINSTALL.md
to set up the API key. -
Run the following commands under
data/transmap/cases/
:
python3 ./classic_translate.py playground
python3 ./classic_srcmapping.py playground
-
Then, you should be able to see the translated JavaScript at
target.rawchatgpt.js
and the source map attarget.rawchatgpt.js.srcmap
. -
Copy those two files to
target.fixed.js
andtarget.fixed.js.srcmap
. Then, open the TransMap UI for Case Studies (mentioned in INSTALLATION). Choose_playground
in the drop-down menu at the top. ClickLoad (Case Study)
. -
Then, click
(0) Test
to check if the code can run. If it shows that there is aMyLogError MISMATCH
error, it indicates that there is a hidden semantic mistake in the translated code. You can clickAUTO-Iterate
to use TransMap to find the bug.
NOTE: If the translated code already pass the test, you can either find a more challenging Python program or manually introduce a hidden semantic mistake to check if TransMap works. For example, you can change the acc += ls[i];
in the JavaScript translation into acc += i;
and TransMap should be able to highlight this line: