rigetti / pyquil

A Python library for quantum programming using Quil.
http://docs.rigetti.com
Apache License 2.0
1.41k stars 343 forks source link

Fencing/ Un-fencing #1375

Open zohimchandani opened 3 years ago

zohimchandani commented 3 years ago

Qubit reset and fencing are 2 common approaches used to enhance the performance of executions on QPU.

Active reset is easy to implement as it has a nice command which can be appended to the start of the program: program += RESET()

The fence command is more complicated and requires one to define a function:

def quilt_no_fence(compiler: AbstractCompiler) -> Program:
    """Read calibrations for the compiler, find `FenceAll`, and collect `Fence` of CZ & XY.

    Args:
        computer: The quantum computer to recalibrate.

    Returns:
        Calibrations for the compiler as a `Program`.
    """
    names = {"CZ", "XY"}
    updated = []
    for cal in compiler.get_calibration_program().calibrations: 
        if isinstance(cal, DefCalibration) and getattr(cal, "name", "") in names:
            instrs: List[Union[AbstractInstruction, Fence]] = []
            for instr in cal.instrs:
                if isinstance(instr, FenceAll):
                    instrs.append(Fence(cal.qubits))
                else:
                    instrs.append(instr)
            updated.append(DefCalibration(cal.name, cal.parameters, cal.qubits, instrs))
    return Program(updated)

which is then used when compiling the program. Can we possibly build this into pyQuil so that users can avoid copying code for function definitions and have an easier user interface from which they can access the fencing feature?

mhodson-rigetti commented 3 years ago

The meaning of this method is to disable global fencing on 2Q gates, and that should be clear in the documentation. If this is to apply to all 2Q native gates then CPHASE needs to be added to names, and a code structure that makes it hard to miss an update caused by deployment of a new standard 2Q gate (or, user-defined 2Q gate calibration) would be preferred.