quairkit.loss.distance¶
The source file of the class for the distance.
- class quairkit.loss.distance.TraceDistance(target_state)¶
The class of the loss function to compute the trace distance.
This interface can make you using the trace distance as the loss function.
from quairkit.database import one_state, bell_state, random_state # Single state example target_state = one_state(1) # Define target input_state = bell_state(1) # Define input trace_distance = TraceDistance(target_state) result = trace_distance(input_state) print('Single state distance:', result) # Output: tensor(0.7071) # Batched states example target_state_batch = random_state(num_systems=1, size=2) # Batch of 2 targets input_state_batch = random_state(num_systems=1, size=2) # Batch of 2 inputs trace_distance = TraceDistance(target_state_batch) batch_result = trace_distance(input_state_batch) print('Batched distances:', batch_result) # Output: tensor([0.7912, 0.7283])
Single state distance: tensor(0.7071) Batched distances: tensor([0.7912, 0.7283])
- class quairkit.loss.distance.StateFidelity(target_state)¶
The class of the loss function to compute the state fidelity.
This interface can make you using the state fidelity as the loss function.
from quairkit.database import one_state, bell_state, random_state # Single state example target_state = one_state(1) # Define target input_state = bell_state(1) # Define input fidelity_calculator = StateFidelity(target_state) result = fidelity_calculator(input_state) print('Single state fidelity:', result) # Output: tensor(0.7071) # Batched states example target_batch = random_state(num_systems=1, size=2) # Batch of 2 targets input_batch = random_state(num_systems=1, size=2) # Batch of 2 inputs fidelity_calculator = StateFidelity(target_batch) batch_result = fidelity_calculator(input_batch) print('Batched fidelities:', batch_result) # Output: tensor([0.5658, 0.7090]) :: Single state fidelity: tensor(0.7071) Batched fidelities: tensor([0.5658, 0.7090])