本文整理汇总了Python中pyquil.gates.CZ属性的典型用法代码示例。如果您正苦于以下问题:Python gates.CZ属性的具体用法?Python gates.CZ怎么用?Python gates.CZ使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pyquil.gates
的用法示例。
在下文中一共展示了gates.CZ属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_gates_in_isa
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CZ [as 别名]
def test_gates_in_isa(isa_dict):
isa = ISA.from_dict(isa_dict)
gates = gates_in_isa(isa)
for q in [0, 1, 2]:
for g in [
I(q),
RX(np.pi / 2, q),
RX(-np.pi / 2, q),
RX(np.pi, q),
RX(-np.pi, q),
RZ(THETA, q),
]:
assert g in gates
assert CZ(0, 1) in gates
assert CZ(1, 0) in gates
assert ISWAP(1, 2) in gates
assert ISWAP(2, 1) in gates
assert CPHASE(THETA, 2, 0) in gates
assert CPHASE(THETA, 0, 2) in gates
示例2: _random_2q_programs
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CZ [as 别名]
def _random_2q_programs(n_progs=3):
"""Generate random programs that consist of single qubit rotations, a CZ, and single
qubit rotations.
"""
r = random.Random(52)
def RI(qubit, angle):
# throw away angle so we can randomly choose the identity
return I(qubit)
def _random_1q_gate(qubit):
return r.choice([RI, RX, RY, RZ])(qubit=qubit, angle=r.uniform(0, 2 * pi))
for _ in range(n_progs):
prog = Program()
prog += _random_1q_gate(0)
prog += _random_1q_gate(1)
prog += CZ(0, 1)
prog += _random_1q_gate(0)
prog += _random_1q_gate(1)
yield prog
示例3: CNOT_X_basis
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CZ [as 别名]
def CNOT_X_basis(control, target) -> Program:
"""
The CNOT in the X basis, i.e.
::
CNOTX = |+X+| * I + |-X-| * Z
where ``|+>`` and ``|->`` are the +/- eigenstate of the Pauli X operator, and ``*`` denotes a
tensor product.
:param control: qubit label
:param target: qubit label
:return: program
"""
prog = Program()
prog += H(control)
prog += CZ(control, target)
prog += H(control)
return prog
示例4: generate_cz_phase_ramsey_experiments
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CZ [as 别名]
def generate_cz_phase_ramsey_experiments(cz_qubits: Sequence[int], measure_qubit: int,
angles: Sequence[float]) -> List[ObservablesExperiment]:
"""
Return ObservablesExperiments containing programs that constitute a CZ phase ramsey experiment.
:param cz_qubits: the qubits participating in the cz gate
:param measure_qubit: Which qubit to measure.
:param angles: A list of angles at which to make a measurement
:return: ObservablesExperiments which can be run to estimate the effective RZ rotation
applied to a single qubit during the application of a CZ gate.
"""
expts = []
for angle in angles:
settings = []
program = Program()
# apply CZ, possibly inducing an effective RZ on measure qubit by some angle
program += CZ(*cz_qubits)
# apply phase to measure_qubit akin to T2 experiment
program += RZ(angle, measure_qubit)
settings = [ExperimentSetting(minusY(measure_qubit), PauliTerm('Y', measure_qubit))]
expts.append(ObservablesExperiment([settings], program))
return expts
示例5: test_lifted_gate_modified
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CZ [as 别名]
def test_lifted_gate_modified():
test_unitary = lifted_gate(RZ(np.pi / 4, 0).dagger(), 1)
true_unitary = mat.RZ(-np.pi / 4)
assert np.allclose(test_unitary, true_unitary)
test_unitary = lifted_gate(X(0).dagger().controlled(1), 2)
true_unitary = lifted_gate(CNOT(1, 0), 2)
other_true = mat.CNOT
assert np.allclose(test_unitary, true_unitary)
assert np.allclose(other_true, true_unitary)
test_unitary = lifted_gate(X(1).dagger().controlled(0).dagger().dagger(), 2)
true_unitary = lifted_gate(CNOT(0, 1), 2)
assert np.allclose(test_unitary, true_unitary)
test_unitary = lifted_gate(X(0).dagger().controlled(1).dagger().dagger().controlled(2), 3)
true_unitary = lifted_gate(CCNOT(1, 2, 0), 3)
other_true = mat.CCNOT
assert np.allclose(test_unitary, true_unitary)
assert np.allclose(other_true, true_unitary)
test_unitary = lifted_gate(RY(np.pi / 4, 0).dagger().controlled(2).dagger().dagger(), 3)
ry_part = lifted_gate(RY(-np.pi / 4, 0), 1)
zero = np.eye(2)
zero[1, 1] = 0
one = np.eye(2)
one[0, 0] = 0
true_unitary = np.kron(zero, np.eye(4)) + np.kron(one, np.kron(np.eye(2), ry_part))
assert np.allclose(test_unitary, true_unitary)
test_unitary = lifted_gate(PHASE(0.0, 1).forked(0, [np.pi]), 2)
true_unitary = lifted_gate(CZ(0, 1), 2)
assert np.allclose(test_unitary, true_unitary)
test_unitary = lifted_gate(PHASE(0.0, 2).forked(1, [0.0]).forked(0, [0.0, np.pi]), 3)
true_unitary = lifted_gate(CZ(1, 2).controlled(0), 3)
assert np.allclose(test_unitary, true_unitary)
示例6: test_noise_helpers
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CZ [as 别名]
def test_noise_helpers():
gates = RX(np.pi / 2, 0), RX(-np.pi / 2, 1), I(1), CZ(0, 1)
prog = Program(*gates)
inferred_gates = _get_program_gates(prog)
assert set(inferred_gates) == set(gates)
示例7: test_apply_noise_model_perturbed_angles
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CZ [as 别名]
def test_apply_noise_model_perturbed_angles():
eps = 1e-15
p = Program(RX(np.pi / 2 + eps, 0), RX(np.pi / 2 - eps, 1), CZ(0, 1), RX(np.pi / 2 + eps, 1))
noise_model = _decoherence_noise_model(_get_program_gates(p))
pnoisy = apply_noise_model(p, noise_model)
for i in pnoisy:
if isinstance(i, DefGate):
pass
elif isinstance(i, Pragma):
assert i.command in ["ADD-KRAUS", "READOUT-POVM"]
elif isinstance(i, Gate):
assert i.name in NO_NOISE or not i.params
示例8: _CNOT
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CZ [as 别名]
def _CNOT(q1, q2):
"""
A CNOT in terms of RX(+-pi/2), RZ(theta), and CZ
.. note:
This uses two of :py:func:`_H`, so it picks up twice the global phase.
Don't control this gate.
"""
p = Program()
p.inst(_H(q2))
p.inst(CZ(q1, q2))
p.inst(_H(q2))
return p
示例9: _CCNOT
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CZ [as 别名]
def _CCNOT(q1, q2, q3):
"""
A CCNOT in terms of RX(+-pi/2), RZ(theta), and CZ
.. note:
Don't control this gate.
"""
p = Program()
p.inst(_H(q3))
p.inst(_CNOT(q2, q3))
p.inst(_T(q3, dagger=True))
p.inst(_SWAP(q2, q3))
p.inst(_CNOT(q1, q2))
p.inst(_T(q2))
p.inst(_CNOT(q3, q2))
p.inst(_T(q2, dagger=True))
p.inst(_CNOT(q1, q2))
p.inst(_SWAP(q2, q3))
p.inst(_T(q2))
p.inst(_T(q3))
p.inst(_CNOT(q1, q2))
p.inst(_H(q3))
p.inst(_T(q1))
p.inst(_T(q2, dagger=True))
p.inst(_CNOT(q1, q2))
return p
示例10: twoq_rb_gateset
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CZ [as 别名]
def twoq_rb_gateset(q1: int, q2: int) -> Iterable[Gate]:
"""
Yield the gateset for 2-qubit randomized benchmarking.
This is two 1-q gatesets and ``CZ``.
:param q1: The first qubit.
:param q2: The second qubit.
"""
yield from oneq_rb_gateset(q1)
yield from oneq_rb_gateset(q2)
yield CZ(q1, q2)
示例11: test_decoherence_noise
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CZ [as 别名]
def test_decoherence_noise():
prog = Program(RX(np.pi / 2, 0), CZ(0, 1), RZ(np.pi, 0))
gates = _get_program_gates(prog)
m1 = _decoherence_noise_model(gates, T1=INFINITY, T2=INFINITY, ro_fidelity=1.0)
# with no readout error, assignment_probs = identity matrix
assert np.allclose(m1.assignment_probs[0], np.eye(2))
assert np.allclose(m1.assignment_probs[1], np.eye(2))
for g in m1.gates:
# with infinite coherence time all kraus maps should only have a single, unitary kraus op
assert len(g.kraus_ops) == 1
(k0,) = g.kraus_ops
# check unitarity
k0dk0 = k0.dot(k0.conjugate().transpose())
assert np.allclose(k0dk0, np.eye(k0dk0.shape[0]))
# verify that selective (by qubit) dephasing and readout infidelity is working
m2 = _decoherence_noise_model(gates, T1=INFINITY, T2={0: 30e-6}, ro_fidelity={0: 0.95, 1: 1.0})
assert np.allclose(m2.assignment_probs[0], [[0.95, 0.05], [0.05, 0.95]])
assert np.allclose(m2.assignment_probs[1], np.eye(2))
for g in m2.gates:
if 0 in g.targets:
# single dephasing (no damping) channel on qc 0, no noise on qc1 -> 2 Kraus ops
assert len(g.kraus_ops) == 2
else:
assert len(g.kraus_ops) == 1
# verify that combined T1 and T2 will lead to 4 outcome Kraus map.
m3 = _decoherence_noise_model(gates, T1={0: 30e-6}, T2={0: 30e-6})
for g in m3.gates:
if 0 in g.targets:
# damping (implies dephasing) channel on qc 0, no noise on qc1 -> 4 Kraus ops
assert len(g.kraus_ops) == 4
else:
assert len(g.kraus_ops) == 1
# verify that gate names are translated
new_prog = apply_noise_model(prog, m3)
# check that headers have been embedded
headers = _noise_model_program_header(m3)
assert all(
(isinstance(i, Pragma) and i.command in ["ADD-KRAUS", "READOUT-POVM"])
or isinstance(i, DefGate)
for i in headers
)
assert headers.out() in new_prog.out()
# verify that high-level add_decoherence_noise reproduces new_prog
new_prog2 = add_decoherence_noise(prog, T1={0: 30e-6}, T2={0: 30e-6})
assert new_prog == new_prog2
示例12: create_graph_state
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CZ [as 别名]
def create_graph_state(graph: nx.Graph, use_pragmas=False):
"""
Write a program to create a graph state according to the specified graph
A graph state involves Hadamarding all your qubits and then applying a CZ for each
edge in the graph. A graph state and the ability to measure it however you want gives
you universal quantum computation. Some good references are [MBQC]_ and [MBCS]_.
Similar to a Bell state / GHZ state, we can try to prepare a graph state and measure
how well we've done according to expected parities.
.. [MBQC] A One-Way Quantum Computer.
Raussendorf et al.
Phys. Rev. Lett. 86, 5188 (2001).
https://doi.org/10.1103/PhysRevLett.86.5188
https://arxiv.org/abs/quant-ph/0010033
.. [MBCS] Measurement-based quantum computation with cluster states.
Raussendorf et al.
Phys. Rev. A 68, 022312 (2003).
https://dx.doi.org/10.1103/PhysRevA.68.022312
https://arxiv.org/abs/quant-ph/0301052
:param graph: The graph. Nodes are used as arguments to gates, so they should be qubit-like.
:param use_pragmas: Use COMMUTING_BLOCKS pragmas to hint at the compiler
:return: A program that constructs a graph state.
"""
program = Program()
for q in graph.nodes:
program += H(q)
if use_pragmas:
program += Pragma('COMMUTING_BLOCKS')
for a, b in graph.edges:
if use_pragmas:
program += Pragma('BLOCK')
program += CZ(a, b)
if use_pragmas:
program += Pragma('END_BLOCK')
if use_pragmas:
program += Pragma('END_COMMUTING_BLOCKS')
return program