1313plt .rcParams .update ({"text.usetex" : False , "font.size" : 10 })
1414from joblib import Parallel , delayed # for parallel simulations
1515import numpy as np
16- from qutip import sigmax , sigmay , sigmaz , basis , qeye , tensor , Qobj , fock_dm
16+ from qutip import (
17+ fidelity , sigmax , sigmay , sigmaz , basis , qeye , tensor , Qobj , fock_dm )
1718from qutip_qip .circuit import QubitCircuit , Gate
1819from qutip_qip .device import ModelProcessor , Model
1920from qutip_qip .compiler import GateCompiler , Instruction
20- from qutip import Options
21+ import qutip
22+ from packaging .version import parse as parse_version
23+ if parse_version (qutip .__version__ ) < parse_version ('5.dev' ):
24+ from qutip import Options as SolverOptions
25+ else :
26+ from qutip import SolverOptions
2127from qutip_qip .noise import Noise
2228
2329
@@ -94,6 +100,7 @@ def single_qubit_gate_compiler(self, gate, args):
94100 # gate.arg_value is the rotation angle
95101 tlist = np .abs (gate .arg_value ) / self .params ["pulse_amplitude" ]
96102 coeff = self .params ["pulse_amplitude" ] * np .sign (gate .arg_value )
103+ coeff /= 2 * np .pi
97104 if gate .name == "RX" :
98105 return self .generate_pulse (gate , tlist , coeff , phase = 0.0 )
99106 elif gate .name == "RY" :
@@ -112,6 +119,7 @@ def rotation_with_phase_compiler(self, gate, args):
112119 # gate.arg_value is the pulse phase
113120 tlist = self .params ["duration" ]
114121 coeff = self .params ["pulse_amplitude" ]
122+ coeff /= 2 * np .pi
115123 return self .generate_pulse (gate , tlist , coeff , phase = gate .arg_value )
116124
117125
@@ -121,14 +129,16 @@ def rotation_with_phase_compiler(self, gate, args):
121129circuit = QubitCircuit (1 )
122130circuit .add_gate ("RX" , targets = 0 , arg_value = np .pi / 2 )
123131circuit .add_gate ("Z" , targets = 0 )
132+ result1 = circuit .run (basis (2 , 0 ))
124133
125134myprocessor = ModelProcessor (model = MyModel (num_qubits ))
126135myprocessor .native_gates = ["RX" , "RY" ]
127136
128137mycompiler = MyCompiler (num_qubits , {"pulse_amplitude" : 0.02 })
129138
130139myprocessor .load_circuit (circuit , compiler = mycompiler )
131- result = myprocessor .run_state (basis (2 , 0 ))
140+ result2 = myprocessor .run_state (basis (2 , 0 )).states [- 1 ]
141+ assert (abs (fidelity (result1 , result2 ) - 1 ) < 1.e-5 )
132142
133143fig , ax = myprocessor .plot_pulses (
134144 figsize = (LINEWIDTH * 0.7 , LINEWIDTH / 2 * 0.7 ), dpi = 200 ,
@@ -209,7 +219,7 @@ def single_crosstalk_simulation(num_gates):
209219 init_state = tensor (
210220 [Qobj ([[init_fid , 0 ], [0 , 0.025 ]]), Qobj ([[init_fid , 0 ], [0 , 0.025 ]])]
211221 )
212- options = Options (nsteps = 10000 ) # increase the maximal allowed steps
222+ options = SolverOptions (nsteps = 10000 ) # increase the maximal allowed steps
213223 e_ops = [tensor ([qeye (2 ), fock_dm (2 )])] # observable
214224
215225 # compute results of the run using a solver of choice with custom options
0 commit comments