<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def rate_to_mcs(rate, bw=20, long_gi=True):
 """Convert bit rate to MCS index. Args: rate (float):
 bit rate in Mbps long_gi (bool):
 True if long GI is used. Returns: mcs (int):
 MCS index 5 """

    if bw not in [20, 40, 80, 160]:
        raise Exception("Unknown bandwidth: %d MHz" % (bw))
    idx = int((math.log(bw/10, 2)-1)*2)
    if not long_gi:
        idx += 1

    for mcs, rates in MCS_TABLE.items():
        if abs(rates[idx] - rate) < 1e-3:
            return mcs

    # failed. Try dot11a rates
    for idx, r in enumerate(DOT11A_RATES):
        if abs(r-rate) < 1e-3:
            return idx

    raise Exception("MCS not found: rate=%f, bw=%d, long_gi=%s" %
                    (rate, bw, long_gi))