Skip to content

Commit 1037e70

Browse files
committed
docs for error part
1 parent 33319c5 commit 1037e70

File tree

3 files changed

+402
-79
lines changed

3 files changed

+402
-79
lines changed

docs/source/quickstart.rst

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -450,24 +450,26 @@ For the Monte Carlo trajectory noise simulator, the unitary Kraus channel can be
450450
451451
.. code-block:: python
452452
453-
>>> c = tc.Circuit(2)
454-
>>> c.unitary_kraus(tc.channels.depolarizingchannel(0.2, 0.2, 0.2), 0)
455-
0.0
456-
>>> c.general_kraus(tc.channels.resetchannel(), 1)
457-
0.0
458-
>>> c.state()
459-
array([0.+0.j, 0.+0.j, 0.+1.j, 0.+0.j], dtype=complex64)
453+
def noisecircuit(random):
454+
c = tc.Circuit(1)
455+
c.x(0)
456+
c.thermalrelaxation(
457+
0,
458+
t1=300,
459+
t2=400,
460+
time=1000,
461+
method="ByChoi",
462+
excitedstatepopulation=0,
463+
status=random,
464+
)
465+
return c.expectation_ps(z=[0])
460466
461-
>>> def noisecircuit(X):
462-
>>> c = tc.Circuit(n)
463-
>>> c.x(0)
464-
>>> c.thermalrelaxtion(0, t1 = 300, t2 = 400, time=1000, method = "ByChoi",excitedstatepopulation = 0,status = X)
465-
>>> return c.expectation_ps(z=[0])
466-
>>> K = tc.set_backend("tensorflow")
467-
>>> noisec_vmap = K.jit(K.vmap(noisecircuit, vectorized_argnums=0))
468-
>>> nmc = 10000
469-
>>> X = K.implicit_randu(nmc)
470-
>>> valuemc = sum(K.numpy(noisec_vmap(X))) / nmc
467+
468+
K = tc.set_backend("tensorflow")
469+
noisec_vmap = K.jit(K.vmap(noisecircuit, vectorized_argnums=0))
470+
nmc = 10000
471+
random = K.implicit_randu(nmc)
472+
valuemc = K.mean(K.numpy(noisec_vmap(random)))
471473
(0.931+0j)
472474
473475
@@ -477,14 +479,18 @@ Density matrix simulator ``tc.DMCircuit`` simulates the noise in a full form, bu
477479
478480
.. code-block:: python
479481
480-
>>> def noisecircuitdm():
481-
>>> dmc = tc.DMCircuit(1)
482-
>>> dmc.x(0)
483-
>>> dmc.thermalrelaxation(0, t1=300, t2=400, time=1000, method="ByChoi", excitedstatepopulation=0)
484-
>>> return dmc.expectation_ps(z=[0])
485-
>>> K = tc.set_backend("tensorflow")
486-
>>> noisec_jit = K.jit(noisecircuitdm)
487-
>>> valuedm = noisec_jit()
482+
def noisecircuitdm():
483+
dmc = tc.DMCircuit(1)
484+
dmc.x(0)
485+
dmc.thermalrelaxation(
486+
0, t1=300, t2=400, time=1000, method="ByChoi", excitedstatepopulation=0
487+
)
488+
return dmc.expectation_ps(z=[0])
489+
490+
491+
K = tc.set_backend("tensorflow")
492+
noisec_jit = K.jit(noisecircuitdm)
493+
valuedm = noisec_jit()
488494
(0.931+0j)
489495
490496
@@ -496,10 +502,12 @@ Multiple quantum errors can be added on circuit.
496502
497503
c = tc.Circuit(1)
498504
c.x(0)
499-
c.thermalrelaxation(0,t1 = 300, t2 = 400, time = 1000,method = "ByChoi", excitedstatepopulation = 0)
500-
c.generaldepolarizing(0,p = 0.01, num_qubits =1)
501-
c.phasedamping(0,gamma=0.2)
502-
c.amplitudedamping(0,gamma = 0.25,p = 0.2)
505+
c.thermalrelaxation(
506+
0, t1=300, t2=400, time=1000, method="ByChoi", excitedstatepopulation=0
507+
)
508+
c.generaldepolarizing(0, p=0.01, num_qubits=1)
509+
c.phasedamping(0, gamma=0.2)
510+
c.amplitudedamping(0, gamma=0.25, p=0.2)
503511
c.reset(0)
504512
c.expectation_ps(z=[0])
505513
@@ -510,16 +518,26 @@ Readout error can be added in experiments for sampling and expectation value cal
510518
511519
.. code-block:: python
512520
513-
>>> c = tc.Circuit(3)
514-
>>> c.X(0)
515-
>>> readout_error = []
516-
>>> readout_error.append([0.9, 0.75]) # readout error of qubit 0
517-
>>> readout_error.append([0.4, 0.7]) # readout error of qubit 1
518-
>>> readout_error.append([0.7, 0.9]) # readout error of qubit 2
519-
>>> value = c.sample_expectation_ps(z=[0, 1, 2], readout_error=readout_error)
520-
tf.Tensor(0.039999977, shape=(), dtype=float32)
521-
>>> instance = c.sample(allow_state=True, readout_error=readout_error)
522-
(<tf.Tensor: shape=(3,), dtype=int32, numpy=array([1, 1, 0], dtype=int32)>, <tf.Tensor: shape=(), dtype=float32, numpy=0.315>)
521+
c = tc.Circuit(3)
522+
c.X(0)
523+
readout_error = []
524+
readout_error.append([0.9, 0.75]) # readout error of qubit 0
525+
readout_error.append([0.4, 0.7]) # readout error of qubit 1
526+
readout_error.append([0.7, 0.9]) # readout error of qubit 2
527+
value = c.sample_expectation_ps(z=[0, 1, 2], readout_error=readout_error)
528+
# tf.Tensor(0.039999977, shape=(), dtype=float32)
529+
instances = c.sample(
530+
batch=3,
531+
allow_state=True,
532+
readout_error=readout_error,
533+
random_generator=tc.backend.get_random_state(42),
534+
)
535+
#[(<tf.Tensor: shape=(3,), dtype=int32, numpy=array([1, 0, 0], dtype=int32)>,
536+
# <tf.Tensor: shape=(), dtype=float32, numpy=0.21000001>),
537+
#(<tf.Tensor: shape=(3,), dtype=int32, numpy=array([1, 0, 0], dtype=int32)>,
538+
# <tf.Tensor: shape=(), dtype=float32, numpy=0.21000001>),
539+
#(<tf.Tensor: shape=(3,), dtype=int32, numpy=array([1, 0, 1], dtype=int32)>,
540+
# <tf.Tensor: shape=(), dtype=float32, numpy=0.09>)]
523541
524542
525543
MPS and MPO

0 commit comments

Comments
 (0)