Boulder Opal / Toolkit / Design / Represent time-varying signals / How to create analytical signals for simulation and optimization / How to create analytical signals for simulation and optimization
Boulder Opal contains analytical signals in the form of piecewise-constant functions (Pwcs), which can be used for simulation and optimization.
The full list of Pwc analytical signals is available in the reference documentation.
All signals require a duration, defining the time interval for the signal between zero and duration.
The signals also require a segment_count, which determines the number of segments in the Pwc.
Many of the signal parameters can be passed as tensors and thus can be optimized to minimize a given cost function.
In this notebook we show how to create signals for use in simulation and optimization.
You can also define your own analytical Hamiltonians from the ground up, see this user guide for more information.
Once a graph has been set up for the system, create a Pwc analytic signal using one of the signals from the signal library.
If one is running an optimization problem, define the optimizable signal parameters using graph.optimization_variable or graph.optimizable_scalar, before defining the signal.
Then add the signal (multiplied by the appropriate operator) to the Hamiltonian.
With the graph object created, a simulation can be run using the boulderopal.execute_graph function. The outputs and the graph must be provided. The function returns the results of the simulation.
where is the amplitude,
is the width of the Gaussian,
is the center of the signal, and
is the flat duration.
import matplotlib.pyplot as plt
import numpy as np
import qctrlvisualizer as qv
import boulderopal as bo
plt.style.use(qv.get_qctrl_style())
# Create the data flow graph describing the system.
graph = bo.Graph()
# Define the duration of the pulse.
duration = 4e-6 # s
# Define the parameters of the pulse.
# Use a minimal segmentation for a more efficient sampling.
pulse = graph.signals.gaussian_pulse_pwc(
duration=duration,
segment_count=100,
amplitude=2 * np.pi * 1.0e6, # rad/s
width=duration * 0.1,
flat_duration=duration * 0.2,
segmentation="MINIMAL",
name="$\\Omega$",
)
# Add the pulse terms to the Hamiltonian.
hamiltonian = graph.hermitian_part(
pulse * graph.pauli_kronecker_product([("M", 0)], subsystem_count=2)
)
# Add the qubit-qubit coupling terms to the Hamiltonian.
couplings = {"X": 8.0e6, "Y": 8.0e6, "Z": 9.0e6} # rad/s
for i, coupling in couplings.items():
hamiltonian += coupling * graph.pauli_kronecker_product(
[(i, 0), (i, 1)], subsystem_count=2
)
sample_times = np.linspace(0.0, duration, 100)
# Compute the unitary using `time_evolution_operators_pwc`.
unitaries = graph.time_evolution_operators_pwc(
hamiltonian=hamiltonian, sample_times=sample_times
)
# Define the initial state.
initial_state = graph.fock_state(4, 0)[:, None]
# Evolve the initial state with the unitary to get the final state.
evolved_states = unitaries @ initial_state
evolved_states.name = "states"
# Run simulation.
result = bo.execute_graph(graph=graph, output_node_names=["$\\Omega$", "states"])
Your task (action_id="1829414") has completed.
# Plot the evolution of the populations of the qubits using `plot_population_dynamics`.
states = result["output"].pop("states")
qubit_populations = np.abs(states["value"].squeeze()) ** 2
qv.plot_population_dynamics(
sample_times, {rf"$|{k:02b}\rangle$": qubit_populations[:, k] for k in range(4)}
)
# View the generated Gaussian pulse using the `plot_controls` function.
qv.plot_controls(result["output"])
Your task (action_id="1829415") has started.
Your task (action_id="1829415") has completed.
Optimized cost: 1.711e-09
# Check that the unitary operator associated with the evolution of the system Hamiltonian
# does indeed correspond to an X gate.
result["output"].pop("unitary")["value"].round(5)
# Print out the converged signal parameters.
print("Alpha signal")
for param in ["start_value", "end_value"]:
print(f"\t{param}: \t{result['output'].pop(f'alpha_{param}')['value']:.3e} rad/s")
for param in ["ramp_duration", "center_time"]:
print(f"\t{param}: \t{result['output'].pop(f'alpha_{param}')['value']:.3e} s")
print("Gamma signal")
for param in ["amplitude"]:
print(f"\t{param}: \t{result['output'].pop(f'gamma_{param}')['value']:.3e} rad/s")
Alpha signal
start_value: 2.726e+06 rad/s
end_value: -5.867e+06 rad/s
ramp_duration: 1.451e-06 s
center_time: 1.500e-06 s
Gamma signal
amplitude: 4.031e+06 rad/s
# View the optimized signals using the `plot_controls` function.
qv.plot_controls(result["output"])
Was this useful?
New to Boulder Opal?
Get access to everything you need to automate and optimize quantum hardware performance at scale.