Source code for qlauncher.workflow.pilotjob_task
1import json
2import os
3import sys
4from qlauncher import QLauncher
5from qlauncher.routines.qiskit import QAOA, QiskitBackend
6from qlauncher.problems import MaxCut, EC, JSSP, QATM, Problem
7import dill
8
9PROBLEM_DICT: dict[str, type[Problem]] = {
10 'MaxCut': MaxCut,
11 'EC': EC,
12 'JSSP': JSSP,
13 'QATM': QATM
14}
15
16ALGORITHM_DICT = {
17 'QAOA': QAOA,
18}
19
20BACKEND_DICT = {
21 'QiskitBackend': QiskitBackend
22}
23
24
[docs]
25def parse_arguments() -> tuple[QLauncher, str]:
26 """ Returns QLauncher object and output file path """
27 if len(sys.argv) == 3:
28 input_file_path = sys.argv[1]
29 with open(input_file_path, 'rb') as f:
30 launcher = dill.load(f)
31 os.remove(input_file_path)
32 output_path = sys.argv[2]
33 elif len(sys.argv) == 6:
34 problem = PROBLEM_DICT[sys.argv[1]]
35 algorithm = ALGORITHM_DICT[sys.argv[2]]
36 backend = BACKEND_DICT[sys.argv[3]]
37 kwargs = json.loads(sys.argv[4])
38 launcher = QLauncher(problem(**kwargs.get('problem', dict())),
39 algorithm(**kwargs.get('algorithm', dict())),
40 backend(**kwargs.get('backend', dict())))
41 output_path = sys.argv[5]
42 else:
43 raise ValueError(f'Wrong number of arguments, expected 3 or 6 got {len(sys.argv)} instead')
44
45 return launcher, output_path
46
47
[docs]
48def main():
49 launcher, output_path = parse_arguments()
50
51 launcher.run()
52 launcher.save(path=output_path, save_format='pickle')
53
54
55if __name__ == '__main__':
56 main()