Skip to content

Commit

Permalink
Qiskit#3343 | FakePulseBackend: change fake backend phases to radians (
Browse files Browse the repository at this point in the history
…Qiskit#3785)

* FakePulseBackend: change fake backend phases to radians

* FakePulseBackend: fix u2 parameters + test

* FakePulseBackend: change order of parameters in mock

* FakePulseBackend: u1 definitions fix

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
IceKhan13 and mergify[bot] authored Feb 7, 2020
1 parent f648fe6 commit aeeef37
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
12 changes: 6 additions & 6 deletions qiskit/test/mock/fake_openpulse_2q.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,22 @@ def __init__(self):
samples=7*[0.j, 0.1j, 1j, 0.5 + 0j])],
cmd_def=[Command(name='u1', qubits=[0],
sequence=[PulseQobjInstruction(name='fc', ch='d0',
t0=0, phase='-P1*np.pi')]),
t0=0, phase='-P0')]),
Command(name='u1', qubits=[1],
sequence=[PulseQobjInstruction(name='fc', ch='d1',
t0=0, phase='-P1*np.pi')]),
t0=0, phase='-P0')]),
Command(name='u2', qubits=[0],
sequence=[PulseQobjInstruction(name='fc', ch='d0',
t0=0, phase='-P0*np.pi'),
t0=0, phase='-P1'),
PulseQobjInstruction(name='test_pulse_4', ch='d0', t0=0),
PulseQobjInstruction(name='fc', ch='d0',
t0=0, phase='-P1*np.pi')]),
t0=0, phase='-P0')]),
Command(name='u2', qubits=[1],
sequence=[PulseQobjInstruction(name='fc', ch='d1',
t0=0, phase='-P0*np.pi'),
t0=0, phase='-P1'),
PulseQobjInstruction(name='test_pulse_4', ch='d1', t0=0),
PulseQobjInstruction(name='fc', ch='d1',
t0=0, phase='-P0*np.pi')]),
t0=0, phase='-P0')]),
Command(name='u3', qubits=[0],
sequence=[PulseQobjInstruction(name='test_pulse_1', ch='d0', t0=0)]),
Command(name='u3', qubits=[1],
Expand Down
16 changes: 8 additions & 8 deletions qiskit/test/mock/fake_openpulse_3q.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,29 @@ def __init__(self):
samples=7*[0.j, 0.1j, 1j, 0.5 + 0j])],
cmd_def=[Command(name='u1', qubits=[0],
sequence=[PulseQobjInstruction(name='fc', ch='d0',
t0=0, phase='-P1*np.pi')]),
t0=0, phase='-P0')]),
Command(name='u1', qubits=[1],
sequence=[PulseQobjInstruction(name='fc', ch='d1',
t0=0, phase='-P1*np.pi')]),
t0=0, phase='-P0')]),
Command(name='u1', qubits=[2],
sequence=[PulseQobjInstruction(name='fc', ch='d2',
t0=0, phase='-P1*np.pi')]),
t0=0, phase='-P0')]),
Command(name='u2', qubits=[0],
sequence=[PulseQobjInstruction(name='fc', ch='d0',
t0=0, phase='-P0*np.pi'),
t0=0, phase='-P1'),
PulseQobjInstruction(name='test_pulse_4', ch='d0', t0=0),
PulseQobjInstruction(name='fc', ch='d0',
t0=0, phase='-P1*np.pi')]),
t0=0, phase='-P0')]),
Command(name='u2', qubits=[1],
sequence=[PulseQobjInstruction(name='fc', ch='d1',
t0=0, phase='-P0*np.pi'),
t0=0, phase='-P1'),
PulseQobjInstruction(name='test_pulse_4', ch='d1', t0=0),
PulseQobjInstruction(name='fc', ch='d1',
t0=0, phase='-P0*np.pi')]),
t0=0, phase='-P0')]),
Command(name='u2', qubits=[2],
sequence=[PulseQobjInstruction(name='test_pulse_3', ch='d2', t0=0),
PulseQobjInstruction(name='fc', ch='d2',
t0=0, phase='-P0*np.pi')]),
t0=0, phase='-P0')]),
Command(name='u3', qubits=[0],
sequence=[PulseQobjInstruction(name='test_pulse_1', ch='d0', t0=0)]),
Command(name='u3', qubits=[1],
Expand Down
4 changes: 2 additions & 2 deletions test/python/providers/test_pulse_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def test_default_building(self):
self.assertTrue(self.inst_map.has('u3', (0,)))
self.assertTrue(self.inst_map.has('u3', 1))
self.assertTrue(self.inst_map.has('cx', (0, 1)))
self.assertEqual(self.inst_map.get_parameters('u1', 0), ('P1',))
u1_minus_pi = self.inst_map.get('u1', 0, P1=1)
self.assertEqual(self.inst_map.get_parameters('u1', 0), ('P0',))
u1_minus_pi = self.inst_map.get('u1', 0, P0=np.pi)
fc_cmd = u1_minus_pi.instructions[0][-1].command
self.assertEqual(fc_cmd.phase, -np.pi)

Expand Down
26 changes: 23 additions & 3 deletions test/python/pulse/test_cmd_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from qiskit.qobj.converters import QobjToInstructionConverter
from qiskit.qobj import PulseQobjInstruction
from qiskit.pulse import (CmdDef, SamplePulse, Schedule,
PulseError, PersistentValue)
PulseError, PersistentValue, FrameChange)
from qiskit.pulse.schedule import ParameterizedSchedule


Expand Down Expand Up @@ -162,8 +162,28 @@ def test_build_cmd_def(self):
pv_found = True
self.assertTrue(pv_found)

self.assertEqual(cmd_def.get_parameters('u1', 0), ('P1',))
self.assertEqual(cmd_def.get_parameters('u1', 0), ('P0',))

u1_minus_pi = cmd_def.get('u1', 0, P1=1)
u1_minus_pi = cmd_def.get('u1', 0, P0=np.pi)
fc_cmd = u1_minus_pi.instructions[0][-1].command
self.assertEqual(fc_cmd.phase, -np.pi)

def test_default_phases_parameters(self):
"""Test parameters for phases."""
defaults = self.backend.defaults()
cmd_def = defaults.build_cmd_def()

for i in range(2):
u1_phases = []
for _, instr in cmd_def.get('u1', i, P0=np.pi).instructions:
cmd = instr.command
if isinstance(cmd, FrameChange):
u1_phases.append(cmd.phase)
self.assertEqual(u1_phases, [-np.pi])

u2_phases = []
for _, instr in cmd_def.get('u2', i, P0=0, P1=np.pi).instructions:
cmd = instr.command
if isinstance(cmd, FrameChange):
u2_phases.append(cmd.phase)
self.assertEqual(u2_phases, [-np.pi, 0])

0 comments on commit aeeef37

Please sign in to comment.