def initializeQuantumProgram ( device, sim ):
    
    # *This function contains SDK specific code.*
    # 
    # Input:
    # * *device* - String specifying the device on which the game is played.
    #              Details about the device will be obtained using getLayout.
    # * *sim* - Whether this is a simulated run
    # Process:
    # * Initializes everything required by the SDK for the quantum program. The details depend on which SDK is used.
    # Output:
    # * *q* - Register of qubits (needed by both QISKit and ProjectQ).
    # * *c* - Register of classical bits (needed by QISKit only).
    # * *engine* - Class required to create programs in QISKit, ProjectQ and Forest.
    # * *script* - The quantum program, needed by QISKit and Forest.

    num, area, entangleType, pairs, pos, example, sdk, runs = getLayout(device)
    
    importSDK ( device )
    
    if sdk in ["QISKit","ManualQISKit"]:
        engine = QuantumProgram()
        engine.set_api(Qconfig.APItoken, Qconfig.config["url"]) # set the APIToken and API url
        q = engine.create_quantum_register("q", num)
        c = engine.create_classical_register("c", num)
        script = engine.create_circuit("script", [q], [c]) 
    elif sdk=="ProjectQ":
        engine = projectq.MainEngine()
        q = engine.allocate_qureg( num )
        c = None
        script = None
    elif sdk=="Forest":
        if sim:
            engine = api.QVMConnection(use_queue=True)
        else:
            engine = api.QPUConnection(device)   
        script = Program()
        q = range(num)
        c = range(num)
        
    return q, c, engine, script