CRY gate control when '0' - quantum-computing

I want to make CRY gate which operates when control bit is '0'
which figure is like this circle with empty space.
I can make it on qiskit but not on pennylane.
How I make that in Pennylane circuit....
Here is my code.
import pennylane as qml
from pennylane import numpy as np
import matplotlib
dev = qml.device('qiskit.aer', wires=2)
#qml.qnode(dev)
def circuit():
qml.CRY(np.pi/2, wires=[0,1],id='0')
return qml.expval(qml.PauliZ(0))
circuit()
dev._circuit.draw(output="mpl")
I want to make this circuit.
And optimizing the gates by method introduced in pennylane

Related

Maya Python Mash - How can I add a selection set using Maya Mash API (in python)

Adding the cmds.connectAttr at the end does connect the selection set in Maya in the UI, but that's all it does. It acts as it its not registering.
import maya.cmds as cmds
import MASH.api as mapi
sel = cmds.ls(sl=1, l=1, fl=1)
new_set = cmds.sets(sel, n="custom_set")
obj_name = sel[0].split(".")[0]
shape = cmds.listRelatives(obj_name, s=True, f=1)
print(shape)
shape = "pCylinderShape1" #distribute mesh
cmds.select("|pCylinder2") #main mesh MASH
#create a new MASH network
mashNetwork = mapi.Network()
mashNetwork.createNetwork(name="Custom_placement", geometry="Repro")
shape = "pCylinderShape1"
mashNetwork.meshDistribute(shape, 4)
cmds.connectAttr(new_set+".message", mashNetwork.distribute+".selectionSetMessage")
Closest answer I found was here but I am not a programmer to know what that means.
If anyone can help, I'd much appreciate it.
After a lot of investigation I did manage to find the answer from the provided link.
The code I wrote was only the first part of the solution.
hasMASHFlag = cmds.objExists('%s.mashOutFilter' % (new_set))
if not hasMASHFlag:
cmds.addAttr( new_set, longName='mashOutFilter', attributeType='bool' )
cmds.setAttr( '%s.arrangement' % (mashNetwork.distribute), 4 )
cmds.setAttr( '%s.meshType' % (mashNetwork.distribute), 7 )
Note sure is needed but I noticed when you connect a selection set by default it has an extra attribute called mashOutFilter.
The part that is needed is the .meshType that makes it work.

How to build a complex controlled gate in the Qiskit?

I work on theory tasks in quantum computing, and make simple experiments with Qiskit. Unfortunately, I can't find a way how to make a complex control gates there, where control is in the quantum register.
I would like to have a "c_if" analogue, which can be chained and use quantum bits as a control.
Smth like
swap(q1, q2).c_if(q0,Zero).c_if(q3,One)
Is there such an operation in the qiskit? How could I emulate such an operation if it doesn't exist?
Check out Qiskit documentation for the MCXGate, know as the Multi-controlled-X Gate. This gate lets you define how many control qubits you would like to include (perhaps the majority of your quantum register) and define a control state.
from qiskit import *
my_circuit = QuantumRegister(3,3)
my_circuit.append(circuit.library.MCXGate(2, ctrl_state='10'), [0,1,2])
Check out the documentation here.
There are also variations that will do Y gate Z gate or whatever you like depending if the circuit sees the correct control gate.
Thanks #Dulah for his answer. I found my old samples and they're working pretty fine with the 0.18.2 qiskit version.
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
from qiskit.circuit.library.standard_gates.x import XGate, MCXGate
from qiskit.circuit.library.standard_gates.swap import SwapGate
simulator = Aer.get_backend('qasm_simulator')
qreg = QuantumRegister(4)
creg = ClassicalRegister(4)
qc = QuantumCircuit(qreg, creg)
control1 = XGate().control(3, None, '110') #: old-style multy-controlled qubits
#control1 = MCXGate(3, None, '110') # fashion-style multi-controlled qubits
control2 = SwapGate().control(2, None, '10')
qc.append(control1, [0, 1, 2, 3])
qc.append(control2, [0, 1, 2, 3])
qc.measure(qreg,creg)
job = execute(qc, simulator, shots=1000)
result = job.result()
counts = result.get_counts(qc)
print("\nTotal count for 00 and 11 are:",counts)
qc.draw()
The code gives me a result

Changing Choregraphe Dialog Confidence Interval for Nao

I am currently working with a Nao robot using Choregraphe and am trying to lower the confidence interval required to act upon a request made through QiChat from the default 50% to 30%.
I have found this solution, https://community.ald.softbankrobotics.com/en/forum/change-speech-engine-confidence-threshold-choregraphe-dialog-8624, but unfortunately the scripting functionality for Dialog boxes is deprecated in Choregraphe v2.1. Does anyone know what the "new" way to do this is?
I have found the solution. Scripting for Dialog boxes is not allowed but you can add a Python script before the Dialog box to change this interval. The code that should go in this box is below.
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
def onLoad(self):
#put initialization code here
pass
def onUnload(self):
#put clean-up code here
pass
def onInput_onStart(self):
# Lower confidence threshold from 50% to 30%
ALDialog = ALProxy('ALDialog')
ALDialog.setASRConfidenceThreshold(0.3)
self.onStopped() #activate the output of the box
def onInput_onStop(self):
self.onUnload() #it is recommended to reuse the clean-up as the box is stopped
self.onStopped() #activate the output of the box
Two solutions to increase recognition rate:
1) Add more variants to your input - for example, if you're listening for "yes", you should also make sure you listen for "yep", "yup", "yeah", "sure", "okay", "fine", etc. - concepts are useful for that, see the qichat doc.
1) as you suggest, set the confidence threshold - for a more compact version (I prefer less boilerplate):
class MyClass(GeneratedClass):
def onInput_onStart(self):
# Lower confidence threshold from 50% to 30%
ALProxy('ALDialog').setASRConfidenceThreshold(0.3)
self.onStopped() # activate the output of the box
HOWEVER, note that this is not very elegant; you will need to reset it, and it greatly increases the risk of false positives, so you should only use this if you can't solve it just by adding more variants.
setASRConfidenceThreshold is for Nao V5; in Pepper and Nao V6 you should use setConfidenceThreshold:
class MyClass(GeneratedClass):
def onInput_onStart(self):
# Lower confidence threshold from 50% to 30%
ALProxy('ALDialog').setConfidenceThreshold("BNF", 0.3)
self.onStopped() # activate the output of the box

Maya creating shader with cmds does not appear in hypershade

using maya 2014/2015 creating a shader like so:
import maya.cmds as cmds
my_shader = cmds.createNode('lambert', n='mine')
will create this result.
anybody knows how to get that shader to be reflected in the hypershade?
shaders are a slightly different node type:
cmds.shadingNode('lambert', asShader=1)
You'll also need to create a shadingEngine node, what we usually know as ShaderGroups or SG`s:
cmds.shadingNode('shadingEngine', asUtility=1)
and connect the .outColor of the shader to the .surfaceShader attribute of the SG. The SG node is actually a subclass of a Maya set, and to assign objects or faces to it use the sets command.
Adding to the answer for completeness:
In some cases (namely ShaderFx shaders) you need to connect the material to the scene's defaultShaderList1 node's next available plug.
import maya.cmds as mc
material = mc.shadingNode('lambert', asShader=True)
shading_engine = mc.sets(name="%sSG" % material, empty=True, renderable=True, noSurfaceShader=True)
mc.connectAttr('%s.outColor' % material, '%s.surfaceShader' % shading_engine)
mc.connectAttr('%s.msg'%material, ':defaultShaderList1.s', na=True)

How does one call external datasets into scikit-learn?

For example consider this dataset:
(1)
https://archive.ics.uci.edu/ml/machine-learning-databases/annealing/anneal.data
Or
(2)
http://data.worldbank.org/topic
How does one call such external datasets into scikit-learn to do anything with it?
The only kind of dataset calling that I have seen in scikit-learn is through a command like:
from sklearn.datasets import load_digits
digits = load_digits()
You need to learn a little pandas, which is a data frame implementation in python. Then you can do
import pandas
my_data_frame = pandas.read_csv("/path/to/my/data")
To create model matrices from your data frame, I recommend the patsy library, which implements a model specification language, similar to R formulas
import patsy
model_frame = patsy.dmatrix("my_response ~ my_model_fomula", my_data_frame)
then the model frame can be passed in as an X into the various sklearn models.
Simply run the following command and replace the name 'EXTERNALDATASETNAME' with the name of your dataset
import sklearn.datasets
data = sklearn.datasets.fetch_EXTERNALDATASETNAME()

Resources