pyquil icon indicating copy to clipboard operation
pyquil copied to clipboard

The logic in Device.get_isa should be somewhere else

Open karalekas opened this issue 4 years ago • 2 comments

All this default annotation logic should be pulled out into a function or a method on ISAs.

def get_isa(self, oneq_type=None, twoq_type=None) -> ISA:
    """
    Construct an ISA suitable for targeting by compilation.
    This will raise an exception if the requested ISA is not supported by the device.
    """
    if oneq_type is not None or twoq_type is not None:
        raise ValueError("oneq_type and twoq_type are both fatally deprecated. If you want to "
                         "make an ISA with custom gate types, you'll have to do it by hand.")

    qubits = [Qubit(id=q.id, type=None, dead=q.dead, gates=[
        MeasureInfo(operator="MEASURE", qubit=q.id, target="_",
                    fidelity=self.specs.fROs()[q.id] or DEFAULT_MEASURE_FIDELITY,
                    duration=DEFAULT_MEASURE_DURATION),
        MeasureInfo(operator="MEASURE", qubit=q.id, target=None,
                    fidelity=self.specs.fROs()[q.id] or DEFAULT_MEASURE_FIDELITY,
                    duration=DEFAULT_MEASURE_DURATION),
        GateInfo(operator="RZ", parameters=["_"], arguments=[q.id],
                 duration=PERFECT_DURATION, fidelity=PERFECT_FIDELITY),
        GateInfo(operator="RX", parameters=[0.0], arguments=[q.id],
                 duration=DEFAULT_RX_DURATION, fidelity=PERFECT_FIDELITY)] + [
            GateInfo(operator="RX", parameters=[param], arguments=[q.id],
                     duration=DEFAULT_RX_DURATION,
                     fidelity=self.specs.f1QRBs()[q.id] or DEFAULT_RX_FIDELITY)
            for param in [np.pi, -np.pi, np.pi / 2, -np.pi / 2]])
        for q in self._isa.qubits]
    edges = [Edge(targets=e.targets, type=None, dead=e.dead, gates=[
                GateInfo(operator="CZ", parameters=[], arguments=["_", "_"],
                         duration=DEFAULT_CZ_DURATION,
                         fidelity=self.specs.fCZs()[tuple(e.targets)] or DEFAULT_CZ_FIDELITY)])
             for e in self._isa.edges]
    return ISA(qubits, edges)

karalekas avatar Oct 20 '19 02:10 karalekas

I think get_isa() should just be a wrapped around self._isa, and that we should trust the ISA provided to Device() to be the One Trust ISA. @karalekas wouldst thou agree?

notmgsk avatar Oct 28 '19 23:10 notmgsk

@notmgsk as long as this default annotation is then moved to the device generation workflow, then yes I wouldst agree

karalekas avatar Oct 29 '19 04:10 karalekas