Skip to content

Commit

Permalink
Merge pull request #134 from BoxiLi/bug-fix
Browse files Browse the repository at this point in the history
Fix a bug in the pulse paper code
  • Loading branch information
BoxiLi committed Apr 17, 2022
2 parents 474089d + 5326ef4 commit bb7d15c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 0 additions & 7 deletions .vscode/settings.json

This file was deleted.

8 changes: 6 additions & 2 deletions doc/pulse-paper/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from qutip_qip.circuit import QubitCircuit, Gate
from qutip_qip.device import ModelProcessor, Model
from qutip_qip.compiler import GateCompiler, Instruction
from qutip import Options
from qutip import Options, fidelity
from qutip_qip.noise import Noise


Expand Down Expand Up @@ -94,6 +94,7 @@ def single_qubit_gate_compiler(self, gate, args):
# gate.arg_value is the rotation angle
tlist = np.abs(gate.arg_value) / self.params["pulse_amplitude"]
coeff = self.params["pulse_amplitude"] * np.sign(gate.arg_value)
coeff /= 2 * np.pi
if gate.name == "RX":
return self.generate_pulse(gate, tlist, coeff, phase=0.0)
elif gate.name == "RY":
Expand All @@ -112,6 +113,7 @@ def rotation_with_phase_compiler(self, gate, args):
# gate.arg_value is the pulse phase
tlist = self.params["duration"]
coeff = self.params["pulse_amplitude"]
coeff /= 2 * np.pi
return self.generate_pulse(gate, tlist, coeff, phase=gate.arg_value)


Expand All @@ -121,14 +123,16 @@ def rotation_with_phase_compiler(self, gate, args):
circuit = QubitCircuit(1)
circuit.add_gate("RX", targets=0, arg_value=np.pi / 2)
circuit.add_gate("Z", targets=0)
result1 = circuit.run(basis(2, 0))

myprocessor = ModelProcessor(model=MyModel(num_qubits))
myprocessor.native_gates = ["RX", "RY"]

mycompiler = MyCompiler(num_qubits, {"pulse_amplitude": 0.02})

myprocessor.load_circuit(circuit, compiler=mycompiler)
result = myprocessor.run_state(basis(2, 0))
result2 = myprocessor.run_state(basis(2, 0)).states[-1]
assert(abs(fidelity(result1, result2) - 1) < 1.e-5)

fig, ax = myprocessor.plot_pulses(
figsize=(LINEWIDTH * 0.7, LINEWIDTH / 2 * 0.7), dpi=200,
Expand Down

0 comments on commit bb7d15c

Please sign in to comment.