How can Controlled Hadamard be implemented with Q#? Is there an inbuilt function? - q#

I found a way to implement Controlled Hadamard on https://quantumexperience.ng.bluemix.net/proxy/tutorial/full-user-guide/004-Quantum_Algorithms/061-Basic_Circuit_Identities_and_Larger_Circuits.html
Is there an easier way in Q# to implement this function?

You can use Controlled functor to produce a controlled version of any operation which allows for that (including primitive gates) as follows:
Controlled H([controls], target);
You can look up the details of using Controlled functor in the documentation.

Related

How to show the whole problem (LP/MILP, SCIP)

How to show the whole LP/MILP problem.
I am using solver(MPSolver::CreateSolver("SCIP")) in c++.
I saw this issue and this reply. However, those are not helpful for SCIP.
Any help?
There are two approaches:
Option A: get the underlying solver, use the scip solver to export the model.
in, details: use the underlying_solver method on the LinearSolver class.
Then cast the returned pointer to SCIP* (see the implementation of this method for the SCIP solver).
Now you have the solver, you can use the solver's API for anything including exporting the model. The only limitation is that you need the solver to have loaded the model, which only happens at solve time.
Option B:
call one the two export methods. This API is also available in non C++ languages.

Set core affinity for thread in zig

What is the suggested way to set core affinity for thread in zig programming language? Can't find anything similar in the docs below:
https://ziglang.org/documentation/master/#Top-Level-Doc-Comments
https://ziglang.org/documentation/master/std/#std?thread
Setting core affinity isn't currently implemented in the standard library.
Since zig makes it very easy to bind to C functions, you can just use a #cImport() to load the platform-specific C headers containing the functions you would like to use, e.g. sched.h for sched_setaffinity(2), pthread.h for pthread_setaffinity_np(3) on Linux or winbase.h for SetThreadAffinityMask, SetProcessAffinityMask on Windows.
#cImport() will then give you back a scope that contains all these functions as if they were defined in Zig: https://ziglang.org/documentation/0.6.0/#Import-from-C-Header-File

How to add unit conversions using Dymola

In Modelica Standard Library, the unit of SpecificEnergy and SpecificEnthalpy is "J/kg", but I'd like to use "kJ/kg" as the display unit, my first thought is to modify the Modelica Standard Library, but I am not sure if it will cause unexpectable issues, so I want to find a way to customize my own Modelica Standard Library. In this way, I could choose to use my own version or the standard one.
My question is: Is there some way like this?
In addition to using defineUnitConversion there is another possibility for prefixed units such as "kJ/kg" or "MJ/kg": just define a variable with that displayUnit in the model by creating e.g.,
SpecificEnthalphy myEnthalpy(displayUnit="MJ/kg")=...;
and then simulating the model.
No need to specify a conversion factor in this case (it is found automatically).
There are multiple possibilities to extend the unit conversions in Dymola. Probably the best is the one for the question asked is mentioned by Hans Olsson below, but you can as well
Create a function like this:
function unitConversions "Define unit conversions, which are currently not pre-defined by Dymola"
extends DymolaModels.Icons.Basic.Function;
algorithm
defineUnitConversion("J/kg", "kJ/kg", 1e-3);
// more conversions could be added here
end unitConversions;
After the function is executed, the conversion should be available for the current session of Dymola. So you need to run the function manually every time Dymola is started. This is actually one reason I asked this question - but there seems to be no answer until now.
As an alternative, you can modify E:\[Dymola_InstallPath]\insert\displayunit.mos and add the same line. This will be usable until you install a new version of Dymola, for which you will have to do the same modification...

In BPMN - how to model interface with details (fields) between two components?

I've been wondering how to model interface between two components using it's rectangular representation (not lollipop) with all the details (attributes, operations).
I have two components and interface that lets them to "talk" to each other.
Using "lollipop" notation I would do this in this way:
But I didn't know how to attach my interface definition to this flow.
Is it correct to attach it to the line of Information Flow? What type of assotiation use to do this?
I found in OMG specifiaction the following description.
The component providing the interface REALIZE it. The one that consume it - USES it.
Recreating the diagram gave me this state:

How to implement interfaces in MyHDL

In VHDL, I often use records to group related signals into something that can be passed around as a single object, e.g. in a port map. What's the MyHDL way of doing this?
Interfaces are available in the 0.9-dev and
are straightforward. If you have an object
(class) with Signals in it it will be name
extended in conversion.
It is explained in the MEP
http://www.myhdl.org/doku.php/meps:mep-107
More examples available here (I realize it
is not well documented - yet):
https://bitbucket.org/cfelton/minnesota
Also, a small example available here:
http://www.edaplayground.com/s/130/941