Skip to content

Commit 01cd657

Browse files
Fix xy angle sign (#232)
* Changed sign of xy_angle in phase * Added to changelog * Created test * Changed sign of phase in correct_signal to match reality * Properly use np testing * Fixed tests to adhere to new phase sign convention
1 parent 76bdf7b commit 01cd657

File tree

6 files changed

+37
-3
lines changed

6 files changed

+37
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This Changelog tracks all past changes to this project as well as details about
2121
- `added` proper physics simulation of circuits using qiskit interface #165
2222
- `added` coupling element which depends on frequency of connected qubits #211
2323
- `added` model subclass with an arbitrary specified basis change for simulations #220
24+
- `fixed` wrong direction of rotations on bloch sphere #231
2425

2526
## Version `1.4` - 23 Dec 2021
2627

c3/signal/gates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def get_awg_signal(self, chan, ts):
318318

319319
xy_angle = comp.params["xy_angle"].get_value()
320320
freq_offset = comp.params["freq_offset"].get_value()
321-
phase = -xy_angle - freq_offset * ts_off
321+
phase = xy_angle - freq_offset * ts_off
322322
env = comp.get_shape_values(ts_off, t_end - t_start)
323323
env = tf.cast(env, tf.complex128)
324324

test/test_awg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def test_AWG_phase_shift() -> None:
6161
rect.params["xy_angle"] = Qty(phase, "pi")
6262

6363
sigs = generator.generate_signals(rectangle)
64-
correct_signal = np.cos(2 * np.pi * lo_freq_q1 * sigs["d1"]["ts"] + phase * np.pi)
64+
# -phase because of legacy xy_angle sign convention
65+
correct_signal = np.cos(2 * np.pi * lo_freq_q1 * sigs["d1"]["ts"] - phase * np.pi)
6566
print(sigs["d1"]["values"])
6667
np.testing.assert_allclose(
6768
sigs["d1"]["values"].numpy(),

test/test_instruction.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import hjson
55

6+
from c3.libraries.fidelities import unitary_infid
67
from c3.signal.gates import Instruction
78

89
from c3.c3objs import Quantity, hjson_decode, hjson_encode
@@ -15,7 +16,7 @@
1516
import numpy as np
1617
import pytest
1718
from c3.libraries.constants import GATES
18-
19+
from examples.single_qubit_experiment import create_experiment
1920

2021
model = Model()
2122
model.read_config("test/test_model.cfg")
@@ -187,3 +188,18 @@ def test_set_name_ideal():
187188
assert (instr.ideal == GATES["ry90p"]).all()
188189
instr.set_name("crzp")
189190
assert (instr.ideal == GATES["crzp"]).all()
191+
192+
193+
@pytest.mark.unit
194+
def test_correct_bloch_rotation_direction():
195+
# makes sure that the rotations on the bloch sphere are in the right direction
196+
GATE_NAME = 'ry90p[0]'
197+
exp = create_experiment()
198+
exp.compute_propagators()
199+
# TODO - remove this line after the ideal updating bug gets fixed...
200+
exp.pmap.instructions[GATE_NAME].set_ideal(None)
201+
202+
ideal_gate = exp.pmap.instructions[GATE_NAME].get_ideal_gate(dims=[3])
203+
propagator = exp.propagators[GATE_NAME].numpy()
204+
# not equal to one because of imperfections in the propagation
205+
np.testing.assert_array_less(unitary_infid(ideal_gate, propagator, dims=[3]).numpy()[0], 0.05)

test/test_model_learning.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ def test_model_learning() -> None:
4646
exp.pmap.set_opt_map(
4747
[[tuple(par) for par in pset] for pset in cfg.pop("exp_opt_map")]
4848
)
49+
50+
# -phase because of legacy xy_angle sign convention
51+
for instruction in exp.pmap.instructions.values():
52+
for comp in instruction.comps.values():
53+
for pulse in comp.values():
54+
if "xy_angle" in pulse.params:
55+
pulse.params["xy_angle"] *= -1
56+
57+
4958
opt = ModelLearning(**cfg, pmap=exp.pmap)
5059
opt.set_exp(exp)
5160
opt.set_created_by(OPT_CONFIG_FILE_NAME)

test/test_tunable_coupler.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,13 @@
283283
parameter_map = PMap(instructions=[crzp], model=model, generator=generator)
284284
exp = Exp(pmap=parameter_map)
285285

286+
# -phase because of legacy xy_angle sign convention
287+
for instruction in exp.pmap.instructions.values():
288+
for comp in instruction.comps.values():
289+
for pulse in comp.values():
290+
if "xy_angle" in pulse.params:
291+
pulse.params["xy_angle"] *= -1
292+
286293
##### TESTING ######
287294

288295
with open("test/tunable_coupler_data.pickle", "rb") as filename:

0 commit comments

Comments
 (0)