Skip to content

Commit

Permalink
fix: add force flag for import testing (#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
math411 committed Jan 29, 2024
1 parent cc28083 commit 343f2be
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 26 deletions.
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Sphinx configuration."""

import datetime

import pkg_resources
Expand Down
8 changes: 5 additions & 3 deletions src/braket/aws/aws_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,11 @@ def _get_regional_device_session(self, session: AwsSession) -> AwsSession:
self._populate_properties(region_session)
return region_session
except ClientError as e:
raise ValueError(f"'{self._arn}' not found") if e.response["Error"][
"Code"
] == "ResourceNotFoundException" else e
raise (
ValueError(f"'{self._arn}' not found")
if e.response["Error"]["Code"] == "ResourceNotFoundException"
else e
)

def _get_non_regional_device_session(self, session: AwsSession) -> AwsSession:
current_region = session.region
Expand Down
8 changes: 5 additions & 3 deletions src/braket/aws/aws_quantum_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,11 @@ def _initialize_regional_device_session(
aws_session.get_device(device)
return aws_session
except ClientError as e:
raise ValueError(f"'{device}' not found.") if e.response["Error"][
"Code"
] == "ResourceNotFoundException" else e
raise (
ValueError(f"'{device}' not found.")
if e.response["Error"]["Code"] == "ResourceNotFoundException"
else e
)

@staticmethod
def _initialize_non_regional_device_session(
Expand Down
6 changes: 3 additions & 3 deletions src/braket/aws/aws_quantum_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,9 @@ def _download_result(
"has_reservation_arn": self._has_reservation_arn_from_metadata(current_metadata),
}
try:
task_event[
"execution_duration"
] = self._result.additional_metadata.simulatorMetadata.executionDuration
task_event["execution_duration"] = (
self._result.additional_metadata.simulatorMetadata.executionDuration
)
except AttributeError:
pass
broadcast_event(_TaskCompletionEvent(**task_event))
Expand Down
8 changes: 5 additions & 3 deletions src/braket/circuits/gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,11 @@ def _to_openqasm(
for state, group in groupby(control_basis_state.as_tuple):
modifier_name = "neg" * (not state) + "ctrl"
control_modifiers += [
f"{modifier_name}"
if (num_control := len(list(group))) == 1
else f"{modifier_name}({num_control})"
(
f"{modifier_name}"
if (num_control := len(list(group))) == 1
else f"{modifier_name}({num_control})"
)
]
control_modifiers.append("")
qubits = control_qubits + target_qubits
Expand Down
8 changes: 4 additions & 4 deletions src/braket/pulse/pulse_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,10 @@ def _parse_from_calibration_schema(
argument_value.update(QubitSet(int(argument["value"])))
instr_args["qubits_or_frames"] = argument_value
elif argument["name"] in instr_args_keys:
instr_args[
argument["name"]
] = calibration_sequence._parse_arg_from_calibration_schema(
argument, waveforms, frames
instr_args[argument["name"]] = (
calibration_sequence._parse_arg_from_calibration_schema(
argument, waveforms, frames
)
)
else:
instr_args["qubits_or_frames"] = []
Expand Down
8 changes: 5 additions & 3 deletions src/braket/quantum_information/pauli_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ def weight_n_substrings(self, weight: int) -> tuple[PauliString, ...]:
substrings = []
for indices in itertools.combinations(self._nontrivial, weight):
factors = [
self._nontrivial[qubit]
if qubit in set(indices).intersection(self._nontrivial)
else "I"
(
self._nontrivial[qubit]
if qubit in set(indices).intersection(self._nontrivial)
else "I"
)
for qubit in range(self._qubit_count)
]
substrings.append(
Expand Down
14 changes: 8 additions & 6 deletions test/unit_tests/braket/aws/common_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,14 @@ def _create_task_args_and_kwargs(
create_kwargs = extra_kwargs or {}
create_kwargs.update(
{
"poll_timeout_seconds": poll_timeout_seconds
if poll_timeout_seconds is not None
else default_poll_timeout,
"poll_interval_seconds": poll_interval_seconds
if poll_interval_seconds is not None
else default_poll_interval,
"poll_timeout_seconds": (
poll_timeout_seconds if poll_timeout_seconds is not None else default_poll_timeout
),
"poll_interval_seconds": (
poll_interval_seconds
if poll_interval_seconds is not None
else default_poll_interval
),
"inputs": inputs,
"gate_definitions": gate_definitions,
"reservation_arn": reservation_arn,
Expand Down
2 changes: 1 addition & 1 deletion test/unit_tests/braket/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_for_import_cycles():
# parameterized version wasn't able to correctly detect some circular imports when running tox.
modules = get_modules_to_test()
processes = []
multiprocessing.set_start_method("spawn")
multiprocessing.set_start_method("spawn", force=True)
for module in modules:
# We create a separate process to make sure the imports do not interfere with each-other.
process = multiprocessing.Process(target=import_module, args=(module,))
Expand Down

0 comments on commit 343f2be

Please sign in to comment.