Skip to content

Commit

Permalink
V4 - fix: Load defaults for ommitted config fields (#1605)
Browse files Browse the repository at this point in the history
* fix: Partial QCS configs will fallback on defaults for omitted fields

* add options fields to QVM api calls

* correct param name

* ignore call arg err

* style

* consolidate get_version_info_requests
  • Loading branch information
MarquessV authored Jun 29, 2023
1 parent a1d0ba4 commit 8fcf7ab
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
28 changes: 14 additions & 14 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 @@ -27,7 +27,7 @@ rpcq = "^3.10.0"
pydantic = "^1.10.7"
networkx = ">=2.5"
importlib-metadata = { version = ">=3.7.3,<5", python = "<3.8" }
qcs-sdk-python = "0.9.0-rc.0"
qcs-sdk-python = "0.9.0"
tenacity = "^8.2.2"
types-python-dateutil = "^2.8.19"
types-retry = "^0.9.9"
Expand Down
7 changes: 5 additions & 2 deletions pyquil/api/_qvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import numpy as np

from qcs_sdk import QCSClient, qvm
from qcs_sdk.qvm import QVMOptions

from pyquil._version import pyquil_version
from pyquil.api import QAM, QuantumExecutable, QAMExecutionResult, MemoryMap
Expand Down Expand Up @@ -107,12 +108,13 @@ def __init__(
else:
raise TypeError("random_seed should be None or a non-negative int")

self.timeout = timeout
self._client = client_configuration or QCSClient.load()
self.connect()

def connect(self) -> None:
try:
version = qvm.api.get_version_info(client=self._client)
version = self.get_version_info()
check_qvm_version(version)
except ConnectionError:
raise QVMNotRunning(f"No QVM server running at {self._client.qvm_url}") from ConnectionError
Expand Down Expand Up @@ -144,6 +146,7 @@ def execute(
self.gate_noise,
self.random_seed,
self._client,
options=QVMOptions(timeout_seconds=self.timeout),
)

memory = {name: np.asarray(data.inner()) for name, data in result.memory.items()}
Expand All @@ -163,7 +166,7 @@ def get_version_info(self) -> str:
:return: String with version information
"""
return qvm.api.get_version_info(self._client)
return qvm.api.get_version_info(self._client, options=QVMOptions(timeout_seconds=self.timeout))


def validate_noise_probabilities(noise_parameter: Optional[Tuple[float, float, float]]) -> None:
Expand Down
14 changes: 11 additions & 3 deletions pyquil/api/_wavefunction_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import numpy as np

from qcs_sdk import QCSClient, qvm
from qcs_sdk.qvm import QVMOptions

from pyquil.api import MemoryMap
from pyquil.api._qvm import (
Expand Down Expand Up @@ -65,6 +66,7 @@ def __init__(
else:
raise TypeError("random_seed should be None or a non-negative int")

self.timeout = timeout
self._client = client_configuration or QCSClient.load()

def wavefunction(self, quil_program: Program, memory_map: Optional[MemoryMap] = None) -> Wavefunction:
Expand Down Expand Up @@ -96,7 +98,9 @@ def wavefunction(self, quil_program: Program, memory_map: Optional[MemoryMap] =
self.gate_noise,
self.random_seed,
)
wavefunction = bytes(qvm.api.get_wavefunction(request, self._client))
wavefunction = bytes(
qvm.api.get_wavefunction(request, self._client, options=QVMOptions(timeout_seconds=self.timeout))
)
return Wavefunction.from_bit_packed_string(wavefunction)

def expectation(
Expand Down Expand Up @@ -141,7 +145,9 @@ def expectation(
prep_prog = self.augment_program_with_memory_values(prep_prog, memory_map)

request = qvm.api.ExpectationRequest(prep_prog.out(), [prog.out() for prog in progs])
expectations = qvm.api.measure_expectation(request, self._client)
expectations = qvm.api.measure_expectation(
request, self._client, options=QVMOptions(timeout_seconds=self.timeout)
)
bare_results = np.asarray(expectations)
results = coeffs * bare_results
if is_pauli_sum:
Expand Down Expand Up @@ -196,7 +202,9 @@ def run_and_measure(
trials,
qubits,
)
measured_qubits = qvm.api.run_and_measure(request)
measured_qubits = qvm.api.run_and_measure(
request, options=QVMOptions(timeout_seconds=self.timeout) # type: ignore[call-arg]
)
return np.asarray(measured_qubits)

@staticmethod
Expand Down

0 comments on commit 8fcf7ab

Please sign in to comment.