Skip to content

Commit

Permalink
fix mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MarquessV committed Jul 7, 2023
1 parent c91f56a commit a08d5d9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
23 changes: 18 additions & 5 deletions pyquil/api/_qpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
##############################################################################
from dataclasses import dataclass
from collections import defaultdict
from typing import Dict, Optional, Union
from typing import Any, Dict, Optional, Union

import numpy as np
from numpy.typing import NDArray
Expand All @@ -28,7 +28,14 @@
MemoryReference,
)
from qcs_sdk import QCSClient
from qcs_sdk.qpu.api import submit, retrieve_results, ExecutionResult, ExecutionOptions
from qcs_sdk.qpu.api import (
submit,
retrieve_results,
ConnectionStrategy,
ExecutionResult,
ExecutionOptions,
ExecutionOptionsBuilder,
)
from qcs_sdk.qpu.rewrite_arithmetic import build_patch_values


Expand Down Expand Up @@ -114,6 +121,7 @@ def __init__(
timeout: float = 10.0,
client_configuration: Optional[QCSClient] = None,
endpoint_id: Optional[str] = None,
execution_options: Optional[ExecutionOptions] = None,
) -> None:
"""
A connection to the QPU.
Expand All @@ -134,7 +142,12 @@ def __init__(
self._last_results: Dict[str, np.ndarray] = {}
self._memory_results: Dict[str, Optional[np.ndarray]] = defaultdict(lambda: None)
self._quantum_processor_id = quantum_processor_id
self._endpoint_id = endpoint_id
if execution_options is None:
execution_options_builder = ExecutionOptionsBuilder.default()
if endpoint_id is not None:
execution_options_builder.connection_strategy(ConnectionStrategy.endpoint_id(endpoint_id))
execution_options = execution_options_builder.build()
self.execution_options = execution_options

@property
def quantum_processor_id(self) -> str:
Expand All @@ -146,6 +159,7 @@ def execute(
executable: QuantumExecutable,
memory_map: Optional[MemoryMap] = None,
execution_options: Optional[ExecutionOptions] = None,
**__: Any,
) -> QPUExecuteResponse:
"""
Enqueue a job for execution on the QPU. Returns a ``QPUExecuteResponse``, a
Expand Down Expand Up @@ -173,9 +187,8 @@ def execute(
program=executable.program,
patch_values=patch_values,
quantum_processor_id=self.quantum_processor_id,
endpoint_id=self._endpoint_id,
client=self._client_configuration,
execution_options=execution_options,
execution_options=execution_options or self.execution_options,
)

return QPUExecuteResponse(_executable=executable, job_id=job_id, execution_options=execution_options)
Expand Down
3 changes: 2 additions & 1 deletion pyquil/api/_qvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
##############################################################################
from dataclasses import dataclass
from typing import Mapping, Optional, Sequence, Tuple
from typing import Any, Mapping, Optional, Sequence, Tuple

import numpy as np

Expand Down Expand Up @@ -123,6 +123,7 @@ def execute(
self,
executable: QuantumExecutable,
memory_map: Optional[MemoryMap] = None,
**__: Any,
) -> QVMExecuteResponse:
"""
Synchronously execute the input program to completion.
Expand Down
4 changes: 1 addition & 3 deletions pyquil/api/_wavefunction_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,7 @@ def run_and_measure(
trials,
qubits,
)
measured_qubits = qvm.api.run_and_measure(
request, options=QVMOptions(timeout_seconds=self.timeout) # type: ignore[call-arg]
)
measured_qubits = qvm.api.run_and_measure(request, options=QVMOptions(timeout_seconds=self.timeout))
return np.asarray(measured_qubits)

@staticmethod
Expand Down
8 changes: 2 additions & 6 deletions pyquil/pyqvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
##############################################################################
import logging
from abc import ABC, abstractmethod
from typing import Dict, List, Optional, Sequence, Type, Union
from typing import Dict, List, Optional, Sequence, Type, Union, Any

import numpy as np
from numpy.random.mtrand import RandomState
Expand Down Expand Up @@ -221,11 +221,7 @@ def _extract_defined_gates(self) -> None:
raise NotImplementedError("PyQVM does not support DEFGATE ... AS MATRIX | PAULI-SUM.")
self.defined_gates[dg.name] = dg.matrix

def execute(
self,
executable: QuantumExecutable,
memory_map: Optional[MemoryMap] = None,
) -> "PyQVM":
def execute(self, executable: QuantumExecutable, memory_map: Optional[MemoryMap] = None, **__: Any) -> "PyQVM":
"""
Execute a program on the PyQVM. Note that the state of the instance is reset on each
call to ``execute``.
Expand Down

0 comments on commit a08d5d9

Please sign in to comment.