Closed liu-zixiong closed 9 months ago
We're swallowing the exception and writing a warning at https://github.com/C2QA/bosonic-qiskit/blob/main/c2qa/parameterized_unitary_gate.py#L61-L75 in order to fix this problem: https://github.com/C2QA/bosonic-qiskit/issues/57. We could change the warning, but making it an exception will break the serialization issue again.
The whole ParameterizedUnitaryGate and its _define() is a bit of a kludge in order to let us parameterize our gates that are defined as unitaries. Qiskit on its own doesn't let you parameterize UnitaryGate, so this is our current workaround that has worked in some cases and led to issues in others.
I would think we could easily add a validation step & raise an exception for the cv_measure
function when the len(qubit_qumode_list) != len(cbit_list)
I updated the warning message to be clearer. The implementation of cv_measure has since been updated to test the size of the cbit_list.
It seems that for functions defined in operators.py, errors produced are silent.
Let me illustrate with a tester function. Within operators.py, define a function that raises errors when given a specific argument. When given arg == 0, the operator will execute properly. When given arg == 1 or 2, the operator will attempt to fail with a warning.
Separately, define a gate in circuit.py that calls this tester function. This gate is copied from the cv_d gate, the only differences are changes to variable names.
When we execute these functions using a simple circuit, we will find that arg == 0 is fine, but arg == 1 or 2 will produce an elaborate error, but without the warnings that we wrote. This elaborate traceback is the exact same traceback as appended in Issue #83.
Since functions in operators.py fail silently, debugging or developing new operators is difficult. Preferably there should be a try-except block somewhere that tells you if the operator did not return a valid value.
Additionally, since bosonic-qiskit is a wrapper for qiskit, I suggest that errors arising from bosonic-qiskit should be caught and stopped before they are fed into qiskit. For example, in parameterized_unitary_gate, under the _define() method, there is a warning for "Unable to define gate". I suggest changing the warning it to an exception. This is so that the user is not mislead by the traceback into thinking that the error occurs within qiskit.
Another example would be something like cv_measure(), which currently does not have an error message for if the number of classical bits passed in is lesser than the total number of qubits in the qumode we are trying to measure.