pyquil icon indicating copy to clipboard operation
pyquil copied to clipboard

Fencing/ Un-fencing

Open zohimchandani opened this issue 3 years ago • 1 comments

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?

zohimchandani avatar Aug 27 '21 18:08 zohimchandani

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.

mhodson-rigetti avatar Sep 07 '21 23:09 mhodson-rigetti