XACC
pulse_instruction.hpp
1 /*******************************************************************************
2  * Copyright (c) 2017 UT-Battelle, LLC.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * and Eclipse Distribution License v1.0 which accompanies this
6  * distribution. The Eclipse Public License is available at
7  * http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution
8  *License is available at https://eclipse.org/org/documents/edl-v10.php
9  *
10  * Contributors:
11  * Alexander J. McCaskey - initial API and implementation
12  *******************************************************************************/
13 #ifndef IBM_PULSE_INSTRUCTION_HPP_
14 #define IBM_PULSE_INSTRUCTION_HPP_
15 
16 #include "Instruction.hpp"
17 #include "Cloneable.hpp"
18 
19 namespace xacc {
20 namespace quantum {
21 
23 
24 protected:
25  std::string _name;
26  bool enabled = true;
27  std::vector<std::size_t> qbits;
28  // parameters[0] corresponds to channel (string)
29  // parameters[1] corresponds to time (int)
30  // parameters[2] corresponds to phase (double or string)
31  // parameters[3] corresponds to samples (vector<complex>)
32  std::vector<InstructionParameter> parameters;
33 
34 public:
36  PulseInstruction(std::string name) : _name(name) {
37  parameters = {std::string(""), (int)0, 0.0,
38  std::vector<std::complex<double>>{}};
39  }
40  PulseInstruction(std::string name, std::vector<InstructionParameter> params)
41  : _name(name), parameters(params) {}
42  PulseInstruction(std::string name, std::vector<std::size_t> bits,
43  std::vector<InstructionParameter> params)
44  : _name(name), parameters(params), qbits(bits) {}
46  : _name(inst._name), parameters(inst.parameters), qbits(inst.qbits) {}
47 
48  const std::string name() const override { return _name; }
49  const std::string description() const override { return ""; }
50 
51  const std::string toString() override {
52  return "{\"name\":" + _name + ", \"channel\":" + parameters[0].toString() +
53  ", \"time\": " + parameters[1].toString() +
54  ", \"phase\": " + parameters[2].toString() + "}";
55  }
56 
57  const std::vector<std::size_t> bits() override { return qbits; }
58  void setBits(const std::vector<std::size_t> bits) override { qbits = bits; }
59 
61  getParameter(const std::size_t idx) const override {
62  return parameters[idx];
63  }
64  std::vector<InstructionParameter> getParameters() override {
65  return parameters;
66  }
67  void setParameter(const std::size_t idx,
68  InstructionParameter &inst) override {
69  parameters[idx] = inst;
70  }
71  const int nParameters() override { return 4; }
72  bool isParameterized() override { return true; }
73 
74  void mapBits(std::vector<std::size_t> bitMap) override {}
75  bool isComposite() override { return false; }
76 
77  bool isEnabled() override { return enabled; }
78  void disable() override { enabled = false; }
79  void enable() override { enabled = true; }
80  const bool isAnalog() const override { return true; }
81 
82  const int nRequiredBits() const override { return 1; }
83 
84  DEFINE_VISITABLE()
85 
86  // #define DEFINE_CLONE(CLASS)
87  std::shared_ptr<Instruction> clone() override {
88  return std::make_shared<PulseInstruction>(_name, qbits, parameters);
89  }
90 };
91 
92 } // namespace ibm
93 } // namespace xacc
94 #endif
const std::string name() const override
Definition: pulse_instruction.hpp:48
const std::string description() const override
Definition: pulse_instruction.hpp:49
Definition: Accelerator.hpp:25
Definition: pulse_instruction.hpp:22
Definition: Instruction.hpp:100