rigetti / rigetti/pyquil

The logic in Device.get_isa should be somewhere else

Open
#1,065 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

refactor :hammer:
Dominant language
Python
Stars
1.5k
Forks
358
Avg merge
1d 58m
Merged PRs (30d)
4

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at Device.get_isa and inspect the referenced ISA, Qubit, Edge, MeasureInfo, and GateInfo definitions. Move the default annotation construction into an appropriate function or ISA method, preserving the existing validation and generated gates and edges; done means Device.get_isa no longer owns that logic.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
quantum-computing
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.