jet.interpreter.run_xir_program

run_xir_program(program: xir.program.Program)List[Union[numpy.number, numpy.ndarray]][source]

Executes an XIR program.

Raises

ValueError – If the given program contains an unsupported gate or output statement or an invalid gate definition.

Parameters

program (xir.Program) – XIR program to execute.

Returns

List of NumPy values representing the output of the XIR program.

Return type

List[Union[np.number, np.ndarray]]

Example

Consider the following XIR script which generates a Bell state and then measures the amplitude of each basis state:

H | [0];
CNOT | [0, 1];

amplitude(state: [0, 0]) | [0, 1];
amplitude(state: [0, 1]) | [0, 1];
amplitude(state: [1, 0]) | [0, 1];
amplitude(state: [1, 1]) | [0, 1];

If the contents of this script are stored in a string called xir_script, then each amplitude of the Bell state can be displayed using Jet as follows:

import jet
import xir

# Parse the XIR script into an XIR program.
xir_program = xir.parse_script(xir_script)

# Run the XIR program using Jet and wait for the results.
result = jet.run_xir_program(xir_program)

# Display the returned amplitudes.
for i, amp in enumerate(result):
    print(f"Amplitude |{i:02b}> = {amp}")