Skip to content

Fix xy angle sign #232

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

Merged
merged 8 commits into from
Aug 12, 2022
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 @@ -21,6 +21,7 @@ This Changelog tracks all past changes to this project as well as details about
- `added` proper physics simulation of circuits using qiskit interface #165
- `added` coupling element which depends on frequency of connected qubits #211
- `added` model subclass with an arbitrary specified basis change for simulations #220
- `fixed` wrong direction of rotations on bloch sphere #231

## Version `1.4` - 23 Dec 2021

Expand Down
2 changes: 1 addition & 1 deletion c3/signal/gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def get_awg_signal(self, chan, ts):

xy_angle = comp.params["xy_angle"].get_value()
freq_offset = comp.params["freq_offset"].get_value()
phase = -xy_angle - freq_offset * ts_off
phase = xy_angle - freq_offset * ts_off
env = comp.get_shape_values(ts_off, t_end - t_start)
env = tf.cast(env, tf.complex128)

Expand Down
3 changes: 2 additions & 1 deletion test/test_awg.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def test_AWG_phase_shift() -> None:
rect.params["xy_angle"] = Qty(phase, "pi")

sigs = generator.generate_signals(rectangle)
correct_signal = np.cos(2 * np.pi * lo_freq_q1 * sigs["d1"]["ts"] + phase * np.pi)
# -phase because of legacy xy_angle sign convention
correct_signal = np.cos(2 * np.pi * lo_freq_q1 * sigs["d1"]["ts"] - phase * np.pi)
print(sigs["d1"]["values"])
np.testing.assert_allclose(
sigs["d1"]["values"].numpy(),
Expand Down
18 changes: 17 additions & 1 deletion test/test_instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import hjson

from c3.libraries.fidelities import unitary_infid
from c3.signal.gates import Instruction

from c3.c3objs import Quantity, hjson_decode, hjson_encode
Expand All @@ -15,7 +16,7 @@
import numpy as np
import pytest
from c3.libraries.constants import GATES

from examples.single_qubit_experiment import create_experiment

model = Model()
model.read_config("test/test_model.cfg")
Expand Down Expand Up @@ -187,3 +188,18 @@ def test_set_name_ideal():
assert (instr.ideal == GATES["ry90p"]).all()
instr.set_name("crzp")
assert (instr.ideal == GATES["crzp"]).all()


@pytest.mark.unit
def test_correct_bloch_rotation_direction():
# makes sure that the rotations on the bloch sphere are in the right direction
GATE_NAME = 'ry90p[0]'
exp = create_experiment()
exp.compute_propagators()
# TODO - remove this line after the ideal updating bug gets fixed...
exp.pmap.instructions[GATE_NAME].set_ideal(None)

ideal_gate = exp.pmap.instructions[GATE_NAME].get_ideal_gate(dims=[3])
propagator = exp.propagators[GATE_NAME].numpy()
# not equal to one because of imperfections in the propagation
np.testing.assert_array_less(unitary_infid(ideal_gate, propagator, dims=[3]).numpy()[0], 0.05)
9 changes: 9 additions & 0 deletions test/test_model_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ def test_model_learning() -> None:
exp.pmap.set_opt_map(
[[tuple(par) for par in pset] for pset in cfg.pop("exp_opt_map")]
)

# -phase because of legacy xy_angle sign convention
for instruction in exp.pmap.instructions.values():
for comp in instruction.comps.values():
for pulse in comp.values():
if "xy_angle" in pulse.params:
pulse.params["xy_angle"] *= -1


opt = ModelLearning(**cfg, pmap=exp.pmap)
opt.set_exp(exp)
opt.set_created_by(OPT_CONFIG_FILE_NAME)
Expand Down
7 changes: 7 additions & 0 deletions test/test_tunable_coupler.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@
parameter_map = PMap(instructions=[crzp], model=model, generator=generator)
exp = Exp(pmap=parameter_map)

# -phase because of legacy xy_angle sign convention
for instruction in exp.pmap.instructions.values():
for comp in instruction.comps.values():
for pulse in comp.values():
if "xy_angle" in pulse.params:
pulse.params["xy_angle"] *= -1

##### TESTING ######

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