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 foldermentioned 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.jsand 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 2inINSTALL.mdto 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.jsand the source map attarget.rawchatgpt.js.srcmap. -
Copy those two files to
target.fixed.jsandtarget.fixed.js.srcmap. Then, open the TransMap UI for Case Studies (mentioned in INSTALLATION). Choose_playgroundin the drop-down menu at the top. ClickLoad (Case Study). -
Then, click
(0) Testto check if the code can run. If it shows that there is aMyLogError MISMATCHerror, it indicates that there is a hidden semantic mistake in the translated code. You can clickAUTO-Iterateto 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:
