Files
TBgen_App/prompt_scripts/__pycache__/base_script.cpython-312.pyc

96 lines
16 KiB
Plaintext
Raw Normal View History

2026-03-30 16:46:48 +08:00
<EFBFBD>
P<>YiV0<00><00><><00>dZddlmZmZmZddlmZmZddlm Z ddl
Z
ddlZ ddl Z dZ ddd <09>Zed
<00>d ed <00><01>Zd dgZGd<0F>d <0A>ZGd<10>d<0E>Zy)z<>
Description : the base script for prompt scripts
Author : Ruidi Qiu (r.qiu@tum.de)
Time : 2024/3/22 10:59:34
LastEdited : 2024/8/12 23:34:35
<EFBFBD>)<03>llm_call<6C> extract_code<64>message_to_conversation)<02>Timer<65>get_time)<01>
autologgerNz<EFBFBD>You are the strongest AI in the world. You alraedy have the knowledge of verilog, python and hardware designing. Do not save words by discarding information. I will tip you 200$ if you can fullfill the tasks I give you.z
```verilogz```)<02>tb_start<72>tb_endr zF
`timescale 1ns / 1ps
(more verilog testbench code here...)
endmodule
r
<00>BaseScriptStage<67>
BaseScriptc<00><><00>eZdZdZdd<03>Zed<04><00>Zed<05><00>Zd<06>Zd<07>Z d<08>Z
d <09>Z d
<EFBFBD>Z d <0B>Z d efd <0A>Zdefd<0F>Zd<10>Zd<11>Zd<12>Zy)r a)
- the base stage for prompt scripts
- the functions that triggered when running:
- make_prompt: make the prompt for gpt (must be implemented)
- call_gpt: call gpt
- postprocessing: postprocessing the response (default is empty)
- gptkwargs: the kwargs for llm_call
- gpt_model: the model name
- api_key_path: the path of gpt key
- sysmessage: (can be ignored) the system message
- json_mode: (can be ignored) the json mode
- temperature: (can be ignored) the temperature
Nc <00>J<00>||_|d|_|d|_|jdt<00>|_|jdd<00>|_|jdd<00>|_d|_d|_ d|_
d|_ i|_ d|_ d|_d |_d|_y)
N<EFBFBD> gpt_model<65> api_key_path<74>system_message<67> json_mode<64> temperature<72><00>z.txtF)<11>
stage_namerr<00>get<65>DEFAULT_SYSMESSAGErrr<00>time<6D>prompt<70>response<73> print_message<67>gptinfo<66>conversation_message<67>conversation_file_suffix<69>reboot<6F> circuit_type)<03>selfr<00> gptkwargss <20>@/home/zhang/CorrectBench/TBgen_App/prompt_scripts/base_script.py<70>__init__zBaseScriptStage.__init__,s<><00><00>$<24><04><0F>"<22>;<3B>/<2F><04><0E>%<25>n<EFBFBD>5<><04><19>'<27>m<EFBFBD>m<EFBFBD>,<<3C>>P<>Q<><04><1B>"<22><1D><1D>{<7B>D<EFBFBD>9<><04><0E>$<24>=<3D>=<3D><1D><04>=<3D><04><18><17><04> <09><18><04> <0B><1A><04> <0A><1F><04><1A><19><04> <0C>$&<26><04>!<21>(.<2E><04>%<25><1B><04> <0B> <20><04><19>c<00><00>t|d<01>ryy)N<> TB_code_outTF<54><01>hasattr<74>r"s r$<00> will_gen_TBzBaseScriptStage.will_gen_TB=s<00><00> <12>4<EFBFBD><1D> '<27><17>r&c<00><00>t|d<01>ryy)N<>Pychecker_code_outTFr)r+s r$<00>will_gen_Pycheckerz"BaseScriptStage.will_gen_PycheckerDs<00><00> <12>4<EFBFBD>-<2D> .<2E><17>r&c<00><><00>td<01><02>5}|j|i|<02><01>ddd<00>j|_|j <00>y#1swY<00>+xYw)NF)<01>print_en)r<00>run<75>intervalr<00>record)r"<00>args<67>kwargs<67>ts r$<00>__call__zBaseScriptStage.__call__KsK<00><00> <12>E<EFBFBD> "<22> &<26>a<EFBFBD> <14>D<EFBFBD>H<EFBFBD>H<EFBFBD>d<EFBFBD> %<25>f<EFBFBD> %<25> &<26><15>J<EFBFBD>J<EFBFBD><04> <09> <0C> <0B> <0B> <0A> <0C>  &<26> &<26>s <00>A
<03>
Ac<00>d<00>|j<00>|j<00>|j<00>y<00>N)<03> make_prompt<70>call_gpt<70>postprocessingr+s r$r2zBaseScriptStage.runRs#<00><00> <0C><18><18><1A> <0C> <0A> <0A><0F> <0C><1B><1B>r&c<00><00>t<00>r:<00><01>NotImplementedErrorr+s r$r;zBaseScriptStage.make_promptWs<00><00>!<21>!r&c<00>`<00>d|jd<02>g}i}|j<00>|j|d<|j<00>|j|d<td||j|j
|j d<06>|<02><01>\|_|_|xjt|jd<00>z c_ y) zX
actually it should be call_llm, but I dont want to modify the old code
<20>user)<02>role<6C>contentNrr)<04>input_messages<65>modelrr<00>messages<65>) rrrrrrrrrrr)r"<00> gpt_messages<65> other_kwargss r$r<zBaseScriptStage.call_gptZs<><00><00>"(<28>D<EFBFBD>K<EFBFBD>K<EFBFBD>@<40>A<> <0C><19> <0C> <0F> <1B> <1B> '<27>*.<2E>*:<3A>*:<3A>L<EFBFBD><1D> '<27> <0F>><3E>><3E> %<25>(,<2C><0E><0E>L<EFBFBD><1B> %<25>&.<2E>'v<02>l<EFBFBD>RV<52>R`<60>R`<60>os<6F>pA<02>pA<02>RV<02>Re<02>Re<02>'v<02>iu<02>'v<02>#<23><04> <0A>t<EFBFBD>|<7C> <0C>!<21>!<21>%<<3C>T<EFBFBD>\<5C>\<5C>*<2A>=U<>%V<>V<>!r&c<00><00>y<01>zempty functionNrHr+s r$r=zBaseScriptStage.postprocessingg<00><00><00> r&c<00>D<00>d|j|jfz|_y)Nz%s ends (%.2fs used))rrrr+s r$r4zBaseScriptStage.recordks<00><00>3<>t<EFBFBD><EFBFBD><EFBFBD><04> <09> <09>6R<36>R<><04>r&<00>configc<00>D<00>tj|j|<01>yr:)<03>ls<6C> save_log_liner)r"rOs r$<00>save_logzBaseScriptStage.save_logos<00><00>
<EFBFBD><18><18><14>+<2B>+<2B>V<EFBFBD>4r&<00>save_dirc<00><00>|jd<01>r|dd}|j|jz}tjj ||<02>}t |d<04>5}|j|j<00>ddd<02>y#1swYyxYw)zrThis function will save the conversation to a file in save_dir. It will be called in stage_operation of BaseScript<70>/N<><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>w) <09>endswithrr<00>os<6F>path<74>join<69>open<65>writer)r"rT<00> file_namer[<00>fs r$<00>save_conversationz!BaseScriptStage.save_conversationrsu<00><00> <13> <1C> <1C>S<EFBFBD> !<21><1F><03><12>}<7D>H<EFBFBD><18>O<EFBFBD>O<EFBFBD>d<EFBFBD>&C<>&C<>C<> <09><11>w<EFBFBD>w<EFBFBD>|<7C>|<7C>H<EFBFBD>i<EFBFBD>0<><04> <11>$<24><03>_<EFBFBD> /<2F><01> <0A>G<EFBFBD>G<EFBFBD>D<EFBFBD>-<2D>-<2D> .<2E> /<2F> /<2F> /<2F>s <00>B<03>B
c<00><00>t||<02><01>S)z<>
#### function:
- extract code from text
#### input:
- text: str, gpt's response
- code_type: str, like "verilog"
#### output:
- list of found code blocks
)<02>text<78> code_type)r)r"rcrds r$rzBaseScriptStage.extract_code<64>s<00><00><1C><14><19>;<3B>;r&c<00><><00>|dxx|jjdi<00>jdd<04>z cc<|dxx|jjdi<00>jdd<04>z cc<|S)Nr<00>usage<67> prompt_tokensr<00>
completion<EFBFBD>completion_tokens)rr)r"<00>tokenss r$<00> update_tokenszBaseScriptStage.update_tokens<6E>se<00><00><0E>x<EFBFBD><18>D<EFBFBD>L<EFBFBD>L<EFBFBD>,<2C>,<2C>W<EFBFBD>b<EFBFBD>9<>=<3D>=<3D>o<EFBFBD>q<EFBFBD>Q<>Q<><18><0E>|<7C><1C><04> <0C> <0C> 0<> 0<><17>"<22> =<3D> A<> A<>BU<42>WX<57> Y<>Y<><1C><15> r&c<00>4<00>|xj|dzz c_y)N<>
)r)r"rs r$<00>add_prompt_linezBaseScriptStage.add_prompt_line<6E>s<00><00> <0C> <0B> <0B>v<EFBFBD><04>}<7D>$<24> r&)<02>returnN)<15>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__r%<00>propertyr,r/r8r2r;r<r=r4<00>objectrS<00>strrarrkrnrHr&r$r r s{<00><00> <08>!<21>"<0E><19><0E><19> <0E><19><0E><19>  <0A><1E>
"<22> W<01> <0A>S<01>5<>f<EFBFBD>5<>/<2F><13>/<2F>*
<<3C><16>
%r&c<00><><00>eZdZdZdedededdfd<07>Zed<08><00>Z ed <09><00>Z
d
<EFBFBD>Z d <0B>Z d <0C>Z d <0A>Zd<0E>Zddefd<10>Zddededefd<14>Zdd<15>Zd<16>Zdd<17>Zd<18>Zd<19>Z defd<1B>Zy)r a
the base class for prompt scripts
- the functions that triggered when running:
- make_and_run_stages: make and run stages (must be implemented)
- postprocessing: postprocessing the response (default is empty)
- save_codes: save the generated codes
<20> prob_data<74>task_dirrOroNc<00><><00>g|_|jd<01>s|n|dd|_||_|jjj
|jjj d<03>|_||_d|_ tjj|jd<05>|_ |ddz|_d|_|ddz|_|dd z|_|d
d z|_g|_d d d <0A>|_d|_d|_g|_d|_d|_d|_tj6|jd<11><12>d|_d|_y)NrVrW)rrr<00> TBgen_codes<65>task_idz_tb.vz_tb.pyz.v<>headerz
endmodule
r<00>rrhr<00>TBFT<46><01>exist_ok)<1E>stagesrYryrO<00>gptrF<00>key_pathr#rx<00>TB_coderZr[r\<00> TB_code_dir<69> TB_code_name<6D>Pychecker_code<64>Pychecker_code_name<6D>empty_DUT_name<6D> empty_DUT<55>stages_gencoderjr<00>
reboot_idx<EFBFBD> reboot_stages<65> reboot_mode<64>py_debug_focus<75>checklist_worked<65>makedirs<72> scenario_num<75> scenario_dict)r"rxryrOs r$r%zBaseScript.__init__<5F>s8<00><00><18><04> <0B>(0<>(9<>(9<>#<23>(><3E><08>H<EFBFBD>S<EFBFBD>b<EFBFBD>M<EFBFBD><04> <0A><1C><04> <0B><1D><1B><1B><1F><1F>.<2E>.<2E> <20>K<EFBFBD>K<EFBFBD>O<EFBFBD>O<EFBFBD>4<>4<>
<EFBFBD><04><0E>#<23><04><0E><19><04> <0C><1D>7<EFBFBD>7<EFBFBD><<3C><<3C><04> <0A> <0A>}<7D>E<><04><18>%<25>i<EFBFBD>0<>7<EFBFBD>:<3A><04><19> <20><04><1B>#,<2C>Y<EFBFBD>#7<>(<28>#B<><04> <20>'<27> <09>2<>T<EFBFBD>9<><04><1B>"<22>8<EFBFBD>,<2C>/@<40>@<40><04><0E> <20><04><1B>!"<22>!<21>4<><04> <0B><17><04> <09><1C><04><0F><1F><04><1A><1F><04><18>#<23><04><1B> %<25><04><1D>
<EFBFBD> <0B> <0B>D<EFBFBD>$<24>$<24>t<EFBFBD>4<> <20><04><19>!<21><04>r&c<00>$<00>|jdk7ryy)NrTF)r<>r+s r$<00> Pychecker_enzBaseScript.Pychecker_en<65>s<00><00> <0F> <1E> <1E>"<22> $<24><17>r&c<00><00>|jSr:)r<>r+s r$<00>Pychecker_code_dirzBaseScript.Pychecker_code_dir<69>s<00><00><13><1F><1F>r&c<00>(<00>|j|i|<02><01>yr:<00>r2<00>r"r5r6s r$r8zBaseScript.__call__<5F>s<00><00><10><04><08><08>$<24>!<21>&<26>!r&c<00><><00>|j<00>|j<00>|j<00>|j<00>yr:)<04>make_and_run_stages<65>compute_time_tokensr=<00>
save_codesr+s r$r2zBaseScript.run<75>s0<00><00> <0C> <20> <20>"<22> <0C> <20> <20>"<22> <0C><1B><1B><1D> <0C><0F><0F>r&c<00><00>td<01><00>)z<>
- in this function, you should make stages and run them
- for example:
::
stage1 = Stage1(**kwargs)
self.stage_operation(stage1)
zMNo make_and_run_stages: You should implement this function in your own scriptr?r+s r$r<>zBaseScript.make_and_run_stages<65>s<00><00>"<22>"q<>r<>rr&c<00><00>td<01><00>)NzINo reboot settings: You should implement this function in your own scriptr?)r"<00> debug_dirs r$<00>make_and_run_reboot_stagesz%BaseScript.make_and_run_reboot_stages<65>s<00><00>!<21>"m<>n<>nr&c<00><00>yrLrHr+s r$r=zBaseScript.postprocessing<6E>rMr&<00> codes_dirc<00><><00>|<01> |j}tj|d<01><02>tjj ||j
<00>}t |d<03>5}|j|j<00>ddd<00>tjj ||j<00>}t |d<03>5}|j|j<00>ddd<00>|jr[tjj ||j<00>}t |d<03>5}|j|j<00>ddd<00>yy#1swY<00><>xYw#1swY<00>}xYw#1swYyxYw)NTr<54>rX)r<>rZr<>r[r\r<>r]r^r<>r<>r<>r<>r<>r<>)r"r<><00> TB_code_pathr`<00>empty_DUT_path<74>Pychecker_code_paths r$r<>zBaseScript.save_codes<65>s<00><00> <14> <1C><1C>(<28>(<28>I<EFBFBD>
<EFBFBD> <0B> <0B>I<EFBFBD><04>-<2D><19>w<EFBFBD>w<EFBFBD>|<7C>|<7C>I<EFBFBD>t<EFBFBD>/@<40>/@<40>A<> <0C> <11>,<2C><03> $<24> "<22><01> <0A>G<EFBFBD>G<EFBFBD>D<EFBFBD>L<EFBFBD>L<EFBFBD> !<21> "<22><1B><17><17><1C><1C>i<EFBFBD><14>1D<31>1D<31>E<><0E> <11>.<2E>#<23> &<26> $<24>!<21> <0A>G<EFBFBD>G<EFBFBD>D<EFBFBD>N<EFBFBD>N<EFBFBD> #<23> $<24> <10> <1C> <1C>"$<24>'<27>'<27>,<2C>,<2C>y<EFBFBD>$<24>:R<>:R<>"S<> <1F><15>)<29>3<EFBFBD>/<2F> -<2D>1<EFBFBD><11><07><07><04>+<2B>+<2B>,<2C> -<2D> -<2D> <1D>  "<22> "<22><> $<24> $<24><>
 -<2D> -<2D>s$<00>E<03>6E<03>E<03>E <07>E<07>E#<07>stage<67>conversation_dir<69> reboot_enc<00><><00>|<02> |j}|<01>|r)|j|jj|<01>n|jj|<01>|j |<02>|j |j<00>|jr|j|_
|jr|j|_ t|d<02>r|j|_yy)z<>
- what to do on a stage after making it; will be called in make_and_run_stages
- run, save stages and renew the generated codes of current wf
N<> TB_modified)ryr<>r<><00>appendr<64>rarSrOr,r(r<>r/r.r<>r*r<>r<>)r"r<>r<>r<>s r$<00>stage_operationzBaseScript.stage_operation<6F>s<><00><00>
<1C> #<23>#<23>}<7D>}<7D> <1C> <0A><07> <14> <10> <1E> <1E>t<EFBFBD><EFBFBD><EFBFBD> /<2F> 6<> 6<>u<EFBFBD> =<3D> <10>K<EFBFBD>K<EFBFBD> <1E> <1E>u<EFBFBD> %<25> <0A><1F><1F> 0<>1<> <0A><0E><0E>t<EFBFBD>{<7B>{<7B>#<23> <10> <1C> <1C> <20>,<2C>,<2C>D<EFBFBD>L<EFBFBD> <10> #<23> #<23>"'<27>":<3A>":<3A>D<EFBFBD> <1F> <12>5<EFBFBD>-<2D> (<28>$)<29>$5<>$5<>D<EFBFBD> !<21> )r&c<00>d<00>|xjdz c_|jjg<00>d|_||_|j d<03>r|ddn|}|j |<01>|j|j|j<00>|j<00>|j|<01>y)z*
- regenerate the TB code
<20>rrVNrW)
r<EFBFBD>r<>r<>r<>r<>rYr<>r<>r=r<>)r"r<>r<>s r$<00>
run_rebootzBaseScript.run_reboots<><00><00> <0A><0F><0F>1<EFBFBD><1C><0F> <0C><1A><1A>!<21>!<21>"<22>%<25><19><04> <0C>&<26><04><18>&/<2F>&8<>&8<><13>&=<3D>I<EFBFBD>c<EFBFBD>r<EFBFBD>N<EFBFBD>9<EFBFBD> <09> <0A>'<27>'<27> <09>2<> <0C> <20> <20><14>!3<>!3<>D<EFBFBD>O<EFBFBD>O<EFBFBD>!D<>E<> <0C><1B><1B><1D> <0C><0F><0F> <09>"r&c<00>&<00>d|_ddd<03>|_y)Nrrr~)rrjr+s r$<00>clear_time_tokenszBaseScript.clear_time_tokens(s<00><00><17><04> <09>!"<22>!<21>4<><04> r&c<00><><00>|<01> |j}|D]A}|xj|jz c_|j|j<00>|_<00>Cyr:)r<>rrkrj)r"r<>r<>s r$r<>zBaseScript.compute_time_tokens,sG<00><00> <11>><3E><19>[<5B>[<5B>F<EFBFBD><1B> ;<3B>E<EFBFBD> <10>I<EFBFBD>I<EFBFBD><15><1A><1A> #<23>I<EFBFBD><1F>-<2D>-<2D>d<EFBFBD>k<EFBFBD>k<EFBFBD>:<3A>D<EFBFBD>K<EFBFBD> ;r&c<00>.<00>tj|<01>yr:)r<00>info)r"<00>lines r$rSzBaseScript.save_log3s<00><00><12><0F><0F><04>r&c<00>(<00>|j|i|<02><01>yr:r<>r<>s r$r8zBaseScript.__call__7s<00><00><10><04><08><08>$<24>!<21>&<26>!<21> r&<00> attr_namec<00>4<00>t||<01>r t||<01>Syr:)r*<00>getattr)r"r<>s r$<00>get_attrzBaseScript.get_attr;s<00><00> <12>4<EFBFBD><19> #<23><1A>4<EFBFBD><19>+<2B> +<2B>r&r:)NF)r)rprqrrrs<00>dictrvrur%rtr<>r<>r8r2r<>r<>r=r<>r <00>boolr<6C>r<>r<>r<>rSr<>rHr&r$r r <00>s<><00><00><08>"<22><14>"<22><03>"<22>F<EFBFBD>"<22>t<EFBFBD>"<22>8<0E><19><0E><19> <0E> <20><0E> <20>"<22><1A> s<01>o<01> <0A>-<2D>3<EFBFBD>-<2D> 6<>O<EFBFBD>6<>c<EFBFBD>6<>Z^<5E>6<>4#<23>25<>;<3B><1E> <0A><18><13>r&)rs<00>LLM_callrrr<00> utils.utilsrr<00> loader_saverrrZrQ<00>copyr<00>
IDENTIFIER<EFBFBD>TESTBENCH_TEMPLATE<54>__all__r r rHr&r$<00><module>r<>sx<00><01><04>E<01>D<>'<27>#<23> <09><19> <0B>s<03><12><1E><14><02>
<EFBFBD>
<14>J<EFBFBD> <1F><1A>H<EFBFBD>!5<> 7<><12> <1D>l<EFBFBD>
+<2B><07>{%<25>{%<25>zd<18>dr&