Source code for quantum_launcher.workflow.pilotjob_task

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