Skip to content

Commit

Permalink
Tidy up the examples a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
gefux committed May 25, 2022
1 parent fec9ebb commit 839c97f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
13 changes: 7 additions & 6 deletions examples/mean-field-process.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ def H(t, field):
control=control,
start_time=0.0,
initial_state=initial_state)
with np.printoptions(precision=4):
for i,t in enumerate(dynamics._times):
print('t = {:.1f}\nField {:.8g}\nState\n{}'.format(t, dynamics._fields[i], dynamics._states[i]))

print(f"The the final time t = {dynamics.times[-1]:.1f} " \
+ "the field is {dynamics.fields[-1]:.8g} and the state is:")
print(dynamics.states[-1])


t, s_x = dynamics.expectations(oqupy.operators.sigma("x")/2, real=True)
t, s_z = dynamics.expectations(oqupy.operators.sigma("z")/2, real=True)
Expand All @@ -74,6 +76,5 @@ def H(t, field):
axes[0].set_ylabel('<Sz>')
axes[1].set_ylabel('n')
plt.tight_layout()
#plt.savefig('out.png', bbox_inches='tight')
stacked_data = np.array([t, dynamics._fields, dynamics._states], dtype=object)
#np.save('oqupy.npy', stacked_data)

plt.show()
11 changes: 5 additions & 6 deletions examples/mean-field-tempo.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ def H(t, field):
start_time=0.0,
parameters=tempo_parameters)
dynamics = tempo_sys.compute(end_time=end_time)
with np.printoptions(precision=4):
for i,t in enumerate(dynamics._times):
print('t = {:.1f}\nField {:.8g}\nState\n{}'.format(t, dynamics._fields[i], dynamics._states[i]))

print(f"The the final time t = {dynamics.times[-1]:.1f} " \
+ f"the field is {dynamics.fields[-1]:.8g} and the state is:")
print(dynamics.states[-1])

t, s_x = dynamics.expectations(oqupy.operators.sigma("x")/2, real=True)
t, s_z = dynamics.expectations(oqupy.operators.sigma("z")/2, real=True)
Expand All @@ -69,6 +69,5 @@ def H(t, field):
axes[0].set_ylabel('<Sz>')
axes[1].set_ylabel('n')
plt.tight_layout()
#plt.savefig('out.png', bbox_inches='tight')
stacked_data = np.array([t, dynamics._fields, dynamics._states], dtype=object)
#np.save('oqupy.npy', stacked_data)

plt.show()
19 changes: 10 additions & 9 deletions examples/tempo.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@
Sx=np.array([[0,0.5],[0.5,0]])
wc=0.0
kappa=0.1
end_time=1#.1
end_time=1

def H(t):
return 2.0 * gn * np.abs(field) * Sx

system = oqupy.TimeDependentSystem(H)
correlations = oqupy.PowerLawSD(alpha=a,
zeta=1,
cutoff=omega_cutoff,
cutoff_type='gaussian',
correlations = oqupy.PowerLawSD(alpha=a,
zeta=1,
cutoff=omega_cutoff,
cutoff_type='gaussian',
temperature=temperature)
bath = oqupy.Bath(oqupy.operators.sigma("z")/2.0, correlations)

Expand All @@ -45,7 +46,7 @@ def H(t):
start_time=0.0,
parameters=tempo_parameters)
dynamics = tempo_sys.compute(end_time=end_time)
with np.printoptions(precision=4):
for i,t in enumerate(dynamics._times):
print('t = {:.1f}\nState\n{}'.format(t, dynamics._states[i]))

print(f"The final state at t = {dynamics.times[-1]:.1f} is:")
print(dynamics.states[-1])

0 comments on commit 839c97f

Please sign in to comment.