# SETUP (common to all tutorials) 
import fermioniq 
client = fermioniq.Client() # Initialize the client (assumes environment variables are set) 

import rich # Module for pretty printing 
import nest_asyncio # Necessary only for Jupyter, can be omitted in .py files 
nest_asyncio.apply() 

1) Running a circuit#

We’ll start with creating a circuit, use it to create an emulation job, and then submit that job for running on the emulator. Currently we support circuits from Qiskit and Cirq. We’ll use Qiskit for these tutorials.

from qiskit import QuantumCircuit

def qiskit_bell_pair():
  circuit = QuantumCircuit(2)
  circuit.h(0)
  circuit.cx(0, 1)
  return circuit

circuit = qiskit_bell_pair()

# Create an emulator job
emulator_job = fermioniq.EmulatorJob(circuit=circuit)

# Send job and wait for the results
result = client.schedule_and_wait(emulator_job)

Running the job via schedule_and_wait will block program execution until the job is complete, in which case result will hold the results of the job. For asynchronous running, see Tutorial 4.

The results can be printed in a pretty way by using the Rich python library.

rich.print(result)
rich.print(result.job_metadata)

Alternatively, you can print the raw output using the usual print command. This is best done via the {amplitudes(), samples(), expectation_values(), metadata(), config()} methods of the output object, by specifying the circuit number and run number (both 0 if there was only a single emulation performed).

# Amplitudes
print("Amplitudes:", result.amplitudes(circuit_number=0, run_number=0))

# Samples
print("Samples:", result.samples(circuit_number=0, run_number=0))

# Expectation values
print("Expectation values:", result.expectation_values(circuit_number=0, run_number=0))

# Metadata
print("Metadata:", result.run_metadata(circuit_number=0, run_number=0))

# Config
print("Config:", result.config(circuit_number=0, run_number=0))

# Whole result
print("All output data:", result)