Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V4 - fix: Load defaults for ommitted config fields #1605

Merged
merged 6 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 4 additions & 1 deletion 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 = qvm.api.get_version_info(client=self._client, options=QVMOptions(timeout_seconds=self.timeout))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new options parameter shouldn't be required, but it is. Regardless, we needed to use it here to apply the timeout, so I added it. Created a follow-up issue in qcs-sdk-rust#315

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 Down
12 changes: 9 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,7 @@ 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))
return np.asarray(measured_qubits)

@staticmethod
Expand Down
Loading