Photonic hardware

Using Strawberry Fields, you can submit quantum programs to be executed on photonic hardware using the Xanadu cloud platform.

Warning

An authentication token is required to access the Xanadu cloud platform. In the following, replace AUTHENTICATION_TOKEN with your personal API token.

If you do not have an authentication token, you can request hardware access via email at sf@xanadu.ai.

Configuring your account

Before using the Xanadu cloud platform, you will need to configure your credentials. This can be done using several methods:

  • Configuration file (recommended). Use the Strawberry Fields store_account() function from within Python or a Jupyter notebook,

    >>> sf.store_account("AUTHENTICATION_TOKEN")
    

    or the sf configure command line interface,

    $ sf configure --token AUTHENTICATION_TOKEN
    

    to store a configuration file containing your credentials. Replace AUTHENTICATION_TOKEN above with your Xanadu cloud access token.

    Note

    The above configuration file need only be created once. Once created, Strawberry Fields will automatically load the stored authentication credentials.

  • Environment variables. Set the SF_API_AUTHENTICATION_TOKEN environment variable with your API token.

  • Keyword argument. Pass the keyword argument token when initializing the RemoteEngine.

See also

For more details on configuring Strawberry Fields for cloud access, including creating local per-project configuration files, see the configuration module and store_account() function.

Verifying your connection

To verify that your account credentials correctly authenticate against the cloud platform, the ping() function can be used from within Python,

>>> sf.ping()
You have successfully authenticated to the platform!

or the ping flag can be used on the command line:

$ sf --ping
You have successfully authenticated to the platform!

Submitting jobs

Once connected to the Xanadu cloud platform, the Strawberry Fields RemoteEngine can be used to submit quantum programs to available photonic hardware:

>>> eng = sf.RemoteEngine("chip_name")
>>> result = eng.run(prog)

In the above example, eng.run() is a blocking method; Python will wait until the job result has been returned from the cloud before further lines will execute.

Jobs can also be submitted using the non-blocking eng.run_async() method. Unlike eng.run(), which returns a Results object once the computation is complete, this method instead returns a Job object directly that can be queried to get the job’s status.

>>> job = engine.run_async(prog, shots=3)
>>> job.status
"queued"
>>> job.refresh()
>>> job.status
"complete"
>>> result = job.result
>>> result.samples
array([[0, 0, 1, 0, 1, 0, 1, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 2]])

Job objects have the following properties and methods:

id

The job ID.

status

Returns the current job status, with possible values including "open", "queued", "cancelled", "complete", and "failed".

result

Returns the Result of a completed job.

refresh()

Refreshes the status and metadata of an open or queued job, along with the job result if the job is newly completed.

cancel()

Cancels an open or queued job.

Alternatively, if you have your quantum program available as a Blackbird script, you can submit the Blackbird script file to be executed remotely using the Strawberry Fields command line interface:

$ sf run blackbird_script.xbb --output out.txt

After executing the above command, the result will be stored in out.txt in the current working directory. You can also omit the --output parameter to print the result to the screen.

Tutorials

For more details on submitting jobs to photonic hardware, check out the following tutorials.