예제 #1
0
    def test_TLE(self):
        tle_code = """
            #include <iostream>
            using namespace std;
            int main() {
                int a, b;
                cin >> a >> b;
                while(true){
                    a += b;
                }
                cout << a + b << endl;
                return 0;
            }
"""
        submitted_executor = get_executor(self.submission_lang, tle_code,
                                          f'{self.submission_dir}/submitted')
        result = do_judge(
            {
                "submit_id": 1,
                "problem_id": 1,
                "time_limit": 1111,
                "memory_limit": 262144,
                "checker_type": "icmp",
            }, self.submission_dir, submitted_executor)

        self.assertEqual(result["verdict"],
                         VerdictResult.TLE,
                         msg=result['desc'])
예제 #2
0
    def test_MLE(self):
        mle_code = """
            #include <iostream>
            int f**k[3000000];
            int dick[3000000];
            using namespace std;
            int main() {
                int a, b;
                cin >> a >> b;
                for(int i = 0;i < 3000000;i++)
                { f**k[i] = i;
                dick[i] = i;}
                cout << a + b << endl;
                return 0;
            }
"""
        submitted_executor = get_executor(self.submission_lang, mle_code,
                                          f'{self.submission_dir}/submitted')
        result = do_judge(
            {
                "submit_id": 1,
                "problem_id": 1,
                "time_limit": 10011,
                "memory_limit": 26072,
                "checker_type": "icmp",
            }, self.submission_dir, submitted_executor)

        self.assertEqual(result["verdict"],
                         VerdictResult.MLE,
                         msg=result['desc'])
예제 #3
0
    def test_WA(self):
        wa_code = """
            #include <iostream>
            using namespace std;
            int main() {
                int a, b;
                cin >> a >> b;
                cout << a + b + 2 << endl;
                return 0;
            }
"""
        submitted_executor = get_executor("GXX", wa_code,
                                          f'{self.submission_dir}/submitted')
        result = do_judge(
            {
                "submit_id": 1,
                "problem_id": 1,
                "time_limit": 1000,
                "memory_limit": 262144,
                "checker_type": "icmp",
            }, self.submission_dir, submitted_executor)

        self.assertEqual(result['verdict'],
                         VerdictResult.WA,
                         msg=result['desc'])
예제 #4
0
def judge_submission(**submit_detail):
    submitted_code = submit_detail["submitted_code"]
    submitted_lang = submit_detail['submitted_lang']
    submit_id = submit_detail['submit_id']

    result = {
        "verdict": VerdictResult.SE,
        "desc": "",
        "time_usage": 0,
        "memory_usage": 0,
        "outputs": [],
    }

    try:
        submission_dir = f'{conf.SUBMISSION_DIR}/{submit_id}'
        try:
            submitted_executor = get_executor(submitted_lang, submitted_code,
                                              f'{submission_dir}/submitted')
        except ExecutorInitException as e:
            result['verdict'] = VerdictResult.CE
            result['desc'] = str(e)
            return result
        result = do_judge(submit_detail, submission_dir, submitted_executor)
    except Exception as ex:
        result['desc'] = str(ex)
        raise
    finally:
        result = {'submit_id': submit_id, 'result': json.dumps(result)}
        send_result_back(conf.RESULT_API_URL, result)
예제 #5
0
    def test_TLE(self):
        tle_code = """
#include<stdio.h>
int main() {
    int a, b;
    scanf("%d%d",&a,&b);
    while(1) {a+=b;}
    printf("%d",a+b);
    return 0;
}
"""
        submitted_executor = get_executor(self.submission_lang, tle_code,
                                          f'{self.submission_dir}/submitted')
        result = do_judge(
            {
                "submit_id": 1,
                "problem_id": 1,
                "time_limit": 1111,
                "memory_limit": 262144,
                "checker_type": "icmp",
            }, self.submission_dir, submitted_executor)

        self.assertEqual(result["verdict"],
                         VerdictResult.TLE,
                         msg=result['desc'])
예제 #6
0
    def test_TLE(self):
        tle_code = """
import java.util.Scanner;
import java.util.*;
public class Solution {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt(),b=sc.nextInt();
        ArrayList<Integer> arr = new ArrayList<Integer>();
        int t = 20000000;
        for (int i = 0; i < t; ++i) {
            arr.add(1);
            arr.remove(arr.size() - 1);
        }
        System.out.println(a+b);
    }
}
"""
        submitted_executor = get_executor(self.submission_lang, tle_code, f'{self.submission_dir}/submitted')
        result = do_judge({
            "submit_id": 1,
            "problem_id": 1,
            "time_limit": 100,
            "memory_limit": 262144,
            "checker_type": "icmp",
        }, self.submission_dir, submitted_executor)
        self.assertEqual(result['verdict'], VerdictResult.TLE, msg=result['desc'])
예제 #7
0
    def test_OLE(self):
        ole_code = f"""
                    #include <stdio.h>
                    int main() {{
                        int a, b;
                        scanf("%d%d",&a,&b);
                        for(int i = 0;i < 729145;i++)
                            printf("%s","{'A' * 100}");
                            
                        return 0;
                    }}
"""
        submitted_executor = get_executor(self.submission_lang, ole_code,
                                          f'{self.submission_dir}/submitted')
        result = do_judge(
            {
                "submit_id": 1,
                "problem_id": 1,
                "time_limit": 22222,
                "memory_limit": 262144,
                "checker_type": "icmp",
            }, self.submission_dir, submitted_executor)

        self.assertEqual(result["verdict"],
                         VerdictResult.OLE,
                         msg=result['desc'])
예제 #8
0
    def test_MLE(self):
        mle_code = """
            #include <stdio.h>
            int f**k[3500000];
            int dick[3500000];
            int main() {
                int a, b;
                scanf("%d%d",&a,&b);
                for(int i = 0;i < 3500000;i++)
                { f**k[i] = i;
                dick[i] = i;}
                printf("%d",f**k[1]+dick[1]);
                return 0;
            }
"""
        submitted_executor = get_executor(self.submission_lang, mle_code,
                                          f'{self.submission_dir}/submitted')
        result = do_judge(
            {
                "submit_id": 1,
                "problem_id": 1,
                "time_limit": 10011,
                "memory_limit": 28072,
                "checker_type": "icmp",
            }, self.submission_dir, submitted_executor)

        self.assertEqual(result["verdict"],
                         VerdictResult.MLE,
                         msg=f"{result}\n{result['desc']}")
예제 #9
0
    def test_SJ(self):
        sj_code = """
#include "testlib.h"
#include <stdio.h>

int main(int argc, char * argv[])
{
    setName("compare two signed int%d's", 8 * int(sizeof(int)));
    registerTestlibCmd(argc, argv);
    
    int ja = ans.readInt();
    int pa = ouf.readInt();
    
    if (ja != pa)
        quitf(_wa, "expected %d, found %d", ja, pa);
    
    quitf(_ok, "answer is %d", ja);
}
"""
        ac_code = """
                #include <iostream>
                using namespace std;
                int main() {
                    int a, b;
                    cin >> a >> b;
                    cout << a + b<< endl;
                    return 0;
                }
        """

        sj_name = 'test_checker'
        log_file_path = f'{conf.LOG_DIR}/sj_{sj_name}.log'

        result = create_special_judge(sj_code, sj_name, log_file_path)
        self.assertEqual(result['result'],
                         VerdictResult.AC,
                         msg=result['desc'])

        submitted_executor = get_executor("GXX", ac_code,
                                          f'{self.submission_dir}/submitted')
        result = do_judge(
            {
                "submit_id": 1,
                "problem_id": 1,
                "time_limit": 1000,
                "memory_limit": 262144,
                "checker_type": sj_name,
            }, self.submission_dir, submitted_executor)
        self.assertEqual(result['verdict'],
                         VerdictResult.AC,
                         msg=result['desc'])
예제 #10
0
    def test_CE(self):
        ce_code = """
        import java.util.Scanner;
        public class Solution {
            public static void main(String[] args) {
                Scanner sc=new Scanner(System.in);
                int a=sc.nextInt(),b=sc.nextInt()
                System.out.println(a+b+1);
            }
        }
"""
        with self.assertRaises(exceptions.ExecutorInitException) as cm:
            submitted_executor = get_executor(self.submission_lang, ce_code, f'{self.submission_dir}/submitted')
            print(cm.exception, flush=True)
예제 #11
0
    def test_AC(self):
        ac_code = """
a = input().split()
print(int(a[0]) + int(a[1]))
"""
        submitted_executor = get_executor(self.submission_lang, ac_code, f'{self.submission_dir}/submitted')
        result = do_judge({
            "submit_id": 1,
            "problem_id": 1,
            "time_limit": 1000,
            "memory_limit": 262144,
            "checker_type": "icmp",
        }, self.submission_dir, submitted_executor)
        self.assertEqual(result['verdict'], VerdictResult.AC, msg=result['desc'])
예제 #12
0
    def test_OLE(self):
        ole_code = f"""
a = input().split()
for i in range(0, 729145):
    print("{'A' * 100}")
"""
        submitted_executor = get_executor(self.submission_lang, ole_code, f'{self.submission_dir}/submitted')
        result = do_judge({
            "submit_id": 1,
            "problem_id": 1,
            "time_limit": 22222,
            "memory_limit": 262144,
            "checker_type": "icmp",
        }, self.submission_dir, submitted_executor)

        self.assertEqual(result['verdict'], VerdictResult.OLE, msg=result['desc'])
예제 #13
0
    def test_WA(self):
        wa_code = """
        import java.util.Scanner;
        public class Solution {
            public static void main(String[] args) {
                Scanner sc=new Scanner(System.in);
                int a=sc.nextInt(),b=sc.nextInt();
                System.out.println(a+b+1);
            }
        }
"""
        submitted_executor = get_executor(self.submission_lang, wa_code, f'{self.submission_dir}/submitted')
        result = do_judge({
            "submit_id": 1,
            "problem_id": 1,
            "time_limit": 5000,
            "memory_limit": 262144,
            "checker_type": "icmp",
        }, self.submission_dir, submitted_executor)
        self.assertEqual(result['verdict'], VerdictResult.WA, msg=result['desc'])
예제 #14
0
    def test_CE(self):
        ce_code = """
            #include <iostream>
            int f**k[60000000000];
            using namespace std;
            int main() {
                int a, b;
                cin >> a >> b;
                for(int i = 0;i < 60050000000;i++)
                { f**k[i] = i;
               }
                cout << a + b << endl;
                return 0;
            }
"""
        with self.assertRaises(exceptions.ExecutorInitException) as cm:
            submitted_executor = get_executor(
                self.submission_lang, ce_code,
                f'{self.submission_dir}/submitted')
            print(cm.exception, flush=True)
예제 #15
0
    def test_CE(self):
        ce_code = """
            #include <stdio.h>
            int f**k[3500000];
            int dick[3500000];
            int main() {
                int a, b;
                scanf("%d%d",&a,&b);
                for(int i = 0;i < 4000000;i++)
                { f**k[i] = i
                dick[i] = i;}
                printf("%d",f**k[1]+dick[1]);
                return 0;
            }
"""
        with self.assertRaises(exceptions.ExecutorInitException) as cm:
            submitted_executor = get_executor(
                self.submission_lang, ce_code,
                f'{self.submission_dir}/submitted')
            print(cm.exception, flush=True)
예제 #16
0
def check_solution_and_checker(**detail):
    solution_code = detail['solution_code']
    solution_lang = detail['solution_lang']
    problem_id = detail['problem_id']
    time_limit = detail['time_limit']
    memory_limit = detail['memory_limit']
    channel_name = detail['channel_name']

    problem_dir = f'problems/{problem_id}'

    result = {
        'solution': {},
        'special_judge': {},
    }

    try:
        try:
            solution_executor = get_executor(solution_lang, solution_code,
                                             f'{problem_dir}/solution')
            result['solution'] = get_solution_answers(problem_dir,
                                                      solution_executor,
                                                      time_limit, memory_limit)
        except ExecutorInitException as e:
            result['solution']['verdict'] = VerdictResult.CE
            result['solution']['desc'] = str(e)

        sj_code = detail.get('sj_code')
        sj_name = detail.get('sj_name')
        if sj_code is not None:
            log_file_path = f'{conf.LOG_DIR}/sj_{sj_name}.log'
            result['special_judge'] = create_special_judge(
                sj_code, sj_name, log_file_path)  # compile here
    finally:
        result = {
            'problem_id': problem_id,
            'channel_name': channel_name,
            'result': json.dumps(result)
        }
        send_result_back(conf.SJ_RESULT_API_URL, result)
예제 #17
0
    def test_WA(self):
        wa_code = """
           #include<stdio.h>
int main() {
    int a, b;
    scanf("%d%d",&a,&b);
    printf("%d",a+b+1);
    return 0;
}
"""
        submitted_executor = get_executor(self.submission_lang, wa_code,
                                          f'{self.submission_dir}/submitted')
        result = do_judge(
            {
                "submit_id": 1,
                "problem_id": 1,
                "time_limit": 1000,
                "memory_limit": 262144,
                "checker_type": "icmp",
            }, self.submission_dir, submitted_executor)

        self.assertEqual(result['verdict'],
                         VerdictResult.WA,
                         msg=result['desc'])
예제 #18
0
    def test_OLE(self):
        ole_code = f"""
                       import java.util.Scanner;
                       public class Solution {{
                           public static void main(String[] args) {{
                               Scanner sc=new Scanner(System.in);
                               int a=sc.nextInt(),b=sc.nextInt();
                               int t = 729145;
                               for (int i = 0; i < t; ++i) {{
                                 System.out.println("{'A' * 100}");
                               }}

                           }}
                       }}
"""
        submitted_executor = get_executor(self.submission_lang, ole_code, f'{self.submission_dir}/submitted')
        result = do_judge({
            "submit_id": 1,
            "problem_id": 1,
            "time_limit": 22222,
            "memory_limit": 262144,
            "checker_type": "icmp",
        }, self.submission_dir, submitted_executor)
        self.assertEqual(result['verdict'], VerdictResult.OLE, msg=result['desc'])
예제 #19
0
파일: run_train.py 프로젝트: zaynmi/ns-vqa
import sys
sys.path.append("/home/tang/ns-vqa-master/reason")
from options.train_options import TrainOptions
from datasets import get_dataloader
from executors import get_executor
from models.parser import Seq2seqParser
from trainer import Trainer

opt = TrainOptions().parse()
train_loader = get_dataloader(opt, 'train')
val_loader = get_dataloader(opt, 'val')
model = Seq2seqParser(opt)
executor = get_executor(opt)
trainer = Trainer(opt, train_loader, val_loader, model, executor)

trainer.train()
예제 #20
0
            wandb.log({k: v}, step=t)
            # wandb.log({k: v, 'global_step': 1})
        # checkpoint.update(result)
        checkpoint['result'] = result
        json_fp = os.path.join(opt.run_dir,
                               f'test_opt_{opt.run_timestamp}.json')
        with open(json_fp, 'w') as f:
            json.dump(checkpoint, f, indent=2)
        wandb.save(json_fp)
        #os.remove(json_fp)


opt = TestOptions().parse()
opt.is_train = False
loader = get_dataloader(opt, 'val')
executor = get_executor(opt, graph_parser=graph_parser, embedder=embedder)
model = Seq2seqParser(opt)

logging.debug('| running test')
stats = {
    'count': 0,
    'count_tot': 0,
    'exist': 0,
    'exist_tot': 0,
    'compare_num': 0,
    'compare_num_tot': 0,
    'compare_attr': 0,
    'compare_attr_tot': 0,
    'query': 0,
    'query_tot': 0,
    'correct_ans': 0,