pyquil icon indicating copy to clipboard operation
pyquil copied to clipboard

Support for creating custom ISAs

Open bramathon opened this issue 4 years ago • 0 comments

Pre-Request Checklist

  • [x] I am running the latest versions of pyQuil and the Forest SDK
  • [x] I checked to make sure that this feature has not already been requested

Issue Description

Customizing the Instruction Set Architecture is not an officially documented ability, but it's an important feature for power-users who want more control over compilation and which qubits or gates are used.

In pyquil2, it was possible to create a custom instruction set architecture like this:

qc = get_qc("Aspen-9")

isa_dict = qc.device.get_isa().to_dict()

# modify the isa dict
new_isa_dict = modify_isa(isa_dict)

qc.compiler.target_device.isa = new_isa_dict

In pyquil3, this becomes a bit harder:

from pyquil.external.rcpq import  CompilerISA

qc = get_qc("Aspen-9")
isa_dict = qc.compiler.quantum_processor.to_compiler_isa().dict()

# modify the ISA
new_isa_dict = modify_isa(isa_dict)

# rename keys: 'qubits' -> '1Q', 'edges' -> '2Q'
new_isa_dict['1Q'] = new_isa_dict.pop('qubits')
new_isa_dict['2Q'] = new_isa_dict.pop('edges')

new_isa = CompilerISA.parse_obj(new_isa_dict)

# monkey patch the object
qc.compiler.quantum_processor.to_compiler_isa = lambda: new_isa

Proposed Solution

I don't have a proposed solution here. Sticking with 1 set of key names would be a welcome improvement.

Common use-cases are reducing the ISA to a specific set of qubits and edges or a subset of gates.

bramathon avatar Sep 02 '21 20:09 bramathon