Skip to content

Commit

Permalink
feat: Remove unused rewrite arithmetic logic, deprecate recalculation…
Browse files Browse the repository at this point in the history
…_table (#1787)

* chore: Remove rewrite_arithmetic and special handling for translation backend V1

* update vulnerable deps

* deprecate recalculation_table

* format

* Update pyquil/api/_abstract_compiler.py

Co-authored-by: Kalan <22137047+kalzoo@users.noreply.github.com>

---------

Co-authored-by: Kalan <22137047+kalzoo@users.noreply.github.com>
  • Loading branch information
MarquessV and kalzoo authored Jul 2, 2024
1 parent 352e33d commit f516aae
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 44 deletions.
52 changes: 26 additions & 26 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ numpy = "^1.25"
scipy = "^1.11"
rpcq = "^3.11.0"
networkx = ">=2.5"
qcs-sdk-python = "0.17.9"
qcs-sdk-python = "0.18.0"
packaging = "^23.1"
deprecated = "^1.2.14"
types-deprecated = "^1.2.9.3"
Expand Down
30 changes: 28 additions & 2 deletions pyquil/api/_abstract_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
##############################################################################
import dataclasses
import json
import warnings
from abc import ABC, abstractmethod
from collections.abc import Sequence
from dataclasses import dataclass
from dataclasses import dataclass, field, fields
from typing import Any, Optional, Union

from deprecated.sphinx import deprecated
from qcs_sdk import QCSClient
from qcs_sdk.compiler.quilc import CompilationResult, CompilerOpts, QuilcClient, TargetDevice, compile_program
from rpcq.messages import ParameterSpec
Expand Down Expand Up @@ -55,13 +57,37 @@ class EncryptedProgram:
ro_sources: dict[MemoryReference, str]
"""Readout sources, mapped by memory reference."""

recalculation_table: list[str]
_recalculation_table: list[str] = field(default_factory=list, repr=False, init=False)
"""A mapping from memory references to the original gate arithmetic."""

def copy(self) -> "EncryptedProgram":
"""Return a deep copy of this EncryptedProgram."""
return dataclasses.replace(self)

def __post_init__(self) -> None:
if any(f.name == "recalculation_table" for f in fields(self)):
warnings.warn(
"The recalculation_table field is no longer used. It will be removed in future versions.",
DeprecationWarning,
stacklevel=2,
)

@property
@deprecated(
version="4.12.0",
reason="The recalculation_table field is no longer used. It will be removed in future versions.",
)
def recalculation_table(self) -> list[str]:
return self._recalculation_table

@recalculation_table.setter
@deprecated(
version="4.12.0",
reason="The recalculation_table field is no longer used. Recalculation is now performed by the execution service. This field will be removed in future versions.",
)
def recalculation_table(self, value: list[str]) -> None:
self._recalculation_table = value


QuantumExecutable = Union[EncryptedProgram, Program]

Expand Down
7 changes: 0 additions & 7 deletions pyquil/api/_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

from qcs_sdk import QCSClient
from qcs_sdk.compiler.quilc import QuilcClient
from qcs_sdk.qpu.rewrite_arithmetic import rewrite_arithmetic
from qcs_sdk.qpu.translation import (
TranslationBackend,
get_quilt_calibrations,
Expand Down Expand Up @@ -115,13 +114,8 @@ def native_quil_to_executable(
If `api_options` is provided, it overrides the options set on `self`.
"""
program = nq_program.out()
recalculation_table = []
backend = api_options.backend if api_options is not None else None
backend = select_backend_for_quantum_processor_id(self.quantum_processor_id, backend)
if backend is TranslationBackend.V1:
rewrite_response = rewrite_arithmetic(nq_program.out())
program = rewrite_response.program
recalculation_table = list(rewrite_response.recalculation_table)

translated_program = translate(
native_quil=program,
Expand All @@ -136,7 +130,6 @@ def native_quil_to_executable(
program=translated_program.program,
memory_descriptors=_collect_memory_descriptors(nq_program),
ro_sources={parse_mref(mref): source for mref, source in ro_sources.items() or []},
recalculation_table=recalculation_table,
)

def _fetch_calibration_program(self) -> Program:
Expand Down
8 changes: 1 addition & 7 deletions pyquil/api/_qpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
retrieve_results,
submit_with_parameter_batch,
)
from qcs_sdk.qpu.rewrite_arithmetic import build_patch_values
from rpcq.messages import ParameterSpec

from pyquil.api import EncryptedProgram, QuantumExecutable
Expand Down Expand Up @@ -205,16 +204,11 @@ def execute_with_memory_map_batch(
if not isinstance(executable, EncryptedProgram):
raise ValueError("QPU#execute requires an rpcq.EncryptedProgram. Create one with QuantumComputer#compile")

patch_values = []
for memory_map in memory_maps:
memory_map = memory_map or {}
patch_values.append(build_patch_values(executable.recalculation_table, memory_map))

effective_execution_options = execution_options or self.execution_options

job_ids = submit_with_parameter_batch(
program=executable.program,
patch_values=patch_values,
patch_values=memory_maps,
quantum_processor_id=self.quantum_processor_id,
client=self._client_configuration,
execution_options=effective_execution_options,
Expand Down
1 change: 0 additions & 1 deletion test/unit/test_qpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def mock_encrypted_program():
MemoryReference("ro", 1): "q1",
MemoryReference("ro"): "q0",
},
recalculation_table=[],
)


Expand Down

0 comments on commit f516aae

Please sign in to comment.