CBox.upload_standard_weights(modulation_frequency)

LutMan.Q_modulation(modulation_frequency)
LutMan.Q_gauss_width(10e-9)
LutMan.Q_amp180(0.2513)
LutMan.Q_amp90(LutMan.Q_amp180()/2)

LutMan.lut_mapping(['I', 'X180', 'Y180', 'X90', 'Y90', 'mX90', 'mY90',
                    'M_square'])
LutMan.M_modulation(modulation_frequency)
LutMan.M_amp(0.2)
LutMan.M_length(600e-9)

LutMan.load_pulses_onto_AWG_lookuptable(0)

gen.load_settings_onto_instrument(AncT_CB)


op_dict = AncT_CB.get_operation_dict()


try:
    qxc = qx.qx_client()
    QX_Server_IP = "192.168.56.101"
    QX_Server_Port = 5555
    qxc.connect(QX_Server_IP, QX_Server_Port)
    qxc.create_qubits(2)

except Exception as e:
    logging.warning('Could not connect to QX simulator')
    logging.warning(e)
                                              FluxCtrl=Flux_Control,
                                              MC=MC,
                                              server_name=None)
station.add_component(DataM)
DataT = qbt.Tektronix_driven_transmon('DataT', LO=LO, cw_source=Spec_source,
                                              td_source=Qubit_LO,
                                              IVVI=IVVI, rf_RO_source=RF,
                                              AWG=AWG,
                                              heterodyne_instr=HS,
                                              FluxCtrl=Flux_Control,
                                              MC=MC,
                                              server_name=None)
station.add_component(DataT)

# load settings onto qubits
gen.load_settings_onto_instrument(AncB)
gen.load_settings_onto_instrument(AncT)
gen.load_settings_onto_instrument(DataB)
gen.load_settings_onto_instrument(DataM)
gen.load_settings_onto_instrument(DataT)
gen.load_settings_onto_instrument(HS)

DataT.E_c(0.28e9)
DataT.asymmetry(0)
DataT.dac_flux_coefficient(0.0016813942523375956)
DataT.dac_sweet_spot(-53.472554718672427)
DataT.f_max(5.688884012383026e9)
DataT.f_qubit_calc('flux')

AncB.E_c(0.28e9)
AncB.asymmetry(0)
station.add_component(QL)

# Bus_m = qbt.Tektronix_driven_transmon('Bus_m', LO=LO, cw_source=None,
#                                               td_source=QR_LO,
#                                               IVVI=IVVI, rf_RO_source=RF,
#                                               AWG=AWG,
#                                               heterodyne_instr=HS,
#                                               MC=MC,
#                                               FluxCtrl=Flux_Control,
#                                               server_name=None)
# station.add_component(Bus_m)

# # load settings onto qubits
# gen.load_settings_onto_instrument(QL)
# gen.load_settings_onto_instrument(QR)
gen.load_settings_onto_instrument(QL, load_from_instr='QL_QWG')
# gen.load_settings_onto_instrument(QL_CB)
# gen.load_settings_onto_instrument(HS)
# gen.load_settings_onto_instrument(Bus_m)

nested_MC = mc.MeasurementControl('nested_MC')
nested_MC.station = station

# The AWG sequencer
# station.pulsar = ps.Pulsar()
# station.pulsar.AWG = station.components['AWG']
# marker1highs=[2,2,2.7,2]
# for i in range(4):
#     # Note that these are default parameters and should be kept so.
#     # the channel offset is set in the AWG itself. For now the amplitude is
#     # hardcoded. You can set it by hand but this will make the value in the
w0 = np.round(cosI*120)
w1 = np.round(sinI*120)

CBox.set_integration_weights(line=0, weights=w0)
CBox.set_integration_weights(line=1, weights=w1)
CBox.set_averaging_parameters(70, 11)
print("CBox initialized")

CBox_lut_man = qt.instruments.create(
    'CBox_lut_man', 'QuTech_ControlBox_LookuptableManager')

CBox_lut_man_2 = qt.instruments.create(
    'CBox_lut_man_2', 'QuTech_ControlBox_LookuptableManager')

# Reload the settings
gen.load_settings_onto_instrument(CBox_lut_man)
gen.load_settings_onto_instrument(CBox_lut_man_2)

# switching on pulsemode
RF.set_pulsemod_state('ON')
RF.set_parameter_bounds('power', -120, 20)

print("pulsed RF on")
HS = qt.instruments.create('HS', 'HeterodyneSource',
                           RF='RF', LO='LO', IF=.01)

ATT = qt.instruments.create('ATT', 'Aeroflex_8320', address='TCPIP0::192.168.0.98')

# print 'Initializing Signal Hound'
SH = qt.instruments.create('SH', 'SignalHound_USB_SA124B')
                                              MC=MC,
                                              FluxCtrl=Flux_Control,
                                              server_name=None)
station.add_component(QL)
QR = qbt.Tektronix_driven_transmon('QR', LO=LO, cw_source=Spec_source,
                                              td_source=QR_LO,
                                              IVVI=IVVI, rf_RO_source=RF,
                                              AWG=AWG,
                                              heterodyne_instr=HS,
                                              MC=MC,
                                              FluxCtrl=Flux_Control,
                                              server_name=None)
station.add_component(QR)

# # load settings onto qubits
gen.load_settings_onto_instrument(QL)
gen.load_settings_onto_instrument(QR)
gen.load_settings_onto_instrument(HS)


nested_MC = mc.MeasurementControl('nested_MC')
nested_MC.station = station

# The AWG sequencer
station.pulsar = ps.Pulsar()
station.pulsar.AWG = station.components['AWG']
marker1highs=[2,2,2.7,2]
for i in range(4):
    # Note that these are default parameters and should be kept so.
    # the channel offset is set in the AWG itself. For now the amplitude is
    # hardcoded. You can set it by hand but this will make the value in the
                                              cw_source=Qubit_LO,
                                              td_source=Qubit_LO,
                                              IVVI=IVVI, rf_RO_source=RF,
                                              AWG=AWG,
                                              CBox=CBox, heterodyne_instr=HS,
                                              MC=MC,
                                              server_name=None)

VIP_mon_2_dux = dt.Duplexer_tek_transmon('VIP_mon_2_dux', LO=LO,
                                         cw_source=Qubit_LO,
                                         td_source=Qubit_LO,
                                         IVVI=IVVI, AWG=AWG, CBox=CBox,
                                         heterodyne_instr=HS, MC=MC, Mux=Dux,
                                         rf_RO_source=RF, server_name=None)

gen.load_settings_onto_instrument(VIP_mon_2_tek)#, timestamp='20160621_101926')
gen.load_settings_onto_instrument(VIP_mon_4_tek)#, timestamp='20160621_101926')
gen.load_settings_onto_instrument(VIP_mon_2_dux)#, timestamp='20160621_101926')


station = qc.Station(LO, RF, Qubit_LO, IVVI, Dux, Pump,
                     AWG, AWG520, HS, CBox, LutMan,
                     VIP_mon_2_dux,
                     VIP_mon_2_tek, VIP_mon_4_tek)
MC.station = station
station.MC = MC
nested_MC = mc.MeasurementControl('nested_MC')
nested_MC.station = station

# The AWG sequencer
station.pulsar = ps.Pulsar()