From dcb37452ef6f012bab24bedc2b6bbb023c521882 Mon Sep 17 00:00:00 2001
From: unknown <asoalexandros@gmail.com>
Date: Tue, 10 Dec 2024 12:26:16 +0100
Subject: [PATCH] Changes  memristor 1-7

---
 hp4155/memristor (Version 4.0)/help.py        | 32 +++++----
 hp4155/memristor (Version 4.0)/help_pulse.py  |  3 +-
 hp4155/memristor (Version 4.0)/memristor.py   | 67 ++++++++-----------
 .../memristor_buttons.ipynb                   |  8 +--
 4 files changed, 53 insertions(+), 57 deletions(-)

diff --git a/hp4155/memristor (Version 4.0)/help.py b/hp4155/memristor (Version 4.0)/help.py
index 905a916..97d5da2 100644
--- a/hp4155/memristor (Version 4.0)/help.py	
+++ b/hp4155/memristor (Version 4.0)/help.py	
@@ -86,11 +86,11 @@ def contact_check(i,j,device):
     device.single_measurement()
     while device.operation_completed() == False:
         time.sleep(2)
-       
-    device.autoscaling()
+   
     R = device.return_values(f'R{i}{j}')[0] #only the first value
     print(f"R{i}{j}:{'{:.2e}'.format(R)} Ohm")
     device.del_user_functions()
+    device.autoscaling()
     return R
     
     
@@ -241,24 +241,31 @@ def sampling_check(voltage,device):
 
     device.user_function('R','OHM','V2/I2')
 
-    device.display_variable('X','@TIME')
+    device.display_variable('X','@INDEX')
     device.display_variable('Y1','R')
     device.single_measurement()
     while device.operation_completed() == False:
         time.sleep(2)
        
-    device.autoscaling()
-    R = device.return_values('R')
-    R = np.array(R)
+    index = np.array(device.return_values('@INDEX'))
+    R = np.array(device.return_values('R'))
     R_mean = np.average(R)
     device.del_user_functions()
+    device.autoscaling()
 
-    if np.max(R)/np.min(R)>10:
-        # red color code red = '\033[91m'
-        red = '\033[91m'
-        print()
+    # Plot the results
+    fig,ax = plt.subplots()
+    
+    ax.set_title(f"Average Resistance(Sampling Check):{'{:.2e}'.format(R_mean)} Ohm")
+    ax.set_yscale('log')
+    ax.set_ylabel('Resistance (Ohm)')
+    ax.set_xlabel('Sampling Index')
+    ax.set_xticks(index)
+    ax.scatter(index,np.absolute(R),label = f"Voltage={voltage}V")
+    ax.legend()
+    display(fig)
+    
     return R_mean
-  
 
 #new (retention)
 def retention(voltage,period,duration,device):
@@ -314,12 +321,13 @@ def retention(voltage,period,duration,device):
     while device.operation_completed() == False:
         time.sleep(2)
 
-    device.autoscaling()
+    
     TIME = device.return_values('@TIME')
     R = device.return_values('R')
     TIME = np.array(TIME)
     R = np.array(R)
     device.del_user_functions()
+    device.autoscaling()
     return TIME,R
     
 
diff --git a/hp4155/memristor (Version 4.0)/help_pulse.py b/hp4155/memristor (Version 4.0)/help_pulse.py
index 07992d3..d65e0d3 100644
--- a/hp4155/memristor (Version 4.0)/help_pulse.py	
+++ b/hp4155/memristor (Version 4.0)/help_pulse.py	
@@ -229,7 +229,7 @@ def constant_meas(dictionary,device):
     t1 = time.time()
     # get the execution time
     elapsed_time = t1 - t0
-    device.autoscaling()
+    
 
     I_i=device.return_values("I2")
     V_i=device.return_values("V2")
@@ -242,6 +242,7 @@ def constant_meas(dictionary,device):
     values = (V_i,I_i,R_i)
 
     device.del_user_functions()
+    device.autoscaling()
 
     return times,values
 
diff --git a/hp4155/memristor (Version 4.0)/memristor.py b/hp4155/memristor (Version 4.0)/memristor.py
index bd95d85..35a9900 100644
--- a/hp4155/memristor (Version 4.0)/memristor.py	
+++ b/hp4155/memristor (Version 4.0)/memristor.py	
@@ -6,6 +6,9 @@ from keyboard import add_hotkey,remove_hotkey
 # pulsed libraries
 from help_pulse import *
 
+import warnings
+warnings.filterwarnings("ignore")
+
 
 #create temporary file to store the results localy
 temp_file= os.path.join(os.getcwd(),'tempfile.txt')
@@ -195,7 +198,7 @@ device.disable_not_smu()
 def on_contact_check_clicked(b):
     global folder,temp_file
     with output:
-        clear_output(wait = True)
+        clear_output()
         change_state(all_widgets)
         device.inst.lock_excl()
 
@@ -219,7 +222,7 @@ def on_contact_check_clicked(b):
 def on_qcc_clicked(b):
     global folder,temp_file
     with output:
-        clear_output(wait = True)
+        clear_output()
         change_state(all_widgets)
         device.inst.lock_excl()
 
@@ -267,9 +270,8 @@ def on_set_button_clicked(b):
 
         if valid == True:
             if sampling.value == True: #do sampling set before set process(100mV)
-                R_mean_before = sampling_check(-0.01,device)
-                print(f"Average Resistance(Sampling Check):{'{:.2e}'.format(R_mean_before)} Ohm")
-                first_sampling = False
+                R_mean_before= sampling_check(-0.01,device)
+                 
                
             #execute measurement,plot results and save them
             V12,I12 = sweep(0,Vset.value,step.value,CC_vset.value,integration_time.value,device)
@@ -280,8 +282,6 @@ def on_set_button_clicked(b):
 
             if sampling.value == True: #do sampling set after set process(10mV)
                 R_mean_after = sampling_check(0.01,device)
-                print(f"Average Resistance(Sampling Check):{'{:.2e}'.format(R_mean_after)} Ohm")
-                first_sampling = False
             
             date = str(datetime.today().replace(microsecond=0))
             title = [f"SET Memristor at {date}",f"Set Voltage={Vset.value}V",f"current compliance={CC_vset.value}A"]
@@ -320,8 +320,6 @@ def on_reset_button_clicked(b):
         if valid == True:
             if sampling.value == True: #do sampling set before reset process(10mV)
                 R_mean_before = sampling_check(0.01,device)
-                print(f"Average Resistance(Sampling Check):{'{:.2e}'.format(R_mean_before)} Ohm")
-                first_sampling = False
             
             #execute measurement,plot results and save them
             V34,I34 = sweep(0,Vreset.value,step.value,CC_vreset.value,integration_time.value,device)
@@ -331,8 +329,6 @@ def on_reset_button_clicked(b):
             
             if sampling.value == True: #do sampling set after reset process(100mV)
                 R_mean_after = sampling_check(-0.01,device)
-                print(f"Average Resistance(Sampling Check):{'{:.2e}'.format(R_mean_after)} Ohm")
-                first_sampling = False
 
             date = str(datetime.today().replace(microsecond=0))
             title =[f"RESET Memristor at {date}",f"Reset Voltage={Vreset.value}V",f"current compliance={CC_vreset.value}A"]
@@ -382,7 +378,6 @@ def on_full_button_clicked(b):
             with open(temp_file,'a') as f:
                 header =[f"{number.value} full sweeps with parameters:",f"Set Voltage = {Vset.value}V",f"Current compliance set = {CC_vset.value}A",f"Reset Voltage = {Vreset.value}V",f"Current compliance reset = {CC_vreset.value}A"]
                 
-                plt.figure().clear()
                 fig, (ax1, ax2) = plt.subplots(2,sharex=True,figsize=(8,6)) #the plots share the same x axis 
                 fig.suptitle('FULL SWEEP')
                 ax1.set_title('Linear I')
@@ -402,12 +397,15 @@ def on_full_button_clicked(b):
                 add_hotkey("esc",break_loop)
                 #execute number of measurements
                 for i in range(number.value):#here it is easier to implement the sampling checks
-                    clear_output(wait = True)
+                    clear_output()
+                    if i>0 :
+                        display(fig)
                     if sampling.value == True: #before set(100mv)
                         R_mean_init = sampling_check(-0.01,device)
                         resistances.append(R_mean_init)
                         
                     V12,I12 = sweep(0,Vset.value,step.value,CC_vset.value,integration_time.value,device) #set
+                    plot_sweep(V12,I12,f"SET Iteration {i+1}")
                     
                     #after set/before reset
                     if sampling.value == True: #before set(10mv)
@@ -415,6 +413,12 @@ def on_full_button_clicked(b):
                         resistances.append(R_mean_set)
                     
                     V34,I34 = sweep(0,Vreset.value,step.value,CC_vreset.value,integration_time.value,device) #reset
+                    plot_sweep(V34,I34,f"RESET Iteration {i+1}")
+
+                    #after reset
+                    if sampling.value == True:#-0.1V
+                        R_mean_reset = sampling_check(-0.01,device)
+                        resistances.append(R_mean_reset)
 
                     #Quick Contact Check after reset Process 
                     if auto_qcc.value == True:
@@ -423,20 +427,13 @@ def on_full_button_clicked(b):
                         else: # OL
                             R = OL(device)
 
-                    #no reason to do check at the end because the next loop will do that(not anymore) more sampling checks
-
-                    #after reset
-                    if sampling.value == True:#-0.1V
-                        R_mean_reset = sampling_check(-0.01,device)
-                        resistances.append(R_mean_reset)
-
-
                     #butterfly curve
                     V=np.concatenate((V12,V34))
                     I=np.concatenate((I12,I34))
 
                     #create data frame and save to file
                     df = create_data_frame(V,I)
+                    display(df)
                     if i == 0 :
                         header.extend([f"{i+1} Iteration"])
                         title = header.copy()
@@ -451,16 +448,11 @@ def on_full_button_clicked(b):
                         title= [f"Quick Contact Check({qcc_select.value}) after Reset"]
                         write_to_file(temp_file,title,R)
 
-
                     #plot results
                     ax1.plot(V,I)
                     ax2.plot(V,np.absolute(I))
                     fig.tight_layout()
 
-                    #update plot 
-                    display(fig)
-                    display(df)
-
                     #check for loop termination
                     if stop == True:
                         information_box("Endurance stopped after esc!")
@@ -476,26 +468,21 @@ def on_full_button_clicked(b):
                 #plot resistances if sampling value == True or len(resistances) !=0
                 if len(resistances)!=0:
                     indexes = np.arange(1,len(resistances)+1)
-                    resistances = np.array(resistances)
+                    resistances = np.absolute(resistances)
                 
-                    plt.figure().clear()
                     fig, ax = plt.subplots()
                     
-                    fig.suptitle('Resistance')
-                    ax.set(xlabel='Index',ylabel='Resistance(Ohm)')
-                    ax.set_yscale('log')
-                    plt.scatter(indexes,resistances)
-                    plt.show()
-                    #print(len(resistances))
-                    #print(indexes)
-        
+                    fig.suptitle('Average Resistances from sampling checks')
+                    ax.set(xlabel='Index',ylabel='Resistance(Ohm)',yscale='log')
+                    ax.scatter(indexes,resistances)
+                    display(fig)
+
+
             #upload results
             temp_file,file,folder=upload_results(temp_file,file,folder)
         
         #unlock the device
         device.inst.unlock()
-
-        
         change_state(all_widgets)
 
 
@@ -543,7 +530,7 @@ def on_retention_button_clicked(b):
 
 def on_sweep_button_clicked(b):
     with output:
-        clear_output(wait = True)
+        clear_output()
         change_state(all_widgets)
         check_pulse(sweep_dict)
 
@@ -565,7 +552,7 @@ def on_sweep_button_clicked(b):
 def on_constant_button_clicked(b):
     with output:
         global first
-        clear_output(wait = True)
+        clear_output()
         change_state(all_widgets)
         
         check_pulse(sweep_dict)
diff --git a/hp4155/memristor (Version 4.0)/memristor_buttons.ipynb b/hp4155/memristor (Version 4.0)/memristor_buttons.ipynb
index 35144fd..43f6979 100644
--- a/hp4155/memristor (Version 4.0)/memristor_buttons.ipynb	
+++ b/hp4155/memristor (Version 4.0)/memristor_buttons.ipynb	
@@ -9,7 +9,7 @@
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "e907a7767009491da92ac730cb310874",
+       "model_id": "6e4058bf902d421babfc628c5663e9e9",
        "version_major": 2,
        "version_minor": 0
       },
@@ -23,7 +23,7 @@
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "3ebd085796c54e8daaac92ddf5309393",
+       "model_id": "862dbbbc94c04ff29613fa11d666c2b1",
        "version_major": 2,
        "version_minor": 0
       },
@@ -37,7 +37,7 @@
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "90dc92bfe8374348bc680caf722f494e",
+       "model_id": "b48ee34dc7774e778bc91cf196269652",
        "version_major": 2,
        "version_minor": 0
       },
@@ -74,7 +74,7 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "ca8f0bc8-670c-4deb-bedb-8d5d92b978f2",
+   "id": "01f338ba-d3a5-47ec-993e-53866010308b",
    "metadata": {},
    "outputs": [],
    "source": []
-- 
GitLab