You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/hardware/ionq/service.md
+21-21Lines changed: 21 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# IonQ API Service
2
2
3
3
IonQ's API provides a way to execute quantum circuits on IonQ's trapped ion quantum computers
4
-
or on cloud based simulators. As of April 2021 this access is restricted to partners.
4
+
or on cloud based simulators. As of April 2021, this access is restricted to partners.
5
5
See [Access and Authentication](access.md) for details of access.
6
6
7
7
## Service class
@@ -10,14 +10,16 @@ The main entrance for accessing IonQ's API are instances of the `cirq_ionq.Servi
10
10
These objects need to be initialized with an api key, see
11
11
[Access and Authentication](access.md) for details.
12
12
13
-
The basic flow of running a quantum circuit in a blocking manner is
13
+
The basic steps for running a quantum circuit in a blocking manner are:
14
+
14
15
1. Create a circuit to run.
15
-
1. Create a `cirq_ionq.Service` with proper authentication and endpoints.
16
+
2. Create a `cirq_ionq.Service` with proper authentication and endpoints.
16
17
3. Submit this circuit to run on the service and await the results of this call.
17
18
(Or alternatively use asynchronous jobs and processing)
18
19
4. Transform the results in a form that is most useful for your analysis.
19
20
20
-
Here is a simple example of this flow
21
+
Here is a simple example of this flow:
22
+
21
23
```python
22
24
import cirq
23
25
import cirq_ionq as ionq
@@ -31,20 +33,20 @@ circuit = cirq.Circuit(
31
33
32
34
# Create a ionq.Service object.
33
35
# Replace API_KEY with your api key.
34
-
#Or alternatively if you have the IONQ_API_KEY environment
35
-
#variables set, you can omit specifying thee api_key parameters.
36
+
#Alternatively, if you have the IONQ_API_KEY environment
37
+
#variable set, you can omit specifying this api_key parameters.
36
38
service = ionq.Service(api_key=API_KEY)
37
39
38
-
# Run a program against the service. This method will block execution
39
-
#until the result is returned and periodically polls the IonQ API.
40
+
# Run a program against the service. This method will block execution until
41
+
# the result is returned (determined by periodically polling the IonQ API).
40
42
result = service.run(circuit=circuit, repetitions=100, target='qpu')
41
43
42
44
# The return object of run is a cirq.Result object.
43
-
# From this object you can get a histogram of results.
45
+
# From this object, you can get a histogram of results.
44
46
histogram = result.histogram(key='x')
45
47
print(f'Histogram: {histogram}')
46
48
47
-
#Or the data as a pandas frame.
49
+
#You can also get the data as a pandas frame.
48
50
print(f'Data:\n{result.data}')
49
51
```
50
52
This produces output (will vary due to quantum randomness!)
@@ -70,18 +72,16 @@ Data:
70
72
71
73
## Service options
72
74
73
-
In addition to the `remote_host` and `api_key` there are some other options which are
74
-
useful for configuring the service. The most useful of these are
75
-
76
-
*`default_target`: this is a string of either `simulator` or `qpu`. By setting this you
77
-
do not have to specify a target every time you run a job using `run`, `create_job`
78
-
or via the `sampler` interface. A helpful pattern is to create two services with
79
-
defaults for the simulator and for the QPU separately.
75
+
In addition to the `api_key`, there are some other options which are
76
+
useful for configuring the service. These are passed as arguments
77
+
when creating a `cirq_ionq.Service` object.
80
78
81
-
*`max_retry_seconds`: The API will pull with exponential backoff for completed jobs.
82
-
By specifying this you can change the number of seconds before this retry gives up.
83
-
It is common to set this to a very small number when, for example, wanting to fail
84
-
fast, or to be set very long for long running jobs.
79
+
*`remote_host`: The location of the api in the form of an url. If this is None,
80
+
then this instance will use the environment variable `IONQ_REMOTE_HOST`. If that
81
+
variable is not set, then this uses `https://api.ionq.co/{api_version}`.
82
+
*`default_target`: this is a string of either `simulator` or `qpu`. By setting this you do not have to specify a target every time you run a job using `run`, `create_job` or via the `sampler` interface. A helpful pattern is to create two services with defaults for the simulator and for the QPU separately.
83
+
*`api_version`: Version of the api. Defaults to 'v0.1'.
84
+
*`max_retry_seconds`: The API will pull with exponential backoff for completed jobs. By specifying this you can change the number of seconds before this retry gives up. It is common to set this to a very small number when, for example, wanting to fail fast, or to be set very long for long running jobs.
0 commit comments