qilimanjaro-tech/qililab

Errors in Platform documentation

Opened this issue · 0 comments

There are a few mistakes in the documentation of Platform that should be fixed:

  • In this example in the docs of Platform

    from qibo.models import Circuit
    from qibo import gates
    
    circuit = Circuit(1)
    circuit.add(gates.X(0))
    circuit.add(gates.M(0))
    

    the circuit, the way it is defined, cannot be executed because the X gate is not defined in the runcard. To avoid having to define this gate in the runcard, the X gate in this circuit has to be replaced with a Drag gate, or the whole circuit needs to be translated using translate_circuit() before transforming it in a pulse schedule using CircuitToPulses().translate().

  • In this example, also in the docs of Platform

from qililab.pulses.circuit_to_pulses import CircuitToPulses

pulse_schedule = CircuitToPulses(platform=platform).translate(circuits=[circuit])

results = []

gain_values = np.arange(0, 1, step=0.1)
for gain in gain_values:
    # We assume the bus used to drive qubit 0 is called "drive_q0"
    platform.set_parameter(alias="drive_q0", parameter=ql.Parameter.GAIN, value=gain)
    result = platform.execute(program=pulse_schedule, num_avg=1000, repetition_duration=6000)
    results.append(result.array)

when platform.execute() is called, it will try to iterate over the elements of the pulse schedule, which are retrieved using pulse_schedule.elements, but it will fail because CircuitToPulses.translate() returns a list of pulse schedules, which, unlike a pulse schedule, does not have an elements attribute.

To fix this, extract the pulse schedule from the list returned by CircuitToPulses.translate(). So, instead of writing
pulse_schedule = CircuitToPulses(platform=platform).translate(circuits=[circuit])
write
pulse_schedule = CircuitToPulses(platform=platform).translate(circuits=[circuit])[0]

Finally, when the result.array is obtained to append it to the results list in this line
results.append(result.array)
results.array will contain the IQ data. However the values of this array should all be divided by the integration length: this data can further on be used to plot the experiment results, and this plot will be faulty if the IQ data is not divided by the integration length, and it will not be possible to divide by the integration length when plotting because the value of the integration length is not contained in results but only in result, and in the plotting phase only results, in the convenient array format, is considered.