Hardware and cloud¶
Using Strawberry Fields, you can submit quantum programs to be executed on photonic hardware or to be run on a cloud simulator via the Xanadu Cloud.
Warning
An API key is required to communicate with the hardware locally. Set up a Xanadu Cloud account for free, and generate your cloud API key.
Configuring your account¶
Before using the Xanadu Cloud platform, you will need to configure your
credentials using the Xanadu Cloud Client. The simplest way
to do this is through the xcc config
command line interface:
$ xcc config set REFRESH_TOKEN "Xanadu Cloud API key goes here"
You can verify that your account credentials successfully authenticate against the Xanadu Cloud platform by running
$ xcc ping
Successfully connected to the Xanadu Cloud.
Submitting jobs on hardware¶
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 Result
object once the computation is
complete, this method instead returns a xcc.Job
object directly that can be queried
to get the job’s status.
>>> job = engine.run_async(prog, shots=3)
>>> job.status
"queued"
>>> job.wait()
>>> job.status
"complete"
>>> result = sf.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]])
Further details on the xcc.Job
class can be found in the
Xanadu Cloud Client documentation.
Alternatively, if you have your compiled quantum program available as a Blackbird script, you can submit the Blackbird script file to be executed remotely using the Xanadu Cloud Client command line interface:
$ xcc job submit \
--name "example" \
--target "X8_01" \
--language "blackbird:1.0" \
--circuit "name example\nversion 1.0\ntarget X8_01 (shots=3)\n ..."
Cloud simulator¶
In addition to submitting jobs to be run on quantum hardware, it is also
possible to run jobs on cloud simulators (which we refer to as “simulons”) via
the Xanadu Quantum Cloud. The process is very similar to running jobs on
hardware. You will need to configure your account, as described above, and
submit a job via the RemoteEngine
, using a simulator as the target instead
of a specific chip:
>>> eng = sf.RemoteEngine("simulon_gaussian")
>>> result = eng.run(prog)
Simulator jobs can also be submitted asynchronously using eng.run_async
, or
by submitting a Blackbird script with the target
set to a simulator target
in the Blackbird header.
See the Submitting jobs on hardware section above for more details.
Note
The simulon_gaussian
simulator runs on the gaussian
backend (see
Simulating your program) and thus only supports Gaussian operations,
including homodyne and heterodyne measurements, as well terminal Fock
measurements. Note that there are limits to how many measurements a circuit
can have depending on the type of measurement. These can be retrieved by
calling engine.device_spec.modes
with engine =
sf.RemoteEngine("simulon_gaussian")
.
Tutorials¶
For more details on submitting jobs to photonic hardware, check out the following tutorials.