From fa5d8a74fede47c6de7733acbc6a67c55ce16484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iy=C3=A1n=20M=C3=A9ndez=20Veiga?= Date: Sun, 12 May 2024 16:48:00 +0200 Subject: [PATCH] Avoid lossing precision when scaling frequencies Classes in pulse_instruction.py scale frequency values to GHz by multipliying `ParameterExpression` with float 1e9. This can lead to numerical errors on some systems using symengine. Instead, this scaling can be done multiplying by integer 10**9. See: https://github.com/Qiskit/qiskit/issues/12359#issuecomment-2104426621 --- qiskit/qobj/converters/pulse_instruction.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/qiskit/qobj/converters/pulse_instruction.py b/qiskit/qobj/converters/pulse_instruction.py index 77e811100f37..80c332aaab4a 100644 --- a/qiskit/qobj/converters/pulse_instruction.py +++ b/qiskit/qobj/converters/pulse_instruction.py @@ -234,7 +234,7 @@ def _convert_set_frequency( "name": "setf", "t0": time_offset + instruction.start_time, "ch": instruction.channel.name, - "frequency": instruction.frequency / 1e9, + "frequency": instruction.frequency / 10**9, } return self._qobj_model(**command_dict) @@ -257,7 +257,7 @@ def _convert_shift_frequency( "name": "shiftf", "t0": time_offset + instruction.start_time, "ch": instruction.channel.name, - "frequency": instruction.frequency / 1e9, + "frequency": instruction.frequency / 10**9, } return self._qobj_model(**command_dict) @@ -746,7 +746,7 @@ def _convert_setf( .. note:: We assume frequency value is expressed in string with "GHz". - Operand value is thus scaled by a factor of 1e9. + Operand value is thus scaled by a factor of 10^9. Args: instruction: SetFrequency qobj instruction @@ -755,7 +755,7 @@ def _convert_setf( Qiskit Pulse set frequency instructions """ channel = self.get_channel(instruction.ch) - frequency = self.disassemble_value(instruction.frequency) * 1e9 + frequency = self.disassemble_value(instruction.frequency) * 10**9 yield instructions.SetFrequency(frequency, channel) @@ -768,7 +768,7 @@ def _convert_shiftf( .. note:: We assume frequency value is expressed in string with "GHz". - Operand value is thus scaled by a factor of 1e9. + Operand value is thus scaled by a factor of 10^9. Args: instruction: ShiftFrequency qobj instruction @@ -777,7 +777,7 @@ def _convert_shiftf( Qiskit Pulse shift frequency schedule instructions """ channel = self.get_channel(instruction.ch) - frequency = self.disassemble_value(instruction.frequency) * 1e9 + frequency = self.disassemble_value(instruction.frequency) * 10**9 yield instructions.ShiftFrequency(frequency, channel)