from qiskit_ibm_experiment import IBMExperimentService
from qiskit_experiments.framework.json import ExperimentDecoder, ExperimentEncoder
from IPython.display import SVG, display

IBMExperimentService.save_account(token="MY_API_TOKEN")
IBMExperimentService.save_account(name="staging", token="MY_STAGING_API_TOKEN", url='https://api-dev.quantum-computing.ibm.com')

service = IBMExperimentService()
service.experiments()

exp_id = 'b4bebb95-66d4-461b-9287-1441443a3336'
service.experiment(exp_id)

service.experiments(experiment_type='readout_test')

service.analysis_results(experiment_id = exp_id)

fig = service.figure(exp_id, 'figure_b4bebb95_2022-03-30T11:40:21.656059_0.svg')
display(SVG(fig))

service = IBMExperimentService(name="staging")
service.experiments()

from qiskit.providers.ibmq import IBMQ, least_busy
provider = IBMQ.enable_account(url='https://api-dev.quantum-computing.ibm.com/v2', token="c0026ac13d5f10513555e5f396f20b60f97eabf85ba8591a3415ebcfb54e4961c8c095938a29ff4b657a725fa48e301d993ef509a7699ceddc891b0d1eddb137")
backend = least_busy(provider.backends(simulator=False, min_num_qubits=5))

exp_id = service.create_experiment(experiment_type="demo_day", 
                                   backend_name = backend.name(),
                                   provider=provider,
                                   metadata = {'complex_number': 3+2j},
                                   json_encoder=ExperimentEncoder
                                  )
exp_id

service.experiment(exp_id, json_decoder=ExperimentDecoder)

for i in range(30):
    service.create_analysis_result(exp_id,
                                  result_data = {'100': 100-i, '010': 24+i},
                                  result_type = f'result{i}'
                                  )

service.analysis_results(experiment_id = exp_id)

service.analysis_results(experiment_id = exp_id,
                        result_type = 'result1',
                        result_type_operator='like')

fig_name, _ = service.create_figure(exp_id, fig)

new_fig = service.figure(exp_id, fig_name)
display(SVG(new_fig))