liveBook · Manning

Qsharp.run

As explained in Quantum Programming in Depth

qsharp.run is a Python API method that executes a Q# operation using a simulator instance.

qsharp.run executes a Q# operation from Python through a simulator instance. Unlike qsharp.eval, it supports repeated test shots, creating a new simulator instance for each execution. section 4.1.3

Running a Q# test

Initialize the project, then call qsharp.run("Test.TestReadInformation()", shots=100) to execute the Q# test repeatedly. The Q# operation generates random basis-state cases and validates each measurement result. section 4.1.3

import qsharp

def test_read_info():
  qsharp.init(project_root='.')
  qsharp.run("Test.TestReadInformation()", shots=100)
  

Use this compact Python wrapper as the execution pattern for Q# tests whose testing logic resides in Q#. section 4.1.3

How Quantum Programming in Depth covers it

How deep it goes
Demonstrates a wrapper call with initialization and shots, but defers simulator internals and API behavior beyond testing.
Examples
Runs Test.TestReadInformation with 100 shots after initializing the project root.
What it assumes
Assumes a Q# operation, a Python wrapper, and an initialized project root.
What you can do after
Operate it to execute and repeat Q# tests through a Python wrapper.
How it connects
Connects Python wrappers with Q# operations, qsharp.eval, simulator instances, and randomized testing.

This explainer was generated by Manning's knowledge graph from the text of Quantum Programming in Depth. The section links point to the parts of the book it draws on.