Skip to content

Commit

Permalink
Update: Remove deprecated code (see CHANGELOG.md)
Browse files Browse the repository at this point in the history
  • Loading branch information
ameyer-rigetti committed Jun 4, 2021
1 parent 6e42195 commit 0e9dfee
Show file tree
Hide file tree
Showing 32 changed files with 233 additions and 666 deletions.
49 changes: 48 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,61 @@ Changelog

- Dropped `gates_in_isa` and refactored as an internal function for preparing a list of `pyquil.Gate`'s that the user may use to initialize a `NoiseModel` based on the underlying `CompilerISA`.

- `get_qc` raises `ValueError` when the user passes a QCS quantum processor name and `noisy=True`.
- `get_qc()` raises `ValueError` when the user passes a QCS quantum processor name and `noisy=True`.

- `QuantumComputer.run_and_measure()` has been removed. Instead, add explicit `MEASURE` instructions to programs and use
`QuantumComputer.compile()` along with `QuantumComputer.run()` to compile and execute.

- The `ro` memory region is no longer implicitly declared. All memory regions must be declared explicitly.

- The `pyquil.magic` package has been removed in favor of writing programs more explicitly.

- Removed `TomographyExperiment` (deprecated). Use `Experiment` instead.

- Removed `Experiment.qubits` (deprecated).

- `ExperimentSetting` constructor no longer accepts a `PauliTerm` for its `in_state` parameter (deprecated). Supply a
`TensorProductState` instead.

- Removed `ExperimentSetting.in_operator` (deprecated). Use `ExperimentSetting.in_state` instead.

- Removed the following `ExperimentResult` attributes (deprecated):
- `stddev`: Use `std_err` instead.
- `raw_stddev`: Use `raw_std_err` instead.
- `calibration_stddev`: Use `calibration_std_err` instead.

- Removed deprecated `protoquil_positional` parameter from `QuantumComputer.compile()`. Use `protoquil` keyword
parameter instead.

- `get_qc()` no longer accepts `"9q-generic"` (deprecated). Use `"9q-square"` instead.

- Removed `QAM.read_from_memory_region()` (deprecated). Use `QAM.read_memory()` instead.

- Removed `local_qvm()` (deprecated). Use `local_forest_runtime()` instead.

- Removed `Wavefunction.ground()` (deprecated). Use `Wavefunction.zeros()` instead.

- `WavefunctionSimulator`'s `run_and_measure()`, `wavefunction()`, and `expectation()` methods no longer accept a
`Dict[MemoryReference, Any]` for the `memory_map` parameter (deprecated). Supply a
`Dict[str, List[Union[int, float]]]` instead.

- `gates.MEASURE()` no longer accepts an integer for `classical_reg` (deprecated). Use a `MemoryReference` instead.

- Removed `gates.TRUE()`, `gates.FALSE()`, and classes `ClassicalTrue` and `ClassicalFalse` (deprecated).
Use `gates.MOVE()` and class `ClassicalMove` instead.

- Removed `gates.OR()` and class `ClassicalOr` (deprecated). Use `gates.IOR()` and class `ClassicalInclusiveOr` instead.

- `measure_observables()` no longer accepts the following parameters (deprecated):
- `n_shots`: Set on experiment's program with `Program.wrap_in_numshots_loop()` instead.
- `active_reset`: Add `RESET` instruction to experiment's program instead.
- `symmetrize_readout` & `readout_symmetrize`: Set `Experiment.symmetrization` on experiment instead.

- `PauliTerm.pauli_string()` now requires `qubits` instead of accepting them optionally (deprecated).

- Removed `Program.alloc()` (deprecated). Instantiate a `QubitPlaceholder` instead.

- Removed `Addr` (deprecated). Use `MemoryReference` instead.

### Bugfixes

Expand Down
1 change: 0 additions & 1 deletion docs/source/apidocs/gates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ Furthermore, Quilt instructions may be executed natively, although are not fully
NEG
NOT
AND
OR
IOR
XOR
MOVE
Expand Down
1 change: 0 additions & 1 deletion docs/source/apidocs/program.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Program
~Program.measure
~Program.reset
~Program.measure_all
~Program.alloc
~Program.declare
~Program.wrap_in_numshots_loop

Expand Down
19 changes: 4 additions & 15 deletions docs/source/apidocs/simulators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ simulation, you can directly inspect amplitudes and probabilities.
:template: autosumm.rst

~pyquil.api.WavefunctionSimulator
~pyquil.reference_simulator.ReferenceWavefunctionSimulator
~pyquil.reference_simulator.ReferenceDensitySimulator
~pyquil.numpy_simulator.NumpyWavefunctionSimulator
~pyquil.simulation.ReferenceWavefunctionSimulator
~pyquil.simulation.ReferenceDensitySimulator
~pyquil.simulation.NumpyWavefunctionSimulator


Reference Utilities
-------------------

.. currentmodule:: pyquil.unitary_tools
.. currentmodule:: pyquil.simulation.tools
.. autosummary::
:toctree: autogen
:template: autosumm.rst
Expand All @@ -30,14 +30,3 @@ Reference Utilities
program_unitary
all_bitstrings


Numpy Utilities
---------------

.. currentmodule:: pyquil.numpy_simulator
.. autosummary::
:toctree: autogen
:template: autosumm.rst

targeted_einsum
targeted_tensordot
4 changes: 2 additions & 2 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ignore_errors = True
ignore_errors = True

# Ignore errors in all test files
[mypy-*/tests/*]
[mypy-test/*]
ignore_errors = True

# Ignore errors in the conftest.py file
Expand All @@ -43,4 +43,4 @@ ignore_errors = True
# Ignore errors in the pyquil/parser.py file
# TODO(notmgsk): Add types
[mypy-pyquil.parser]
ignore_errors = True
ignore_errors = True
9 changes: 3 additions & 6 deletions pyquil/_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@
ClassicalMove,
ClassicalNeg,
ClassicalNot,
ClassicalTrue,
ClassicalFalse,
ClassicalAnd,
ClassicalOr,
ClassicalInclusiveOr,
ClassicalExclusiveOr,
ClassicalAdd,
Expand Down Expand Up @@ -398,9 +395,9 @@ def move(self, left, right):
@v_args(inline=True)
def classical_unary(self, op, target):
if op == "TRUE":
return ClassicalTrue(target)
return ClassicalMove(target, 1) # TODO(andrew): should this be removed?
elif op == "FALSE":
return ClassicalFalse(target)
return ClassicalMove(target, 0) # TODO(andrew): should this be removed?
elif op == "NEG":
return ClassicalNeg(target)
elif op == "NOT":
Expand All @@ -411,7 +408,7 @@ def logical_binary_op(self, op, left, right):
if op == "AND":
return ClassicalAnd(left, right)
elif op == "OR":
return ClassicalOr(left, right)
return ClassicalInclusiveOr(left, right) # TODO(andrew): should this be removed?
elif op == "IOR":
return ClassicalInclusiveOr(left, right)
elif op == "XOR":
Expand Down
1 change: 0 additions & 1 deletion pyquil/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
list_quantum_computers,
get_qc,
local_forest_runtime,
local_qvm,
)
from pyquil.api._qvm import QVMConnection, QVM
from pyquil.api._wavefunction_simulator import WavefunctionSimulator
Expand Down
19 changes: 0 additions & 19 deletions pyquil/api/_qam.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,25 +134,6 @@ def read_memory(self, *, region_name: str) -> Optional[np.ndarray]:
assert self._memory_results is not None
return self._memory_results[region_name]

@_record_call
def read_from_memory_region(self, *, region_name: str) -> Optional[np.ndarray]:
"""
Reads from a memory region named region_name on the QAM.
This is a shim over the eventual API and only can return memory from a region named
"ro" of type ``BIT``.
:param region_name: The string naming the declared memory region.
:return: A list of values of the appropriate type.
"""
warnings.warn(
"pyquil.api._qam.QAM.read_from_memory_region is deprecated, please use "
"pyquil.api._qam.QAM.read_memory instead.",
DeprecationWarning,
)

return self.read_memory(region_name=region_name) # type: ignore

@_record_call
def reset(self) -> None:
"""
Expand Down
36 changes: 1 addition & 35 deletions pyquil/api/_quantum_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ def compile(
program: Program,
to_native_gates: bool = True,
optimize: bool = True,
protoquil_positional: Optional[bool] = None,
*,
protoquil: Optional[bool] = None,
) -> QuantumExecutable:
Expand All @@ -404,20 +403,6 @@ def compile(
to protoquil (executable on QPU). A value of ``None`` means defer to server.
:return: An executable binary suitable for passing to :py:func:`QuantumComputer.run`.
"""
if protoquil_positional is not None:
warnings.warn(
'Setting "protoquil" via a positional argument has been deprecated and '
"will be removed in a future release. Please set it as a keyword arg.",
category=FutureWarning,
)
if protoquil is not None:
warnings.warn(
'You have set "protoquil" via both a positional and keyword argument.'
"Continuing with the value of the keyword argument.",
category=FutureWarning,
)
else:
protoquil = protoquil_positional

if isinstance(self.qam, QPU):
self.reset()
Expand Down Expand Up @@ -863,10 +848,7 @@ def get_qc(
)

# 3. Check for "9q-square" qvm
if prefix == "9q-generic" or prefix == "9q-square":
if prefix == "9q-generic":
warnings.warn("Please prefer '9q-square' instead of '9q-generic'", DeprecationWarning)

if prefix == "9q-square":
if qvm_type is None:
raise ValueError("The quantum_processor '9q-square' is only available as a QVM")
return _get_9q_square_qvm(
Expand Down Expand Up @@ -916,22 +898,6 @@ def get_qc(
return QuantumComputer(name=name, qam=qpu, compiler=compiler)


@contextmanager
def local_qvm() -> Iterator[Tuple[Optional[subprocess.Popen], Optional[subprocess.Popen]]]: # type: ignore
"""A context manager for the Rigetti local QVM and QUIL compiler.
.. deprecated:: 2.11
Use py:func:`local_forest_runtime` instead.
"""
warnings.warn(
DeprecationWarning(
"Use of pyquil.api.local_qvm has been deprecated.\n" "Please use pyquil.api.local_forest_runtime instead."
)
)
with local_forest_runtime() as (qvm, quilc):
yield (qvm, quilc)


def _port_used(host: str, port: int) -> bool:
"""Check if a (TCP) port is listening.
Expand Down
36 changes: 9 additions & 27 deletions pyquil/api/_wavefunction_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
# limitations under the License.
##############################################################################
import warnings
from typing import Dict, List, Union, Optional, Any, Set, cast, Iterable, Sequence
from warnings import warn
from typing import Dict, List, Union, Optional, Set, cast, Iterable, Sequence

import numpy as np
from qcs_api_client.client import QCSClientConfiguration
Expand Down Expand Up @@ -66,7 +65,7 @@ def __init__(
self._qvm_client = QVMClient(client_configuration=client_configuration, request_timeout=timeout)

@_record_call
def wavefunction(self, quil_program: Program, memory_map: Any = None) -> Wavefunction:
def wavefunction(self, quil_program: Program, memory_map: Dict[str, List[Union[int, float]]] = {}) -> Wavefunction:
"""
Simulate a Quil program and return the wavefunction.
Expand All @@ -83,13 +82,10 @@ def wavefunction(self, quil_program: Program, memory_map: Any = None) -> Wavefun
This is expected to be of type Dict[str, List[Union[int, float]]],
where the keys are memory region names and the values are arrays of
initialization data.
For now, we also support input of type Dict[MemoryReference, Any],
but this is deprecated and will be removed in a future release.
:return: A Wavefunction object representing the state of the QVM.
"""

if memory_map is not None:
if memory_map:
quil_program = self.augment_program_with_memory_values(quil_program, memory_map)

request = wavefunction_request(quil_program, self.random_seed)
Expand All @@ -101,7 +97,7 @@ def expectation(
self,
prep_prog: Program,
pauli_terms: Union[PauliSum, List[PauliTerm]],
memory_map: Any = None,
memory_map: Dict[str, List[Union[int, float]]] = {},
) -> Union[float, np.ndarray]:
"""
Calculate the expectation value of Pauli operators given a state prepared by prep_program.
Expand All @@ -124,9 +120,6 @@ def expectation(
This is expected to be of type Dict[str, List[Union[int, float]]],
where the keys are memory region names and the values are arrays of
initialization data.
For now, we also support input of type Dict[MemoryReference, Any],
but this is deprecated and will be removed in a future release.
:return: Either a float or array floats depending on ``pauli_terms``.
"""

Expand All @@ -138,7 +131,7 @@ def expectation(
coeffs = np.array([pt.coefficient for pt in pauli_terms])
progs = [pt.program for pt in pauli_terms]

if memory_map is not None:
if memory_map:
prep_prog = self.augment_program_with_memory_values(prep_prog, memory_map)

bare_results = self._expectation(prep_prog, progs)
Expand Down Expand Up @@ -166,7 +159,7 @@ def run_and_measure(
quil_program: Program,
qubits: Optional[List[int]] = None,
trials: int = 1,
memory_map: Optional[Union[Dict[str, List[Union[int, float]]], Dict[MemoryReference, Any]]] = None,
memory_map: Dict[str, List[Union[int, float]]] = {},
) -> np.ndarray:
"""
Run a Quil program once to determine the final wavefunction, and measure multiple times.
Expand Down Expand Up @@ -196,15 +189,12 @@ def run_and_measure(
This is expected to be of type Dict[str, List[Union[int, float]]],
where the keys are memory region names and the values are arrays of
initialization data.
For now, we also support input of type Dict[MemoryReference, Any],
but this is deprecated and will be removed in a future release.
:return: An array of measurement results (0 or 1) of shape (trials, len(qubits))
"""
if qubits is None:
qubits = sorted(cast(Set[int], quil_program.get_qubits(indices=True)))

if memory_map is not None:
if memory_map:
quil_program = self.augment_program_with_memory_values(quil_program, memory_map)

request = run_and_measure_request(quil_program, qubits, trials, self.random_seed)
Expand All @@ -214,7 +204,7 @@ def run_and_measure(
@staticmethod
def augment_program_with_memory_values(
quil_program: Program,
memory_map: Union[Dict[str, List[Union[int, float]]], Dict[MemoryReference, Any]],
memory_map: Dict[str, List[Union[int, float]]],
) -> Program:
p = Program()

Expand All @@ -224,18 +214,10 @@ def augment_program_with_memory_values(

if len(memory_map.keys()) == 0:
return quil_program
elif isinstance(list(memory_map.keys())[0], MemoryReference):
warn(
"Use of memory_map values of type Dict[MemoryReference, Any] have been "
"deprecated. Please use Dict[str, List[Union[int, float]]], as with "
"QuantumComputer.run ."
)
for k, v in memory_map.items():
p += MOVE(k, v)
elif isinstance(list(memory_map.keys())[0], str):
for name, arr in memory_map.items():
for index, value in enumerate(arr):
p += MOVE(MemoryReference(cast(str, name), offset=index), value)
p += MOVE(MemoryReference(name, offset=index), value)
else:
raise TypeError("Bad memory_map type; expected Dict[str, List[Union[int, float]]].")

Expand Down
2 changes: 0 additions & 2 deletions pyquil/experiment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pyquil.experiment._main import (
Experiment,
OperatorEncoder,
TomographyExperiment,
read_json,
to_json,
)
Expand All @@ -20,7 +19,6 @@
)
from pyquil.experiment._setting import (
_OneQState,
_pauli_to_product_state,
ExperimentSetting,
SIC0,
SIC1,
Expand Down
Loading

0 comments on commit 0e9dfee

Please sign in to comment.