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

Add referral to forum in error messages #428

Merged
merged 9 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
into PennyLane is updated to allow passing parameters as args or kwargs, rather than as
a dictionary. The old dictionary UI continues to be supported.
[(#406)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/406)
[(#428)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/428)

* Measurement operations are now added to the PennyLane template when a `QuantumCircuit`
is converted using `load`. Additionally, one can override any existing terminal
Expand Down
15 changes: 10 additions & 5 deletions pennylane_qiskit/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@

dagger_map = {"SdgGate": qml.S, "TdgGate": qml.T, "SXdgGate": qml.SX}

referral_to_forum = (
"\n \nIf you are experiencing any difficulties with converting circuits from Qiskit, you can reach out "
"\non the PennyLane forum at https://discuss.pennylane.ai/c/pennylane-plugins/pennylane-qiskit/"
)


def _check_parameter_bound(param: Parameter, unbound_params: Dict[Parameter, Any]):
"""Utility function determining if a certain parameter in a QuantumCircuit has
Expand Down Expand Up @@ -121,7 +126,7 @@ def _format_params_dict(quantum_circuit, params, *args, **kwargs):
# the key needs to be the actual Parameter, whereas kwargs keys are parameter names
if not k in expected_params:
raise TypeError(
f"Got unexpected parameter keyword argument '{k}'. Circuit contains parameters: {param_name_string}"
f"Got unexpected parameter keyword argument '{k}'. Circuit contains parameters: {param_name_string} {referral_to_forum}"
)
params[expected_params[k]] = v

Expand All @@ -140,7 +145,7 @@ def _format_params_dict(quantum_circuit, params, *args, **kwargs):
else ""
)
raise TypeError(
f"Expected {len(expected_arg_params)} positional argument{'s' if len(expected_arg_params) > 1 else ''} but {len(args)} were given. {param_vector_info}"
f"Expected {len(expected_arg_params)} positional argument{'s' if len(expected_arg_params) > 1 else ''} but {len(args)} were given. {param_vector_info} {referral_to_forum}"
)
params.update(dict(zip(expected_arg_params, args)))

Expand Down Expand Up @@ -193,7 +198,7 @@ def _check_circuit_and_assign_parameters(
if name in [p.name for p in quantum_circuit.parameters]:
raise RuntimeError(
f"Cannot interpret QuantumCircuit with parameter '{name}' as a PennyLane "
f"quantum function, as this argument is reserved"
f"quantum function, as this argument is reserved. {referral_to_forum}"
)

expected_params, param_name_string = _expected_parameters(quantum_circuit)
Expand All @@ -202,7 +207,7 @@ def _check_circuit_and_assign_parameters(
if quantum_circuit.parameters:
s = "s" if len(quantum_circuit.parameters) > 1 else ""
raise TypeError(
f"Missing required argument{s} to define Parameter value{s} for: {param_name_string}"
f"Missing required argument{s} to define Parameter value{s} for: {param_name_string} {referral_to_forum}"
)
return quantum_circuit

Expand All @@ -212,7 +217,7 @@ def _check_circuit_and_assign_parameters(
s = "s" if len(undefined_params) > 1 else ""
param_names = ", ".join(undefined_params)
raise TypeError(
f"Missing {len(undefined_params)} required argument{s} to define Parameter value{s} for: {param_names}"
f"Missing {len(undefined_params)} required argument{s} to define Parameter value{s} for: {param_names}. {referral_to_forum}"
)

for k in diff_params:
Expand Down
2 changes: 0 additions & 2 deletions tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,6 @@ def test_format_params_dict_new_interface(self, args, kwargs):
assert params == {a: 0.5, b: 0.3, c: 0.4}



class TestConverterWarningsAndErrors:
"""Tests that the converter.load function emits warnings and errors."""

Expand Down Expand Up @@ -908,7 +907,6 @@ def test_too_many_args(self):
with pytest.raises(TypeError, match="Expected 1 positional argument but 2 were given"):
load(qc)([0.1, 0.3], 0.5, a=0.2, b=0.4)


def test_missing_argument(self):
"""Test that if calling with missing arguments, a clear error is raised"""

Expand Down
Loading