Skip to content

Commit

Permalink
improve gate times
Browse files Browse the repository at this point in the history
  • Loading branch information
obliviateandsurrender committed Jul 13, 2024
1 parent 061ca00 commit d2cfc4a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
6 changes: 3 additions & 3 deletions pennylane_qiskit/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,9 +1060,9 @@ def load_noise_model(noise_model, **kwargs) -> qml.NoiseModel:
thermal_relaxation (bool): prefer conversion of ``QiskitErrors`` to thermal relaxation errors
over damping errors. Default is ``False``.
readout_error (bool): include readout error in the converted noise model. Default is ``True``.
gate_times (Dict[str, Tuple[Tuple[int], float]]): a dictionary to provide gate times for building
thermal relaxation error. Each key will be the instruction name and the corresponding values
will be tuple of qubit indices and the time in seconds. If it is not provided or a gate/qubit
gate_times (Dict[Tuple(str, Tuple[int]), float]): a dictionary to provide gate times for building
thermal relaxation error. Each key will be a tuple of instruction name and qubit indices and
the corresponding value will be the time in seconds. If it is not provided or a gate/qubit
is missing, then a default value of `1.0 s`` will be used for the specific constructions.
optimize (bool): controls if a contraction order optimization is used for ``einsum`` while
transforming Kraus operators to a Choi matrix, wherever required. Default is ``False``.
Expand Down
22 changes: 13 additions & 9 deletions pennylane_qiskit/noise_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,15 @@ def _process_kraus_ops(
return (False, "QubitChannel", Kraus(Choi(choi_matrix)).data) if not kdata else kdata


def _extract_gate_time(gate_data: tuple[tuple[int], float], gate_wires: int) -> float:
def _extract_gate_time(gate_data: dict, gate_name: str, gate_wires: int) -> float:
"""Helper method to extract gate time for a quantum error"""
tg = 1.0
if gate_data is not None:
gate_data[0] = (gate_data[0],) if isinstance(int, gate_data[0]) else gate_data[0]
if gate_wires in gate_data[0]:
tg = gate_data[1]
if fgates := dict(filter(lambda item: item[0][0] == gate_name, gate_data)):
for g_d, g_t in fgates.items():
g_d[1] = (g_d[1],) if isinstance(int, g_d[1]) else g_d[1]
if gate_wires in g_d:
tg = g_t
break

Check warning on line 164 in pennylane_qiskit/noise_models.py

View check run for this annotation

Codecov / codecov/patch

pennylane_qiskit/noise_models.py#L160-L164

Added lines #L160 - L164 were not covered by tests
return tg

Check notice on line 166 in pennylane_qiskit/noise_models.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane_qiskit/noise_models.py#L109-L166

Complex Method

Expand All @@ -173,7 +175,8 @@ def _process_thermal_relaxation(choi_matrix, **kwargs):
nt_values[[(0, 2), (3, 5)]].sum(axis=1), 1.0, rtol=rtol, atol=atol
) and np.isclose(*nt_values[[1, 4]], rtol=rtol, atol=atol):
tg = _extract_gate_time(
gate_data=kwargs.get("gate_times", {}).get(kwargs.get("gate_name", None), None),
gate_data=kwargs.get("gate_times", {}),
gate_name=kwargs.get("gate_name", ""),
gate_wires=kwargs.get("gate_wires", None),
)
if np.isclose(nt_values[[2, 3]].sum(), 0.0, rtol=rtol, atol=atol):
Expand Down Expand Up @@ -263,7 +266,8 @@ def _process_reset(error_dict: dict, **kwargs) -> dict:
else: # uses t1 > t2
error_dict["name"] = "ThermalRelaxationError"
tg = _extract_gate_time(
gate_data=kwargs.get("gate_times", {}).get(kwargs.get("gate_name", None), None),
gate_data=kwargs.get("gate_times", {}),
gate_name=kwargs.get("gate_name", ""),
gate_wires=kwargs.get("gate_wires", None),
)
p0 = 1.0 if len(error_probs) == 3 else error_probs[2] / (error_probs[2] + error_probs[3])
Expand Down Expand Up @@ -409,8 +413,8 @@ def _build_noise_model_map(noise_model, **kwargs) -> Tuple[dict, dict]:
over damping errors. Default is ``False``.
gate_times (Dict[Tuple(str, Tuple[int]), float]): a dictionary to provide gate times for building
thermal relaxation error. Each key will be a tuple of instruction name and qubit indices and
the corresponding value will be the time in seconds. If it is not provided or is incomplete,
a default value of `1.0 s`` will be used for the specific constructions.
the corresponding value will be the time in seconds. If it is not provided or a gate/qubit
is missing, then a default value of `1.0 s`` will be used for the specific constructions.
multi_pauli (bool): assume depolarization channel to be multi-qubit. This is currently not
supported with ``qml.DepolarizationChannel``, which is a single qubit channel.
readout_error (bool): include readout error in the converted noise model. Default is ``True``.
Expand Down

0 comments on commit d2cfc4a

Please sign in to comment.