rigetti / rigetti/pyquil

Summing programs takes exponentially long

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

Nobody has claimed this yet.

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

Description

Issue Description

In some cases, programs are combined like so:

sum((program for _ in range(100)), Program());

This is used in forest-benchmarking for example. When the program is an object of a significant size, I observe exponential cost to this operation.

On close examination, I also observe exponential cost for pyquil 3, but it's much faster so It's not noticed.

Code Snippet
import pyquil
print(pyquil.__version__)
from pyquil.api import get_qc
from pyquil.quil import Program
from pyquil.gates import RX

qc = get_qc("Aspen-M-3")
calibration_program = qc.compiler.get_calibration_program()

depth = 80

rotation = calibration_program.copy_everything_except_instructions()
rotation += RX(1.57, 0)

%%time
sum((Program(rotation) for _ in range(depth)), Program());
Error Output

The timing of this operation is below. Extrapolating from n=2, n=80 should take 7.2s

# pyquil 4
# num = 2, time = 0.18
# num = 4, time = 0.49
# num = 6, time = 0.88
# num = 10, time = 2.39
# num = 20, time = 7.1
# num = 40, time = 25.1
# num = 80, time = 98
# pyquil 3
# pyquil 3
# num = 2, time = 111us
# num = 20, time = 4.19ms
# num = 40, time = 1.91ms
# num = 80, time = 16.7ms

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 with the Program construction and addition paths used by the provided sum((Program(rotation) for _ in range(depth)), Program()) reproduction. Run the timing snippet for increasing depths and trace where repeated copying or combination occurs. Done means program summation no longer shows exponential growth and the reproduction scales acceptably.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.